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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/stl_util-inl.h" 16 #include "base/stl_util-inl.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/session_service.h" 21 #include "chrome/browser/sessions/session_service.h"
22 #include "chrome/browser/sessions/session_service_factory.h" 22 #include "chrome/browser/sessions/session_service_factory.h"
23 #include "chrome/browser/sessions/session_types.h" 23 #include "chrome/browser/sessions/session_types.h"
24 #include "chrome/browser/tabs/tab_strip_model.h" 24 #include "chrome/browser/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
27 #include "chrome/browser/ui/browser_navigator.h" 27 #include "chrome/browser/ui/browser_navigator.h"
28 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/common/chrome_notification_types.h"
29 #include "content/browser/renderer_host/render_widget_host.h" 30 #include "content/browser/renderer_host/render_widget_host.h"
30 #include "content/browser/renderer_host/render_widget_host_view.h" 31 #include "content/browser/renderer_host/render_widget_host_view.h"
31 #include "content/browser/tab_contents/navigation_controller.h" 32 #include "content/browser/tab_contents/navigation_controller.h"
32 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/browser/tab_contents/tab_contents_view.h" 34 #include "content/browser/tab_contents/tab_contents_view.h"
34 #include "content/common/notification_registrar.h" 35 #include "content/common/notification_registrar.h"
35 #include "content/common/notification_service.h" 36 #include "content/common/notification_service.h"
36 37
37 #if defined(OS_CHROMEOS) 38 #if defined(OS_CHROMEOS)
38 #include "chrome/browser/chromeos/boot_times_loader.h" 39 #include "chrome/browser/chromeos/boot_times_loader.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 typedef std::set<NavigationController*> TabsLoading; 79 typedef std::set<NavigationController*> TabsLoading;
79 typedef std::list<NavigationController*> TabsToLoad; 80 typedef std::list<NavigationController*> TabsToLoad;
80 typedef std::set<RenderWidgetHost*> RenderWidgetHostSet; 81 typedef std::set<RenderWidgetHost*> RenderWidgetHostSet;
81 82
82 // Loads the next tab. If there are no more tabs to load this deletes itself, 83 // Loads the next tab. If there are no more tabs to load this deletes itself,
83 // otherwise |force_load_timer_| is restarted. 84 // otherwise |force_load_timer_| is restarted.
84 void LoadNextTab(); 85 void LoadNextTab();
85 86
86 // NotificationObserver method. Removes the specified tab and loads the next 87 // NotificationObserver method. Removes the specified tab and loads the next
87 // tab. 88 // tab.
88 virtual void Observe(NotificationType type, 89 virtual void Observe(int type,
89 const NotificationSource& source, 90 const NotificationSource& source,
90 const NotificationDetails& details); 91 const NotificationDetails& details);
91 92
92 // Removes the listeners from the specified tab and removes the tab from 93 // Removes the listeners from the specified tab and removes the tab from
93 // the set of tabs to load and list of tabs we're waiting to get a load 94 // the set of tabs to load and list of tabs we're waiting to get a load
94 // from. 95 // from.
95 void RemoveTab(NavigationController* tab); 96 void RemoveTab(NavigationController* tab);
96 97
97 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes 98 // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes
98 // |LoadNextTab| to load the next tab 99 // |LoadNextTab| to load the next tab
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 DCHECK(find(tabs_loading_.begin(), tabs_loading_.end(), controller) == 171 DCHECK(find(tabs_loading_.begin(), tabs_loading_.end(), controller) ==
171 tabs_loading_.end()); 172 tabs_loading_.end());
172 tabs_loading_.insert(controller); 173 tabs_loading_.insert(controller);
173 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(controller); 174 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(controller);
174 DCHECK(render_widget_host); 175 DCHECK(render_widget_host);
175 render_widget_hosts_loading_.insert(render_widget_host); 176 render_widget_hosts_loading_.insert(render_widget_host);
176 RegisterForNotifications(controller); 177 RegisterForNotifications(controller);
177 } 178 }
178 179
179 void TabLoader::StartLoading() { 180 void TabLoader::StartLoading() {
180 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, 181 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
181 NotificationService::AllSources()); 182 NotificationService::AllSources());
182 #if defined(OS_CHROMEOS) 183 #if defined(OS_CHROMEOS)
183 if (chromeos::NetworkStateNotifier::is_connected()) { 184 if (chromeos::NetworkStateNotifier::is_connected()) {
184 loading_ = true; 185 loading_ = true;
185 LoadNextTab(); 186 LoadNextTab();
186 } else { 187 } else {
187 // Start listening to network state notification now. 188 // Start listening to network state notification now.
188 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, 189 registrar_.Add(this, chrome::NETWORK_STATE_CHANGED,
189 NotificationService::AllSources()); 190 NotificationService::AllSources());
190 } 191 }
191 #else 192 #else
192 loading_ = true; 193 loading_ = true;
193 LoadNextTab(); 194 LoadNextTab();
194 #endif 195 #endif
195 } 196 }
196 197
197 void TabLoader::LoadNextTab() { 198 void TabLoader::LoadNextTab() {
198 if (!tabs_to_load_.empty()) { 199 if (!tabs_to_load_.empty()) {
(...skipping 21 matching lines...) Expand all
220 if (!tabs_to_load_.empty()) { 221 if (!tabs_to_load_.empty()) {
221 force_load_timer_.Stop(); 222 force_load_timer_.Stop();
222 // Each time we load a tab we also set a timer to force us to start loading 223 // Each time we load a tab we also set a timer to force us to start loading
223 // the next tab if this one doesn't load quickly enough. 224 // the next tab if this one doesn't load quickly enough.
224 force_load_timer_.Start( 225 force_load_timer_.Start(
225 base::TimeDelta::FromMilliseconds(force_load_delay_), 226 base::TimeDelta::FromMilliseconds(force_load_delay_),
226 this, &TabLoader::ForceLoadTimerFired); 227 this, &TabLoader::ForceLoadTimerFired);
227 } 228 }
228 } 229 }
229 230
230 void TabLoader::Observe(NotificationType type, 231 void TabLoader::Observe(int type,
231 const NotificationSource& source, 232 const NotificationSource& source,
232 const NotificationDetails& details) { 233 const NotificationDetails& details) {
233 switch (type.value) { 234 switch (type) {
234 #if defined(OS_CHROMEOS) 235 #if defined(OS_CHROMEOS)
235 case NotificationType::NETWORK_STATE_CHANGED: { 236 case chrome::NETWORK_STATE_CHANGED: {
236 chromeos::NetworkStateDetails* state_details = 237 chromeos::NetworkStateDetails* state_details =
237 Details<chromeos::NetworkStateDetails>(details).ptr(); 238 Details<chromeos::NetworkStateDetails>(details).ptr();
238 switch (state_details->state()) { 239 switch (state_details->state()) {
239 case chromeos::NetworkStateDetails::CONNECTED: 240 case chromeos::NetworkStateDetails::CONNECTED:
240 if (!loading_) { 241 if (!loading_) {
241 loading_ = true; 242 loading_ = true;
242 LoadNextTab(); 243 LoadNextTab();
243 } 244 }
244 // Start loading 245 // Start loading
245 break; 246 break;
246 case chromeos::NetworkStateDetails::CONNECTING: 247 case chromeos::NetworkStateDetails::CONNECTING:
247 case chromeos::NetworkStateDetails::DISCONNECTED: 248 case chromeos::NetworkStateDetails::DISCONNECTED:
248 // Disconnected while loading. Set loading_ false so 249 // Disconnected while loading. Set loading_ false so
249 // that it stops trying to load next tab. 250 // that it stops trying to load next tab.
250 loading_ = false; 251 loading_ = false;
251 break; 252 break;
252 default: 253 default:
253 NOTREACHED() << "Unknown nework state notification:" 254 NOTREACHED() << "Unknown nework state notification:"
254 << state_details->state(); 255 << state_details->state();
255 } 256 }
256 break; 257 break;
257 } 258 }
258 #endif 259 #endif
259 case NotificationType::LOAD_START: { 260 case content::NOTIFICATION_LOAD_START: {
260 // Add this render_widget_host to the set of those we're waiting for 261 // Add this render_widget_host to the set of those we're waiting for
261 // paints on. We want to only record stats for paints that occur after 262 // paints on. We want to only record stats for paints that occur after
262 // a load has finished. 263 // a load has finished.
263 NavigationController* tab = Source<NavigationController>(source).ptr(); 264 NavigationController* tab = Source<NavigationController>(source).ptr();
264 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(tab); 265 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(tab);
265 DCHECK(render_widget_host); 266 DCHECK(render_widget_host);
266 render_widget_hosts_loading_.insert(render_widget_host); 267 render_widget_hosts_loading_.insert(render_widget_host);
267 break; 268 break;
268 } 269 }
269 case NotificationType::TAB_CONTENTS_DESTROYED: { 270 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
270 TabContents* tab_contents = Source<TabContents>(source).ptr(); 271 TabContents* tab_contents = Source<TabContents>(source).ptr();
271 if (!got_first_paint_) { 272 if (!got_first_paint_) {
272 RenderWidgetHost* render_widget_host = 273 RenderWidgetHost* render_widget_host =
273 GetRenderWidgetHost(&tab_contents->controller()); 274 GetRenderWidgetHost(&tab_contents->controller());
274 render_widget_hosts_loading_.erase(render_widget_host); 275 render_widget_hosts_loading_.erase(render_widget_host);
275 } 276 }
276 HandleTabClosedOrLoaded(&tab_contents->controller()); 277 HandleTabClosedOrLoaded(&tab_contents->controller());
277 break; 278 break;
278 } 279 }
279 case NotificationType::LOAD_STOP: { 280 case content::NOTIFICATION_LOAD_STOP: {
280 NavigationController* tab = Source<NavigationController>(source).ptr(); 281 NavigationController* tab = Source<NavigationController>(source).ptr();
281 render_widget_hosts_to_paint_.insert(GetRenderWidgetHost(tab)); 282 render_widget_hosts_to_paint_.insert(GetRenderWidgetHost(tab));
282 HandleTabClosedOrLoaded(tab); 283 HandleTabClosedOrLoaded(tab);
283 break; 284 break;
284 } 285 }
285 case NotificationType::RENDER_WIDGET_HOST_DID_PAINT: { 286 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: {
286 if (!got_first_paint_) { 287 if (!got_first_paint_) {
287 RenderWidgetHost* render_widget_host = 288 RenderWidgetHost* render_widget_host =
288 Source<RenderWidgetHost>(source).ptr(); 289 Source<RenderWidgetHost>(source).ptr();
289 if (render_widget_hosts_to_paint_.find(render_widget_host) != 290 if (render_widget_hosts_to_paint_.find(render_widget_host) !=
290 render_widget_hosts_to_paint_.end()) { 291 render_widget_hosts_to_paint_.end()) {
291 // Got a paint for one of our renderers, so record time. 292 // Got a paint for one of our renderers, so record time.
292 got_first_paint_ = true; 293 got_first_paint_ = true;
293 base::TimeDelta time_to_paint = 294 base::TimeDelta time_to_paint =
294 base::TimeTicks::Now() - restore_started_; 295 base::TimeTicks::Now() - restore_started_;
295 UMA_HISTOGRAM_CUSTOM_TIMES( 296 UMA_HISTOGRAM_CUSTOM_TIMES(
(...skipping 20 matching lines...) Expand all
316 // If this is a host for a tab we're not loading some other tab 317 // If this is a host for a tab we're not loading some other tab
317 // has rendered and there's no point tracking the time. This could 318 // has rendered and there's no point tracking the time. This could
318 // happen because the user opened a different tab or restored tabs 319 // happen because the user opened a different tab or restored tabs
319 // to an already existing browser and an existing tab painted. 320 // to an already existing browser and an existing tab painted.
320 got_first_paint_ = true; 321 got_first_paint_ = true;
321 } 322 }
322 } 323 }
323 break; 324 break;
324 } 325 }
325 default: 326 default:
326 NOTREACHED() << "Unknown notification received:" << type.value; 327 NOTREACHED() << "Unknown notification received:" << type;
327 } 328 }
328 // Delete ourselves when we're not waiting for any more notifications. 329 // Delete ourselves when we're not waiting for any more notifications.
329 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) && 330 if ((got_first_paint_ || render_widget_hosts_to_paint_.empty()) &&
330 tabs_loading_.empty() && tabs_to_load_.empty()) 331 tabs_loading_.empty() && tabs_to_load_.empty())
331 delete this; 332 delete this;
332 } 333 }
333 334
334 void TabLoader::RemoveTab(NavigationController* tab) { 335 void TabLoader::RemoveTab(NavigationController* tab) {
335 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, 336 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
336 Source<TabContents>(tab->tab_contents())); 337 Source<TabContents>(tab->tab_contents()));
337 registrar_.Remove(this, NotificationType::LOAD_STOP, 338 registrar_.Remove(this, content::NOTIFICATION_LOAD_STOP,
338 Source<NavigationController>(tab)); 339 Source<NavigationController>(tab));
339 registrar_.Remove(this, NotificationType::LOAD_START, 340 registrar_.Remove(this, content::NOTIFICATION_LOAD_START,
340 Source<NavigationController>(tab)); 341 Source<NavigationController>(tab));
341 342
342 TabsLoading::iterator i = tabs_loading_.find(tab); 343 TabsLoading::iterator i = tabs_loading_.find(tab);
343 if (i != tabs_loading_.end()) 344 if (i != tabs_loading_.end())
344 tabs_loading_.erase(i); 345 tabs_loading_.erase(i);
345 346
346 TabsToLoad::iterator j = 347 TabsToLoad::iterator j =
347 find(tabs_to_load_.begin(), tabs_to_load_.end(), tab); 348 find(tabs_to_load_.begin(), tabs_to_load_.end(), tab);
348 if (j != tabs_to_load_.end()) 349 if (j != tabs_to_load_.end())
349 tabs_to_load_.erase(j); 350 tabs_to_load_.erase(j);
350 } 351 }
351 352
352 void TabLoader::ForceLoadTimerFired() { 353 void TabLoader::ForceLoadTimerFired() {
353 force_load_delay_ *= 2; 354 force_load_delay_ *= 2;
354 LoadNextTab(); 355 LoadNextTab();
355 } 356 }
356 357
357 RenderWidgetHost* TabLoader::GetRenderWidgetHost(NavigationController* tab) { 358 RenderWidgetHost* TabLoader::GetRenderWidgetHost(NavigationController* tab) {
358 TabContents* tab_contents = tab->tab_contents(); 359 TabContents* tab_contents = tab->tab_contents();
359 if (tab_contents) { 360 if (tab_contents) {
360 RenderWidgetHostView* render_widget_host_view = 361 RenderWidgetHostView* render_widget_host_view =
361 tab_contents->GetRenderWidgetHostView(); 362 tab_contents->GetRenderWidgetHostView();
362 if (render_widget_host_view) 363 if (render_widget_host_view)
363 return render_widget_host_view->GetRenderWidgetHost(); 364 return render_widget_host_view->GetRenderWidgetHost();
364 } 365 }
365 return NULL; 366 return NULL;
366 } 367 }
367 368
368 void TabLoader::RegisterForNotifications(NavigationController* controller) { 369 void TabLoader::RegisterForNotifications(NavigationController* controller) {
369 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 370 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
370 Source<TabContents>(controller->tab_contents())); 371 Source<TabContents>(controller->tab_contents()));
371 registrar_.Add(this, NotificationType::LOAD_STOP, 372 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
372 Source<NavigationController>(controller)); 373 Source<NavigationController>(controller));
373 registrar_.Add(this, NotificationType::LOAD_START, 374 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
374 Source<NavigationController>(controller)); 375 Source<NavigationController>(controller));
375 ++tab_count_; 376 ++tab_count_;
376 } 377 }
377 378
378 void TabLoader::HandleTabClosedOrLoaded(NavigationController* tab) { 379 void TabLoader::HandleTabClosedOrLoaded(NavigationController* tab) {
379 RemoveTab(tab); 380 RemoveTab(tab);
380 if (loading_) 381 if (loading_)
381 LoadNextTab(); 382 LoadNextTab();
382 if (tabs_loading_.empty() && tabs_to_load_.empty()) { 383 if (tabs_loading_.empty() && tabs_to_load_.empty()) {
383 base::TimeDelta time_to_load = 384 base::TimeDelta time_to_load =
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 bool old_state = MessageLoop::current()->NestableTasksAllowed(); 441 bool old_state = MessageLoop::current()->NestableTasksAllowed();
441 MessageLoop::current()->SetNestableTasksAllowed(true); 442 MessageLoop::current()->SetNestableTasksAllowed(true);
442 MessageLoop::current()->Run(); 443 MessageLoop::current()->Run();
443 MessageLoop::current()->SetNestableTasksAllowed(old_state); 444 MessageLoop::current()->SetNestableTasksAllowed(old_state);
444 Browser* browser = ProcessSessionWindows(&windows_); 445 Browser* browser = ProcessSessionWindows(&windows_);
445 delete this; 446 delete this;
446 return browser; 447 return browser;
447 } 448 }
448 449
449 if (browser_) { 450 if (browser_) {
450 registrar_.Add(this, NotificationType::BROWSER_CLOSED, 451 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
451 Source<Browser>(browser_)); 452 Source<Browser>(browser_));
452 } 453 }
453 454
454 return browser_; 455 return browser_;
455 } 456 }
456 457
457 // Restore window(s) from a foreign session. 458 // Restore window(s) from a foreign session.
458 void RestoreForeignSession( 459 void RestoreForeignSession(
459 std::vector<SessionWindow*>::const_iterator begin, 460 std::vector<SessionWindow*>::const_iterator begin,
460 std::vector<SessionWindow*>::const_iterator end) { 461 std::vector<SessionWindow*>::const_iterator end) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 current_browser->tab_count()); 493 current_browser->tab_count());
493 FinishedTabCreation(true, true); 494 FinishedTabCreation(true, true);
494 } 495 }
495 496
496 ~SessionRestoreImpl() { 497 ~SessionRestoreImpl() {
497 STLDeleteElements(&windows_); 498 STLDeleteElements(&windows_);
498 restoring = false; 499 restoring = false;
499 g_browser_process->ReleaseModule(); 500 g_browser_process->ReleaseModule();
500 } 501 }
501 502
502 virtual void Observe(NotificationType type, 503 virtual void Observe(int type,
503 const NotificationSource& source, 504 const NotificationSource& source,
504 const NotificationDetails& details) { 505 const NotificationDetails& details) {
505 switch (type.value) { 506 switch (type) {
506 case NotificationType::BROWSER_CLOSED: 507 case chrome::NOTIFICATION_BROWSER_CLOSED:
507 delete this; 508 delete this;
508 return; 509 return;
509 510
510 default: 511 default:
511 NOTREACHED(); 512 NOTREACHED();
512 break; 513 break;
513 } 514 }
514 } 515 }
515 516
516 private: 517 private:
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 std::vector<GURL> gurls; 830 std::vector<GURL> gurls;
830 SessionRestoreImpl restorer(profile, 831 SessionRestoreImpl restorer(profile,
831 static_cast<Browser*>(NULL), true, false, true, gurls); 832 static_cast<Browser*>(NULL), true, false, true, gurls);
832 restorer.RestoreForeignTab(tab); 833 restorer.RestoreForeignTab(tab);
833 } 834 }
834 835
835 // static 836 // static
836 bool SessionRestore::IsRestoring() { 837 bool SessionRestore::IsRestoring() {
837 return restoring; 838 return restoring;
838 } 839 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/restore_tab_helper.cc ('k') | chrome/browser/sessions/session_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698