Chromium Code Reviews| 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 "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "chrome/browser/sessions/session_restore_stats_collector.h" | 8 #include "chrome/browser/sessions/session_restore_stats_collector.h" |
| 9 #include "chrome/browser/sessions/tab_loader.h" | 9 #include "chrome/browser/sessions/tab_loader.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 SessionRestore::SMART_RESTORE_MODE_MRU) | 62 SessionRestore::SMART_RESTORE_MODE_MRU) |
| 63 return contents_->GetLastActiveTime() > | 63 return contents_->GetLastActiveTime() > |
| 64 right.contents_->GetLastActiveTime(); | 64 right.contents_->GetLastActiveTime(); |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 void SessionRestoreDelegate::RestoreTabs( | 69 void SessionRestoreDelegate::RestoreTabs( |
| 70 const std::vector<RestoredTab>& tabs, | 70 const std::vector<RestoredTab>& tabs, |
| 71 const base::TimeTicks& restore_started) { | 71 const base::TimeTicks& restore_started) { |
| 72 // Restore the favicon for all tabs. Any tab may end up being deferred due | |
| 73 // to memory pressure so it's best to have some visual indication of its | |
| 74 // contents. | |
| 75 for (auto& restored_tab : tabs) { | |
|
Alexei Svitkine (slow)
2015/06/18 17:48:48
Nit: const auto&
chrisha
2015/06/18 20:09:03
Done.
| |
| 76 // Restore the favicon for deferred tabs. | |
| 77 favicon::ContentFaviconDriver* favicon_driver = | |
| 78 favicon::ContentFaviconDriver::FromWebContents(restored_tab.contents()); | |
| 79 favicon_driver->FetchFavicon(favicon_driver->GetActiveURL()); | |
| 80 } | |
| 81 | |
| 72 // This experiment allows us to have comparative numbers for session restore | 82 // This experiment allows us to have comparative numbers for session restore |
| 73 // metrics. It will be removed once those numbers are obtained. | 83 // metrics. It will be removed once those numbers are obtained. |
| 74 // TODO(georgesak): Remove this experiment when stats are collected. | 84 // TODO(georgesak): Remove this experiment when stats are collected. |
| 75 base::FieldTrial* trial = | 85 base::FieldTrial* trial = |
| 76 base::FieldTrialList::Find("IntelligentSessionRestore"); | 86 base::FieldTrialList::Find("IntelligentSessionRestore"); |
| 77 if (!trial || trial->group_name() != "DontRestoreBackgroundTabs") { | 87 if (!trial || trial->group_name() != "DontRestoreBackgroundTabs") { |
| 78 SessionRestoreStatsCollector::TrackTabs(tabs, restore_started); | |
| 79 TabLoader::RestoreTabs(tabs, restore_started); | 88 TabLoader::RestoreTabs(tabs, restore_started); |
| 80 } else { | 89 } else { |
| 81 SessionRestoreStatsCollector::TrackActiveTabs(tabs, restore_started); | 90 // A TabLoader will not be used for this session restore, so manually create |
| 91 // and use a SessionRestoreStatsCollector, normally owned by the TabLoader. | |
| 92 scoped_ptr<SessionRestoreStatsCollector::StatsReportingDelegate> | |
| 93 reporting_delegate( | |
| 94 new SessionRestoreStatsCollector::UmaStatsReportingDelegate()); | |
| 95 scoped_refptr<SessionRestoreStatsCollector> stats_collector = | |
| 96 new SessionRestoreStatsCollector(restore_started, | |
| 97 reporting_delegate.Pass()); | |
| 98 stats_collector->TrackTabs(tabs); | |
| 82 for (auto& restored_tab : tabs) { | 99 for (auto& restored_tab : tabs) { |
|
Alexei Svitkine (slow)
2015/06/18 17:48:48
Nit: const auto&
chrisha
2015/06/18 20:09:03
Done.
| |
| 83 if (!restored_tab.is_active()) { | 100 if (!restored_tab.is_active()) { |
| 84 favicon::ContentFaviconDriver* favicon_driver = | 101 // Non-active tabs aren't being loaded, so mark them as deferred. |
| 85 favicon::ContentFaviconDriver::FromWebContents( | 102 auto tab_controller = &restored_tab.contents()->GetController(); |
| 86 restored_tab.contents()); | 103 stats_collector->DeferTab(tab_controller); |
| 87 favicon_driver->FetchFavicon(favicon_driver->GetActiveURL()); | |
| 88 } | 104 } |
| 89 } | 105 } |
| 90 } | 106 } |
| 91 } | 107 } |
| OLD | NEW |