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

Side by Side Diff: chrome/browser/ui/browser_init.cc

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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/ui/browser_init.h" 5 #include "chrome/browser/ui/browser_init.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 300
301 private: 301 private:
302 virtual ~SessionCrashedInfoBarDelegate(); 302 virtual ~SessionCrashedInfoBarDelegate();
303 303
304 // ConfirmInfoBarDelegate: 304 // ConfirmInfoBarDelegate:
305 virtual gfx::Image* GetIcon() const OVERRIDE; 305 virtual gfx::Image* GetIcon() const OVERRIDE;
306 virtual string16 GetMessageText() const OVERRIDE; 306 virtual string16 GetMessageText() const OVERRIDE;
307 virtual int GetButtons() const OVERRIDE; 307 virtual int GetButtons() const OVERRIDE;
308 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 308 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
309 virtual bool Accept() OVERRIDE; 309 virtual bool Accept() OVERRIDE;
310 virtual void InfoBarDismissed() OVERRIDE;
311 virtual void InfoBarClosing() OVERRIDE;
310 312
311 // The Profile that we restore sessions from. 313 // The Profile that we restore sessions from.
312 Profile* profile_; 314 Profile* profile_;
315 bool action_taken_;
313 316
314 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); 317 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
315 }; 318 };
316 319
317 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( 320 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
318 Profile* profile, 321 Profile* profile,
319 InfoBarTabHelper* infobar_helper) 322 InfoBarTabHelper* infobar_helper)
320 : ConfirmInfoBarDelegate(infobar_helper), 323 : ConfirmInfoBarDelegate(infobar_helper),
321 profile_(profile) { 324 profile_(profile),
325 action_taken_(false) {
322 } 326 }
323 327
324 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { 328 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
325 } 329 }
326 330
327 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const { 331 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const {
328 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 332 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
329 IDR_INFOBAR_RESTORE_SESSION); 333 IDR_INFOBAR_RESTORE_SESSION);
330 } 334 }
331 335
332 string16 SessionCrashedInfoBarDelegate::GetMessageText() const { 336 string16 SessionCrashedInfoBarDelegate::GetMessageText() const {
333 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE); 337 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE);
334 } 338 }
335 339
336 int SessionCrashedInfoBarDelegate::GetButtons() const { 340 int SessionCrashedInfoBarDelegate::GetButtons() const {
337 return BUTTON_OK; 341 return BUTTON_OK;
338 } 342 }
339 343
340 string16 SessionCrashedInfoBarDelegate::GetButtonLabel( 344 string16 SessionCrashedInfoBarDelegate::GetButtonLabel(
341 InfoBarButton button) const { 345 InfoBarButton button) const {
342 DCHECK_EQ(BUTTON_OK, button); 346 DCHECK_EQ(BUTTON_OK, button);
343 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); 347 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON);
344 } 348 }
345 349
346 bool SessionCrashedInfoBarDelegate::Accept() { 350 bool SessionCrashedInfoBarDelegate::Accept() {
351 action_taken_ = true;
347 uint32 behavior = 0; 352 uint32 behavior = 0;
348 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 353 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
349 if (browser && browser->tab_count() == 1 354 if (browser && browser->tab_count() == 1
350 && browser->GetTabContentsAt(0)->GetURL() == 355 && browser->GetTabContentsAt(0)->GetURL() ==
351 GURL(chrome::kChromeUINewTabURL)) { 356 GURL(chrome::kChromeUINewTabURL)) {
352 // There is only one tab and its the new tab page, make session restore 357 // There is only one tab and its the new tab page, make session restore
353 // clobber it. 358 // clobber it.
354 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 359 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
355 } 360 }
361 profile_->RestoreSessionState();
356 SessionRestore::RestoreSession( 362 SessionRestore::RestoreSession(
357 profile_, browser, behavior, std::vector<GURL>()); 363 profile_, browser, behavior, std::vector<GURL>());
358 return true; 364 return true;
359 } 365 }
360 366
367 void SessionCrashedInfoBarDelegate::InfoBarDismissed() {
368 action_taken_ = true;
369 profile_->DiscardSessionState();
370 }
371
372 void SessionCrashedInfoBarDelegate::InfoBarClosing() {
373 if (!action_taken_)
374 profile_->DiscardSessionState();
375 }
361 376
362 // Utility functions ---------------------------------------------------------- 377 // Utility functions ----------------------------------------------------------
363 378
364 bool IncognitoIsForced(const CommandLine& command_line, 379 bool IncognitoIsForced(const CommandLine& command_line,
365 const PrefService* prefs) { 380 const PrefService* prefs) {
366 IncognitoModePrefs::Availability incognito_avail = 381 IncognitoModePrefs::Availability incognito_avail =
367 IncognitoModePrefs::GetAvailability(prefs); 382 IncognitoModePrefs::GetAvailability(prefs);
368 return incognito_avail != IncognitoModePrefs::DISABLED && 383 return incognito_avail != IncognitoModePrefs::DISABLED &&
369 (command_line.HasSwitch(switches::kIncognito) || 384 (command_line.HasSwitch(switches::kIncognito) ||
370 incognito_avail == IncognitoModePrefs::FORCED); 385 incognito_avail == IncognitoModePrefs::FORCED);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 924
910 if (pref.type == SessionStartupPref::LAST) { 925 if (pref.type == SessionStartupPref::LAST) {
911 if (!profile_->DidLastSessionExitCleanly() && 926 if (!profile_->DidLastSessionExitCleanly() &&
912 !command_line_.HasSwitch(switches::kRestoreLastSession)) { 927 !command_line_.HasSwitch(switches::kRestoreLastSession)) {
913 // The last session crashed. It's possible automatically loading the 928 // The last session crashed. It's possible automatically loading the
914 // page will trigger another crash, locking the user out of chrome. 929 // page will trigger another crash, locking the user out of chrome.
915 // To avoid this, don't restore on startup but instead show the crashed 930 // To avoid this, don't restore on startup but instead show the crashed
916 // infobar. 931 // infobar.
917 return false; 932 return false;
918 } 933 }
934 if (command_line_.HasSwitch(switches::kEnableRestoreSessionState) &&
935 command_line_.HasSwitch(switches::kRestoreLastSession)) {
936 profile_->RestoreSessionState();
937 } else {
938 profile_->DiscardSessionState();
939 }
919 940
920 uint32 restore_behavior = SessionRestore::SYNCHRONOUS | 941 uint32 restore_behavior = SessionRestore::SYNCHRONOUS |
921 SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; 942 SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
922 #if defined(OS_MACOSX) 943 #if defined(OS_MACOSX)
923 // On Mac, when restoring a session with no windows, suppress the creation 944 // On Mac, when restoring a session with no windows, suppress the creation
924 // of a new window in the case where the system is launching Chrome via a 945 // of a new window in the case where the system is launching Chrome via a
925 // login item or Lion's resume feature. 946 // login item or Lion's resume feature.
926 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { 947 if (base::mac::WasLaunchedAsLoginOrResumeItem()) {
927 restore_behavior = restore_behavior & 948 restore_behavior = restore_behavior &
928 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; 949 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
929 } 950 }
930 #endif 951 #endif
931 952
932 Browser* browser = SessionRestore::RestoreSession(profile_, 953 Browser* browser = SessionRestore::RestoreSession(profile_,
933 NULL, 954 NULL,
934 restore_behavior, 955 restore_behavior,
935 urls_to_open); 956 urls_to_open);
936 AddInfoBarsIfNecessary(browser); 957 AddInfoBarsIfNecessary(browser);
937 return true; 958 return true;
959 } else if (profile_->DidLastSessionExitCleanly()) {
960 profile_->DiscardSessionState();
938 } 961 }
939 962
940 Browser* browser = ProcessSpecifiedURLs(urls_to_open); 963 Browser* browser = ProcessSpecifiedURLs(urls_to_open);
941 if (!browser) 964 if (!browser)
942 return false; 965 return false;
943 966
944 AddInfoBarsIfNecessary(browser); 967 AddInfoBarsIfNecessary(browser);
945 return true; 968 return true;
946 } 969 }
947 970
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 if (!automation->InitializeChannel(channel_id)) 1544 if (!automation->InitializeChannel(channel_id))
1522 return false; 1545 return false;
1523 automation->SetExpectedTabCount(expected_tabs); 1546 automation->SetExpectedTabCount(expected_tabs);
1524 1547
1525 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); 1548 AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
1526 DCHECK(list); 1549 DCHECK(list);
1527 list->AddProvider(automation); 1550 list->AddProvider(automation);
1528 1551
1529 return true; 1552 return true;
1530 } 1553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698