| 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/tab_loader.h" | 5 #include "chrome/browser/sessions/tab_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/sessions/session_restore_stats_collector.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "components/favicon/content/content_favicon_driver.h" | 16 #include "components/favicon/content/content_favicon_driver.h" |
| 16 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 default: | 44 default: |
| 44 NOTREACHED() << "Unknown notification received:" << type; | 45 NOTREACHED() << "Unknown notification received:" << type; |
| 45 } | 46 } |
| 46 // Delete ourselves when we are done. | 47 // Delete ourselves when we are done. |
| 47 if (tabs_loading_.empty() && tabs_to_load_.empty()) | 48 if (tabs_loading_.empty() && tabs_to_load_.empty()) |
| 48 this_retainer_ = nullptr; | 49 this_retainer_ = nullptr; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void TabLoader::SetTabLoadingEnabled(bool enable_tab_loading) { | 52 void TabLoader::SetTabLoadingEnabled(bool enable_tab_loading) { |
| 53 // TODO(chrisha): Make the SessionRestoreStatsCollector aware that tab loading |
| 54 // was explicitly stopped or restarted. This can make be used to invalidate |
| 55 // various metrics. |
| 52 if (enable_tab_loading == loading_enabled_) | 56 if (enable_tab_loading == loading_enabled_) |
| 53 return; | 57 return; |
| 54 loading_enabled_ = enable_tab_loading; | 58 loading_enabled_ = enable_tab_loading; |
| 55 if (loading_enabled_) | 59 if (loading_enabled_) { |
| 56 LoadNextTab(); | 60 LoadNextTab(); |
| 57 else | 61 } else { |
| 58 force_load_timer_.Stop(); | 62 force_load_timer_.Stop(); |
| 63 } |
| 59 } | 64 } |
| 60 | 65 |
| 61 // static | 66 // static |
| 62 void TabLoader::RestoreTabs(const std::vector<RestoredTab>& tabs, | 67 void TabLoader::RestoreTabs(const std::vector<RestoredTab>& tabs, |
| 63 const base::TimeTicks& restore_started) { | 68 const base::TimeTicks& restore_started) { |
| 64 if (!shared_tab_loader_) | 69 if (!shared_tab_loader_) |
| 65 shared_tab_loader_ = new TabLoader(restore_started); | 70 shared_tab_loader_ = new TabLoader(restore_started); |
| 66 | 71 |
| 72 shared_tab_loader_->stats_collector_->TrackTabs(tabs); |
| 67 shared_tab_loader_->StartLoading(tabs); | 73 shared_tab_loader_->StartLoading(tabs); |
| 68 } | 74 } |
| 69 | 75 |
| 70 TabLoader::TabLoader(base::TimeTicks restore_started) | 76 TabLoader::TabLoader(base::TimeTicks restore_started) |
| 71 : memory_pressure_listener_( | 77 : memory_pressure_listener_( |
| 72 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))), | 78 base::Bind(&TabLoader::OnMemoryPressure, base::Unretained(this))), |
| 73 force_load_delay_multiplier_(1), | 79 force_load_delay_multiplier_(1), |
| 74 loading_enabled_(true), | 80 loading_enabled_(true), |
| 75 restore_started_(restore_started) { | 81 restore_started_(restore_started) { |
| 82 scoped_refptr<SessionRestoreStatsCollector::StatsReportingDelegate> |
| 83 reporting_delegate = |
| 84 new SessionRestoreStatsCollector::UmaStatsReportingDelegate(); |
| 85 stats_collector_ = new SessionRestoreStatsCollector( |
| 86 restore_started, reporting_delegate); |
| 76 shared_tab_loader_ = this; | 87 shared_tab_loader_ = this; |
| 77 this_retainer_ = this; | 88 this_retainer_ = this; |
| 78 } | 89 } |
| 79 | 90 |
| 80 TabLoader::~TabLoader() { | 91 TabLoader::~TabLoader() { |
| 81 DCHECK(tabs_loading_.empty() && tabs_to_load_.empty()); | 92 DCHECK(tabs_loading_.empty() && tabs_to_load_.empty()); |
| 82 DCHECK(shared_tab_loader_ == this); | 93 DCHECK(shared_tab_loader_ == this); |
| 83 shared_tab_loader_ = nullptr; | 94 shared_tab_loader_ = nullptr; |
| 84 } | 95 } |
| 85 | 96 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 #endif | 225 #endif |
| 215 | 226 |
| 216 // When receiving a resource pressure level warning, we stop pre-loading more | 227 // When receiving a resource pressure level warning, we stop pre-loading more |
| 217 // tabs since we are running in danger of loading more tabs by throwing out | 228 // tabs since we are running in danger of loading more tabs by throwing out |
| 218 // old ones. | 229 // old ones. |
| 219 if (tabs_to_load_.empty()) | 230 if (tabs_to_load_.empty()) |
| 220 return; | 231 return; |
| 221 // Stop the timer and suppress any tab loads while we clean the list. | 232 // Stop the timer and suppress any tab loads while we clean the list. |
| 222 SetTabLoadingEnabled(false); | 233 SetTabLoadingEnabled(false); |
| 223 while (!tabs_to_load_.empty()) { | 234 while (!tabs_to_load_.empty()) { |
| 224 NavigationController* controller = tabs_to_load_.front(); | 235 NavigationController* tab = tabs_to_load_.front(); |
| 225 tabs_to_load_.pop_front(); | 236 tabs_to_load_.pop_front(); |
| 226 RemoveTab(controller); | 237 RemoveTab(tab); |
| 238 |
| 239 // Notify the stats collector that a tab's loading has been deferred due to |
| 240 // memory pressure. |
| 241 stats_collector_->DeferTab(tab); |
| 227 } | 242 } |
| 228 // By calling |LoadNextTab| explicitly, we make sure that the | 243 // By calling |LoadNextTab| explicitly, we make sure that the |
| 229 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. | 244 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. |
| 230 LoadNextTab(); | 245 LoadNextTab(); |
| 231 } | 246 } |
| 232 | 247 |
| 233 // static | 248 // static |
| 234 TabLoader* TabLoader::shared_tab_loader_ = nullptr; | 249 TabLoader* TabLoader::shared_tab_loader_ = nullptr; |
| OLD | NEW |