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

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

Issue 1371002: Fixes bug where triggering session restore while the browser was... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sessions/session_service.h" 7 #include "chrome/browser/sessions/session_service.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 : BaseSessionService(SESSION_RESTORE, NULL, save_path), 138 : BaseSessionService(SESSION_RESTORE, NULL, save_path),
139 has_open_trackable_browsers_(false), 139 has_open_trackable_browsers_(false),
140 move_on_new_browser_(false) { 140 move_on_new_browser_(false) {
141 Init(); 141 Init();
142 } 142 }
143 143
144 SessionService::~SessionService() { 144 SessionService::~SessionService() {
145 Save(); 145 Save();
146 } 146 }
147 147
148 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open) {
149 return RestoreIfNecessary(urls_to_open, NULL);
150 }
151
148 void SessionService::ResetFromCurrentBrowsers() { 152 void SessionService::ResetFromCurrentBrowsers() {
149 ScheduleReset(); 153 ScheduleReset();
150 } 154 }
151 155
152 void SessionService::MoveCurrentSessionToLastSession() { 156 void SessionService::MoveCurrentSessionToLastSession() {
153 pending_tab_close_ids_.clear(); 157 pending_tab_close_ids_.clear();
154 window_closing_ids_.clear(); 158 window_closing_ids_.clear();
155 pending_window_close_ids_.clear(); 159 pending_window_close_ids_.clear();
156 160
157 Save(); 161 Save();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 NotificationService::AllSources()); 436 NotificationService::AllSources());
433 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 437 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
434 NotificationService::AllSources()); 438 NotificationService::AllSources());
435 registrar_.Add(this, NotificationType::BROWSER_OPENED, 439 registrar_.Add(this, NotificationType::BROWSER_OPENED,
436 NotificationService::AllSources()); 440 NotificationService::AllSources());
437 registrar_.Add(this, 441 registrar_.Add(this,
438 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, 442 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
439 NotificationService::AllSources()); 443 NotificationService::AllSources());
440 } 444 }
441 445
446 bool SessionService::RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
447 Browser* browser) {
448 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() &&
449 !SessionRestore::IsRestoring()
450 #if defined(OS_MACOSX)
451 // OSX has a fairly different idea of application lifetime than the
452 // other platforms. We need to check that we aren't opening a window
453 // from the dock or the menubar.
454 && !app_controller_mac::IsOpeningNewWindow()
455 #endif
456 ) {
457 // We're going from no tabbed browsers to a tabbed browser (and not in
458 // process startup), restore the last session.
459 if (move_on_new_browser_) {
460 // Make the current session the last.
461 MoveCurrentSessionToLastSession();
462 move_on_new_browser_ = false;
463 }
464 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile());
465 if (pref.type == SessionStartupPref::LAST) {
466 SessionRestore::RestoreSession(
467 profile(), browser, false, browser ? false : true, urls_to_open);
468 return true;
469 }
470 }
471 return false;
472 }
473
442 void SessionService::Observe(NotificationType type, 474 void SessionService::Observe(NotificationType type,
443 const NotificationSource& source, 475 const NotificationSource& source,
444 const NotificationDetails& details) { 476 const NotificationDetails& details) {
445 // All of our messages have the NavigationController as the source. 477 // All of our messages have the NavigationController as the source.
446 switch (type.value) { 478 switch (type.value) {
447 case NotificationType::BROWSER_OPENED: { 479 case NotificationType::BROWSER_OPENED: {
448 Browser* browser = Source<Browser>(source).ptr(); 480 Browser* browser = Source<Browser>(source).ptr();
449 if (browser->profile() != profile() || 481 if (browser->profile() != profile() ||
450 !should_track_changes_for_browser_type(browser->type())) { 482 !should_track_changes_for_browser_type(browser->type())) {
451 return; 483 return;
452 } 484 }
453 485
454 if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup() 486 RestoreIfNecessary(std::vector<GURL>(), browser);
455 #if defined(OS_MACOSX)
456 // OSX has a fairly different idea of application lifetime than the
457 // other platforms. We need to check that we aren't opening a window
458 // from the dock or the menubar.
459 && !app_controller_mac::IsOpeningNewWindow()
460 #endif
461 ) {
462 // We're going from no tabbed browsers to a tabbed browser (and not in
463 // process startup), restore the last session.
464 if (move_on_new_browser_) {
465 // Make the current session the last.
466 MoveCurrentSessionToLastSession();
467 move_on_new_browser_ = false;
468 }
469 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile());
470 if (pref.type == SessionStartupPref::LAST) {
471 SessionRestore::RestoreSession(
472 profile(), browser, false, false, std::vector<GURL>());
473 }
474 }
475 SetWindowType(browser->session_id(), browser->type()); 487 SetWindowType(browser->session_id(), browser->type());
476 break; 488 break;
477 } 489 }
478 490
479 case NotificationType::TAB_PARENTED: { 491 case NotificationType::TAB_PARENTED: {
480 NavigationController* controller = 492 NavigationController* controller =
481 Source<NavigationController>(source).ptr(); 493 Source<NavigationController>(source).ptr();
482 SetTabWindow(controller->window_id(), controller->session_id()); 494 SetTabWindow(controller->window_id(), controller->session_id());
483 if (controller->tab_contents()->app_extension()) { 495 if (controller->tab_contents()->app_extension()) {
484 SetTabAppExtensionID( 496 SetTabAppExtensionID(
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 return Browser::TYPE_APP_POPUP; 1296 return Browser::TYPE_APP_POPUP;
1285 case TYPE_DEVTOOLS: 1297 case TYPE_DEVTOOLS:
1286 return Browser::TYPE_DEVTOOLS; 1298 return Browser::TYPE_DEVTOOLS;
1287 case TYPE_APP_PANEL: 1299 case TYPE_APP_PANEL:
1288 return Browser::TYPE_APP_PANEL; 1300 return Browser::TYPE_APP_PANEL;
1289 case TYPE_NORMAL: 1301 case TYPE_NORMAL:
1290 default: 1302 default:
1291 return Browser::TYPE_NORMAL; 1303 return Browser::TYPE_NORMAL;
1292 } 1304 }
1293 } 1305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698