Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // doubled. 88 // doubled.
89 // 89 //
90 // TabLoader keeps a reference to itself when it's loading. When it has finished 90 // TabLoader keeps a reference to itself when it's loading. When it has finished
91 // loading, it drops the reference. If another profile is restored while the 91 // loading, it drops the reference. If another profile is restored while the
92 // TabLoader is loading, it will schedule its tabs to get loaded by the same 92 // TabLoader is loading, it will schedule its tabs to get loaded by the same
93 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. 93 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader.
94 // 94 //
95 // This is not part of SessionRestoreImpl so that synchronous destruction 95 // This is not part of SessionRestoreImpl so that synchronous destruction
96 // of SessionRestoreImpl doesn't have timing problems. 96 // of SessionRestoreImpl doesn't have timing problems.
97 class TabLoader : public content::NotificationObserver, 97 class TabLoader : public content::NotificationObserver,
98 public net::NetworkChangeNotifier::ConnectionTypeObserver, 98 public net::NetworkChangeNotifier::NetworkChangeObserver,
99 public base::RefCounted<TabLoader> { 99 public base::RefCounted<TabLoader> {
100 public: 100 public:
101 // Retrieves a pointer to the TabLoader instance shared between profiles, or 101 // Retrieves a pointer to the TabLoader instance shared between profiles, or
102 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its 102 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its
103 // starting timestamp is set to |restore_started|. 103 // starting timestamp is set to |restore_started|.
104 static TabLoader* GetTabLoader(base::TimeTicks restore_started); 104 static TabLoader* GetTabLoader(base::TimeTicks restore_started);
105 105
106 // Schedules a tab for loading. 106 // Schedules a tab for loading.
107 void ScheduleLoad(NavigationController* controller); 107 void ScheduleLoad(NavigationController* controller);
108 108
(...skipping 19 matching lines...) Expand all
128 // Loads the next tab. If there are no more tabs to load this deletes itself, 128 // Loads the next tab. If there are no more tabs to load this deletes itself,
129 // otherwise |force_load_timer_| is restarted. 129 // otherwise |force_load_timer_| is restarted.
130 void LoadNextTab(); 130 void LoadNextTab();
131 131
132 // NotificationObserver method. Removes the specified tab and loads the next 132 // NotificationObserver method. Removes the specified tab and loads the next
133 // tab. 133 // tab.
134 virtual void Observe(int type, 134 virtual void Observe(int type,
135 const content::NotificationSource& source, 135 const content::NotificationSource& source,
136 const content::NotificationDetails& details) OVERRIDE; 136 const content::NotificationDetails& details) OVERRIDE;
137 137
138 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. 138 // net::NetworkChangeNotifier::NetworkChangeObserver overrides.
139 virtual void OnConnectionTypeChanged( 139 virtual void OnNetworkChanged(
140 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 140 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
141 141
142 // Removes the listeners from the specified tab and removes the tab from 142 // Removes the listeners from the specified tab and removes the tab from
143 // the set of tabs to load and list of tabs we're waiting to get a load 143 // the set of tabs to load and list of tabs we're waiting to get a load
144 // from. 144 // from.
145 void RemoveTab(NavigationController* tab); 145 void RemoveTab(NavigationController* tab);
146 146
147 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes 147 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes
148 // |LoadNextTab| to load the next tab 148 // |LoadNextTab| to load the next tab
149 void ForceLoadTimerFired(); 149 void ForceLoadTimerFired();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 registrar_.Add( 237 registrar_.Add(
238 this, 238 this,
239 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, 239 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
240 content::NotificationService::AllSources()); 240 content::NotificationService::AllSources());
241 this_retainer_ = this; 241 this_retainer_ = this;
242 #if defined(OS_CHROMEOS) 242 #if defined(OS_CHROMEOS)
243 if (!net::NetworkChangeNotifier::IsOffline()) { 243 if (!net::NetworkChangeNotifier::IsOffline()) {
244 loading_ = true; 244 loading_ = true;
245 LoadNextTab(); 245 LoadNextTab();
246 } else { 246 } else {
247 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 247 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
248 } 248 }
249 #else 249 #else
250 loading_ = true; 250 loading_ = true;
251 LoadNextTab(); 251 LoadNextTab();
252 #endif 252 #endif
253 } 253 }
254 254
255 TabLoader::TabLoader(base::TimeTicks restore_started) 255 TabLoader::TabLoader(base::TimeTicks restore_started)
256 : force_load_delay_(kInitialDelayTimerMS), 256 : force_load_delay_(kInitialDelayTimerMS),
257 loading_(false), 257 loading_(false),
258 got_first_paint_(false), 258 got_first_paint_(false),
259 tab_count_(0), 259 tab_count_(0),
260 restore_started_(restore_started), 260 restore_started_(restore_started),
261 max_parallel_tab_loads_(0) { 261 max_parallel_tab_loads_(0) {
262 } 262 }
263 263
264 TabLoader::~TabLoader() { 264 TabLoader::~TabLoader() {
265 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && 265 DCHECK((got_first_paint_ || render_widget_hosts_to_paint_.empty()) &&
266 tabs_loading_.empty() && tabs_to_load_.empty()); 266 tabs_loading_.empty() && tabs_to_load_.empty());
267 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 267 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
268 shared_tab_loader = NULL; 268 shared_tab_loader = NULL;
269 } 269 }
270 270
271 void TabLoader::LoadNextTab() { 271 void TabLoader::LoadNextTab() {
272 if (!tabs_to_load_.empty()) { 272 if (!tabs_to_load_.empty()) {
273 NavigationController* tab = tabs_to_load_.front(); 273 NavigationController* tab = tabs_to_load_.front();
274 DCHECK(tab); 274 DCHECK(tab);
275 tabs_loading_.insert(tab); 275 tabs_loading_.insert(tab);
276 if (tabs_loading_.size() > max_parallel_tab_loads_) 276 if (tabs_loading_.size() > max_parallel_tab_loads_)
277 max_parallel_tab_loads_ = tabs_loading_.size(); 277 max_parallel_tab_loads_ = tabs_loading_.size();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 // Delete ourselves when we're not waiting for any more notifications. If this 382 // Delete ourselves when we're not waiting for any more notifications. If this
383 // was not the last reference, a SessionRestoreImpl holding a reference will 383 // was not the last reference, a SessionRestoreImpl holding a reference will
384 // eventually call StartLoading (which assigns this_retainer_), or drop the 384 // eventually call StartLoading (which assigns this_retainer_), or drop the
385 // reference without initiating a load. 385 // reference without initiating a load.
386 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && 386 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) &&
387 tabs_loading_.empty() && tabs_to_load_.empty()) 387 tabs_loading_.empty() && tabs_to_load_.empty())
388 this_retainer_ = NULL; 388 this_retainer_ = NULL;
389 } 389 }
390 390
391 void TabLoader::OnConnectionTypeChanged( 391 void TabLoader::OnNetworkChanged(
392 net::NetworkChangeNotifier::ConnectionType type) { 392 net::NetworkChangeNotifier::ConnectionType type) {
393 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { 393 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
394 if (!loading_) { 394 if (!loading_) {
395 loading_ = true; 395 loading_ = true;
396 LoadNextTab(); 396 LoadNextTab();
397 } 397 }
398 } else { 398 } else {
399 loading_ = false; 399 loading_ = false;
400 } 400 }
401 } 401 }
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 if (active_session_restorers == NULL) 1185 if (active_session_restorers == NULL)
1186 return false; 1186 return false;
1187 for (std::set<SessionRestoreImpl*>::const_iterator it = 1187 for (std::set<SessionRestoreImpl*>::const_iterator it =
1188 active_session_restorers->begin(); 1188 active_session_restorers->begin();
1189 it != active_session_restorers->end(); ++it) { 1189 it != active_session_restorers->end(); ++it) {
1190 if ((*it)->profile() == profile) 1190 if ((*it)->profile() == profile)
1191 return true; 1191 return true;
1192 } 1192 }
1193 return false; 1193 return false;
1194 } 1194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698