| 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) { |
| 76 // Restore the favicon for deferred tabs. |
| 77 favicon::ContentFaviconDriver* favicon_driver = |
| 78 favicon::ContentFaviconDriver::FromWebContents( |
| 79 restored_tab.contents()); |
| 80 favicon_driver->FetchFavicon(favicon_driver->GetActiveURL()); |
| 81 } |
| 82 |
| 72 // This experiment allows us to have comparative numbers for session restore | 83 // This experiment allows us to have comparative numbers for session restore |
| 73 // metrics. It will be removed once those numbers are obtained. | 84 // metrics. It will be removed once those numbers are obtained. |
| 74 // TODO(georgesak): Remove this experiment when stats are collected. | 85 // TODO(georgesak): Remove this experiment when stats are collected. |
| 75 base::FieldTrial* trial = | 86 base::FieldTrial* trial = |
| 76 base::FieldTrialList::Find("IntelligentSessionRestore"); | 87 base::FieldTrialList::Find("IntelligentSessionRestore"); |
| 77 if (!trial || trial->group_name() != "DontRestoreBackgroundTabs") { | 88 if (!trial || trial->group_name() != "DontRestoreBackgroundTabs") { |
| 78 SessionRestoreStatsCollector::TrackTabs(tabs, restore_started); | |
| 79 TabLoader::RestoreTabs(tabs, restore_started); | 89 TabLoader::RestoreTabs(tabs, restore_started); |
| 80 } else { | 90 } else { |
| 81 SessionRestoreStatsCollector::TrackActiveTabs(tabs, restore_started); | 91 // A TabLoader will not be used for this session restore, so manually create |
| 92 // and use a SessionRestoreStatsCollector, normally owned by the TabLoader. |
| 93 scoped_refptr<SessionRestoreStatsCollector::StatsReportingDelegate> |
| 94 reporting_delegate = |
| 95 new SessionRestoreStatsCollector::UmaStatsReportingDelegate(); |
| 96 scoped_refptr<SessionRestoreStatsCollector> stats_collector = |
| 97 new SessionRestoreStatsCollector(restore_started, reporting_delegate); |
| 98 stats_collector->TrackTabs(tabs); |
| 82 for (auto& restored_tab : tabs) { | 99 for (auto& restored_tab : tabs) { |
| 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 |