| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // doubled. | 73 // doubled. |
| 74 // | 74 // |
| 75 // TabLoader keeps a reference to itself when it's loading. When it has finished | 75 // TabLoader keeps a reference to itself when it's loading. When it has finished |
| 76 // loading, it drops the reference. If another profile is restored while the | 76 // loading, it drops the reference. If another profile is restored while the |
| 77 // TabLoader is loading, it will schedule its tabs to get loaded by the same | 77 // TabLoader is loading, it will schedule its tabs to get loaded by the same |
| 78 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. | 78 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. |
| 79 // | 79 // |
| 80 // This is not part of SessionRestoreImpl so that synchronous destruction | 80 // This is not part of SessionRestoreImpl so that synchronous destruction |
| 81 // of SessionRestoreImpl doesn't have timing problems. | 81 // of SessionRestoreImpl doesn't have timing problems. |
| 82 class TabLoader : public content::NotificationObserver, | 82 class TabLoader : public content::NotificationObserver, |
| 83 public net::NetworkChangeNotifier::OnlineStateObserver, | 83 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 84 public base::RefCounted<TabLoader> { | 84 public base::RefCounted<TabLoader> { |
| 85 public: | 85 public: |
| 86 // Retrieves a pointer to the TabLoader instance shared between profiles, or | 86 // Retrieves a pointer to the TabLoader instance shared between profiles, or |
| 87 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its | 87 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its |
| 88 // starting timestamp is set to |restore_started|. | 88 // starting timestamp is set to |restore_started|. |
| 89 static TabLoader* GetTabLoader(base::TimeTicks restore_started); | 89 static TabLoader* GetTabLoader(base::TimeTicks restore_started); |
| 90 | 90 |
| 91 // Schedules a tab for loading. | 91 // Schedules a tab for loading. |
| 92 void ScheduleLoad(NavigationController* controller); | 92 void ScheduleLoad(NavigationController* controller); |
| 93 | 93 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 113 // Loads the next tab. If there are no more tabs to load this deletes itself, | 113 // Loads the next tab. If there are no more tabs to load this deletes itself, |
| 114 // otherwise |force_load_timer_| is restarted. | 114 // otherwise |force_load_timer_| is restarted. |
| 115 void LoadNextTab(); | 115 void LoadNextTab(); |
| 116 | 116 |
| 117 // NotificationObserver method. Removes the specified tab and loads the next | 117 // NotificationObserver method. Removes the specified tab and loads the next |
| 118 // tab. | 118 // tab. |
| 119 virtual void Observe(int type, | 119 virtual void Observe(int type, |
| 120 const content::NotificationSource& source, | 120 const content::NotificationSource& source, |
| 121 const content::NotificationDetails& details) OVERRIDE; | 121 const content::NotificationDetails& details) OVERRIDE; |
| 122 | 122 |
| 123 // net::NetworkChangeNotifier::OnlineStateObserver overrides. | 123 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 124 virtual void OnOnlineStateChanged(bool online) OVERRIDE; | 124 virtual void OnConnectionTypeChanged( |
| 125 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 125 | 126 |
| 126 // Removes the listeners from the specified tab and removes the tab from | 127 // Removes the listeners from the specified tab and removes the tab from |
| 127 // the set of tabs to load and list of tabs we're waiting to get a load | 128 // the set of tabs to load and list of tabs we're waiting to get a load |
| 128 // from. | 129 // from. |
| 129 void RemoveTab(NavigationController* tab); | 130 void RemoveTab(NavigationController* tab); |
| 130 | 131 |
| 131 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes | 132 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes |
| 132 // |LoadNextTab| to load the next tab | 133 // |LoadNextTab| to load the next tab |
| 133 void ForceLoadTimerFired(); | 134 void ForceLoadTimerFired(); |
| 134 | 135 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (loading_) | 220 if (loading_) |
| 220 return; | 221 return; |
| 221 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | 222 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 222 content::NotificationService::AllSources()); | 223 content::NotificationService::AllSources()); |
| 223 this_retainer_ = this; | 224 this_retainer_ = this; |
| 224 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
| 225 if (!net::NetworkChangeNotifier::IsOffline()) { | 226 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 226 loading_ = true; | 227 loading_ = true; |
| 227 LoadNextTab(); | 228 LoadNextTab(); |
| 228 } else { | 229 } else { |
| 229 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 230 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 230 } | 231 } |
| 231 #else | 232 #else |
| 232 loading_ = true; | 233 loading_ = true; |
| 233 LoadNextTab(); | 234 LoadNextTab(); |
| 234 #endif | 235 #endif |
| 235 } | 236 } |
| 236 | 237 |
| 237 TabLoader::TabLoader(base::TimeTicks restore_started) | 238 TabLoader::TabLoader(base::TimeTicks restore_started) |
| 238 : force_load_delay_(kInitialDelayTimerMS), | 239 : force_load_delay_(kInitialDelayTimerMS), |
| 239 loading_(false), | 240 loading_(false), |
| 240 got_first_paint_(false), | 241 got_first_paint_(false), |
| 241 tab_count_(0), | 242 tab_count_(0), |
| 242 restore_started_(restore_started), | 243 restore_started_(restore_started), |
| 243 max_parallel_tab_loads_(0) { | 244 max_parallel_tab_loads_(0) { |
| 244 } | 245 } |
| 245 | 246 |
| 246 TabLoader::~TabLoader() { | 247 TabLoader::~TabLoader() { |
| 247 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 248 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
| 248 tabs_loading_.empty() && tabs_to_load_.empty()); | 249 tabs_loading_.empty() && tabs_to_load_.empty()); |
| 249 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 250 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 250 shared_tab_loader = NULL; | 251 shared_tab_loader = NULL; |
| 251 } | 252 } |
| 252 | 253 |
| 253 void TabLoader::LoadNextTab() { | 254 void TabLoader::LoadNextTab() { |
| 254 if (!tabs_to_load_.empty()) { | 255 if (!tabs_to_load_.empty()) { |
| 255 NavigationController* tab = tabs_to_load_.front(); | 256 NavigationController* tab = tabs_to_load_.front(); |
| 256 DCHECK(tab); | 257 DCHECK(tab); |
| 257 tabs_loading_.insert(tab); | 258 tabs_loading_.insert(tab); |
| 258 if (tabs_loading_.size() > max_parallel_tab_loads_) | 259 if (tabs_loading_.size() > max_parallel_tab_loads_) |
| 259 max_parallel_tab_loads_ = tabs_loading_.size(); | 260 max_parallel_tab_loads_ = tabs_loading_.size(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 363 } |
| 363 // Delete ourselves when we're not waiting for any more notifications. If this | 364 // Delete ourselves when we're not waiting for any more notifications. If this |
| 364 // was not the last reference, a SessionRestoreImpl holding a reference will | 365 // was not the last reference, a SessionRestoreImpl holding a reference will |
| 365 // eventually call StartLoading (which assigns this_retainer_), or drop the | 366 // eventually call StartLoading (which assigns this_retainer_), or drop the |
| 366 // reference without initiating a load. | 367 // reference without initiating a load. |
| 367 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && | 368 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && |
| 368 tabs_loading_.empty() && tabs_to_load_.empty()) | 369 tabs_loading_.empty() && tabs_to_load_.empty()) |
| 369 this_retainer_ = NULL; | 370 this_retainer_ = NULL; |
| 370 } | 371 } |
| 371 | 372 |
| 372 void TabLoader::OnOnlineStateChanged(bool online) { | 373 void TabLoader::OnConnectionTypeChanged( |
| 373 if (online) { | 374 net::NetworkChangeNotifier::ConnectionType type) { |
| 375 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 374 if (!loading_) { | 376 if (!loading_) { |
| 375 loading_ = true; | 377 loading_ = true; |
| 376 LoadNextTab(); | 378 LoadNextTab(); |
| 377 } | 379 } |
| 378 } else { | 380 } else { |
| 379 loading_ = false; | 381 loading_ = false; |
| 380 } | 382 } |
| 381 } | 383 } |
| 382 | 384 |
| 383 void TabLoader::RemoveTab(NavigationController* tab) { | 385 void TabLoader::RemoveTab(NavigationController* tab) { |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 if (active_session_restorers == NULL) | 1080 if (active_session_restorers == NULL) |
| 1079 return false; | 1081 return false; |
| 1080 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1082 for (std::set<SessionRestoreImpl*>::const_iterator it = |
| 1081 active_session_restorers->begin(); | 1083 active_session_restorers->begin(); |
| 1082 it != active_session_restorers->end(); ++it) { | 1084 it != active_session_restorers->end(); ++it) { |
| 1083 if ((*it)->profile() == profile) | 1085 if ((*it)->profile() == profile) |
| 1084 return true; | 1086 return true; |
| 1085 } | 1087 } |
| 1086 return false; | 1088 return false; |
| 1087 } | 1089 } |
| OLD | NEW |