georgesak | a3ae61c7 | 2015-04-02 01:04:26 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/sessions/session_restore_delegate.h" |
| 6 | |
georgesak | fbcd45d | 2015-04-07 15:08:24 | [diff] [blame] | 7 | #include "base/metrics/field_trial.h" |
georgesak | 98702bbb | 2015-04-03 17:59:22 | [diff] [blame] | 8 | #include "chrome/browser/sessions/session_restore_stats_collector.h" |
georgesak | a3ae61c7 | 2015-04-02 01:04:26 | [diff] [blame] | 9 | #include "chrome/browser/sessions/tab_loader.h" |
georgesak | 189ed37 | 2015-05-08 03:53:30 | [diff] [blame^] | 10 | #include "chrome/common/url_constants.h" |
georgesak | bf4674a | 2015-04-13 18:50:31 | [diff] [blame] | 11 | #include "components/favicon/content/content_favicon_driver.h" |
georgesak | a3ae61c7 | 2015-04-02 01:04:26 | [diff] [blame] | 12 | |
georgesak | 189ed37 | 2015-05-08 03:53:30 | [diff] [blame^] | 13 | namespace { |
| 14 | |
| 15 | bool IsInternalPage(const GURL& url) { |
| 16 | // There are many chrome:// UI URLs, but only look for the ones that users |
| 17 | // are likely to have open. Most of the benefit is from the NTP URL. |
| 18 | const char* const kReloadableUrlPrefixes[] = { |
| 19 | chrome::kChromeUIDownloadsURL, |
| 20 | chrome::kChromeUIHistoryURL, |
| 21 | chrome::kChromeUINewTabURL, |
| 22 | chrome::kChromeUISettingsURL, |
| 23 | }; |
| 24 | // Prefix-match against the table above. Use strncmp to avoid allocating |
| 25 | // memory to convert the URL prefix constants into std::strings. |
| 26 | for (size_t i = 0; i < arraysize(kReloadableUrlPrefixes); ++i) { |
| 27 | if (!strncmp(url.spec().c_str(), kReloadableUrlPrefixes[i], |
| 28 | strlen(kReloadableUrlPrefixes[i]))) |
| 29 | return true; |
| 30 | } |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | SessionRestoreDelegate::RestoredTab::RestoredTab(content::WebContents* contents, |
| 37 | bool is_active, |
| 38 | bool is_app, |
| 39 | bool is_pinned) |
| 40 | : contents_(contents), |
| 41 | is_active_(is_active), |
| 42 | is_app_(is_app), |
| 43 | is_internal_page_(IsInternalPage(contents->GetLastCommittedURL())), |
| 44 | is_pinned_(is_pinned) { |
| 45 | } |
| 46 | |
| 47 | bool SessionRestoreDelegate::RestoredTab::operator<( |
| 48 | const RestoredTab& right) const { |
| 49 | // Tab with internal web UI like NTP or Settings are good choices to |
| 50 | // defer loading. |
| 51 | if (is_internal_page_ != right.is_internal_page_) |
| 52 | return !is_internal_page_; |
| 53 | // Pinned tabs should be loaded first. |
| 54 | if (is_pinned_ != right.is_pinned_) |
| 55 | return is_pinned_; |
| 56 | // Apps should be loaded before normal tabs. |
| 57 | if (is_app_ != right.is_app_) |
| 58 | return is_app_; |
| 59 | // TODO(georgesak): Add criterion based on recency. |
| 60 | return false; |
| 61 | } |
| 62 | |
georgesak | a3ae61c7 | 2015-04-02 01:04:26 | [diff] [blame] | 63 | // static |
georgesak | b1881ce | 2015-05-06 20:22:11 | [diff] [blame] | 64 | void SessionRestoreDelegate::RestoreTabs( |
| 65 | const std::vector<RestoredTab>& tabs, |
| 66 | const base::TimeTicks& restore_started) { |
| 67 | SessionRestoreStatsCollector::TrackTabs(tabs, restore_started); |
| 68 | TabLoader::RestoreTabs(tabs, restore_started); |
georgesak | a3ae61c7 | 2015-04-02 01:04:26 | [diff] [blame] | 69 | } |