| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sessions/session_restore_delegate.h" | 5 #include "chrome/browser/sessions/session_restore_delegate.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "chrome/browser/sessions/session_restore_stats_collector.h" | 12 #include "chrome/browser/sessions/session_restore_stats_collector.h" |
| 13 #include "chrome/browser/sessions/tab_loader.h" | 13 #include "chrome/browser/sessions/tab_loader.h" |
| 14 #include "chrome/browser/ui/chrome_pages.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "components/favicon/content/content_favicon_driver.h" | 16 #include "components/favicon/content/content_favicon_driver.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 | 18 |
| 18 namespace { | |
| 19 | |
| 20 bool IsInternalPage(const GURL& url) { | |
| 21 // There are many chrome:// UI URLs, but only look for the ones that users | |
| 22 // are likely to have open. Most of the benefit is from the NTP URL. | |
| 23 const char* const kReloadableUrlPrefixes[] = { | |
| 24 chrome::kChromeUIDownloadsURL, | |
| 25 chrome::kChromeUIHistoryURL, | |
| 26 chrome::kChromeUINewTabURL, | |
| 27 chrome::kChromeUISettingsURL, | |
| 28 }; | |
| 29 // Prefix-match against the table above. Use strncmp to avoid allocating | |
| 30 // memory to convert the URL prefix constants into std::strings. | |
| 31 for (size_t i = 0; i < arraysize(kReloadableUrlPrefixes); ++i) { | |
| 32 if (!strncmp(url.spec().c_str(), kReloadableUrlPrefixes[i], | |
| 33 strlen(kReloadableUrlPrefixes[i]))) | |
| 34 return true; | |
| 35 } | |
| 36 return false; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 SessionRestoreDelegate::RestoredTab::RestoredTab(content::WebContents* contents, | 19 SessionRestoreDelegate::RestoredTab::RestoredTab(content::WebContents* contents, |
| 42 bool is_active, | 20 bool is_active, |
| 43 bool is_app, | 21 bool is_app, |
| 44 bool is_pinned) | 22 bool is_pinned) |
| 45 : contents_(contents), | 23 : contents_(contents), |
| 46 is_active_(is_active), | 24 is_active_(is_active), |
| 47 is_app_(is_app), | 25 is_app_(is_app), |
| 48 is_internal_page_(IsInternalPage(contents->GetLastCommittedURL())), | 26 is_internal_page_( |
| 49 is_pinned_(is_pinned) { | 27 chrome::IsInternalPage(contents->GetLastCommittedURL())), |
| 50 } | 28 is_pinned_(is_pinned) {} |
| 51 | 29 |
| 52 bool SessionRestoreDelegate::RestoredTab::operator<( | 30 bool SessionRestoreDelegate::RestoredTab::operator<( |
| 53 const RestoredTab& right) const { | 31 const RestoredTab& right) const { |
| 54 // Tab with internal web UI like NTP or Settings are good choices to | 32 // Tab with internal web UI like NTP or Settings are good choices to |
| 55 // defer loading. | 33 // defer loading. |
| 56 if (is_internal_page_ != right.is_internal_page_) | 34 if (is_internal_page_ != right.is_internal_page_) |
| 57 return !is_internal_page_; | 35 return !is_internal_page_; |
| 58 // Pinned tabs should be loaded first. | 36 // Pinned tabs should be loaded first. |
| 59 if (is_pinned_ != right.is_pinned_) | 37 if (is_pinned_ != right.is_pinned_) |
| 60 return is_pinned_; | 38 return is_pinned_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 // contents. | 52 // contents. |
| 75 for (const auto& restored_tab : tabs) { | 53 for (const auto& restored_tab : tabs) { |
| 76 // Restore the favicon for deferred tabs. | 54 // Restore the favicon for deferred tabs. |
| 77 favicon::ContentFaviconDriver* favicon_driver = | 55 favicon::ContentFaviconDriver* favicon_driver = |
| 78 favicon::ContentFaviconDriver::FromWebContents(restored_tab.contents()); | 56 favicon::ContentFaviconDriver::FromWebContents(restored_tab.contents()); |
| 79 favicon_driver->FetchFavicon(favicon_driver->GetActiveURL()); | 57 favicon_driver->FetchFavicon(favicon_driver->GetActiveURL()); |
| 80 } | 58 } |
| 81 | 59 |
| 82 TabLoader::RestoreTabs(tabs, restore_started); | 60 TabLoader::RestoreTabs(tabs, restore_started); |
| 83 } | 61 } |
| OLD | NEW |