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

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

Issue 9232007: Fix: after updating, restore tabs from all profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK fix. Created 8 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
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/browser_init_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 458 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
459 } 459 }
460 SessionRestore::RestoreSession( 460 SessionRestore::RestoreSession(
461 profile_, browser, behavior, std::vector<GURL>()); 461 profile_, browser, behavior, std::vector<GURL>());
462 return true; 462 return true;
463 } 463 }
464 464
465 465
466 // Utility functions ---------------------------------------------------------- 466 // Utility functions ----------------------------------------------------------
467 467
468 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line,
469 Profile* profile) {
470 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
471 if (command_line.HasSwitch(switches::kRestoreLastSession) ||
472 BrowserInit::WasRestarted()) {
473 pref.type = SessionStartupPref::LAST;
474 }
475 if (pref.type == SessionStartupPref::LAST &&
476 IncognitoModePrefs::ShouldLaunchIncognito(command_line,
477 profile->GetPrefs())) {
478 // We don't store session information when incognito. If the user has
479 // chosen to restore last session and launched incognito, fallback to
480 // default launch behavior.
481 pref.type = SessionStartupPref::DEFAULT;
482 }
483 return pref;
484 }
485
486 enum LaunchMode { 468 enum LaunchMode {
487 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. 469 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut.
488 LM_AS_WEBAPP, // Launched as a installed web application. 470 LM_AS_WEBAPP, // Launched as a installed web application.
489 LM_WITH_URLS, // Launched with urls in the cmd line. 471 LM_WITH_URLS, // Launched with urls in the cmd line.
490 LM_SHORTCUT_NONE, // Not launched from a shortcut. 472 LM_SHORTCUT_NONE, // Not launched from a shortcut.
491 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available. 473 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available.
492 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut. 474 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut.
493 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar. 475 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar.
494 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut. 476 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut.
495 LM_SHORTCUT_STARTMENU, // Launched from start menu. 477 LM_SHORTCUT_STARTMENU, // Launched from start menu.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 616
635 } // namespace 617 } // namespace
636 618
637 619
638 // BrowserInit ---------------------------------------------------------------- 620 // BrowserInit ----------------------------------------------------------------
639 621
640 BrowserInit::BrowserInit() {} 622 BrowserInit::BrowserInit() {}
641 623
642 BrowserInit::~BrowserInit() {} 624 BrowserInit::~BrowserInit() {}
643 625
626 // static
627 bool BrowserInit::was_restarted_read_ = false;
628
644 void BrowserInit::AddFirstRunTab(const GURL& url) { 629 void BrowserInit::AddFirstRunTab(const GURL& url) {
645 first_run_tabs_.push_back(url); 630 first_run_tabs_.push_back(url);
646 } 631 }
647 632
648 // static 633 // static
649 bool BrowserInit::InProcessStartup() { 634 bool BrowserInit::InProcessStartup() {
650 return in_startup; 635 return in_startup;
651 } 636 }
652 637
653 // static 638 // static
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 713 }
729 #endif 714 #endif
730 return true; 715 return true;
731 } 716 }
732 717
733 // static 718 // static
734 bool BrowserInit::WasRestarted() { 719 bool BrowserInit::WasRestarted() {
735 // Stores the value of the preference kWasRestarted had when it was read. 720 // Stores the value of the preference kWasRestarted had when it was read.
736 static bool was_restarted = false; 721 static bool was_restarted = false;
737 722
738 // True if we have already read and reset the preference kWasRestarted. 723 if (!was_restarted_read_) {
739 static bool was_restarted_read = false;
740
741 if (!was_restarted_read) {
742 PrefService* pref_service = g_browser_process->local_state(); 724 PrefService* pref_service = g_browser_process->local_state();
743 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted); 725 was_restarted = pref_service->GetBoolean(prefs::kWasRestarted);
744 pref_service->SetBoolean(prefs::kWasRestarted, false); 726 pref_service->SetBoolean(prefs::kWasRestarted, false);
745 was_restarted_read = true; 727 was_restarted_read_ = true;
746 } 728 }
747 return was_restarted; 729 return was_restarted;
748 } 730 }
749 731
732 // static
733 SessionStartupPref BrowserInit::GetSessionStartupPref(
734 const CommandLine& command_line,
735 Profile* profile) {
736 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile);
737 if (command_line.HasSwitch(switches::kRestoreLastSession) ||
738 BrowserInit::WasRestarted()) {
739 pref.type = SessionStartupPref::LAST;
740 }
741 if (pref.type == SessionStartupPref::LAST &&
742 IncognitoModePrefs::ShouldLaunchIncognito(command_line,
743 profile->GetPrefs())) {
744 // We don't store session information when incognito. If the user has
745 // chosen to restore last session and launched incognito, fallback to
746 // default launch behavior.
747 pref.type = SessionStartupPref::DEFAULT;
748 }
749 return pref;
750 }
751
752
750 // BrowserInit::LaunchWithProfile::Tab ---------------------------------------- 753 // BrowserInit::LaunchWithProfile::Tab ----------------------------------------
751 754
752 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} 755 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {}
753 756
754 BrowserInit::LaunchWithProfile::Tab::~Tab() {} 757 BrowserInit::LaunchWithProfile::Tab::~Tab() {}
755 758
756 759
757 // BrowserInit::LaunchWithProfile --------------------------------------------- 760 // BrowserInit::LaunchWithProfile ---------------------------------------------
758 761
759 BrowserInit::LaunchWithProfile::LaunchWithProfile( 762 BrowserInit::LaunchWithProfile::LaunchWithProfile(
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 } 1673 }
1671 #endif 1674 #endif
1672 1675
1673 // If we don't want to launch a new browser window or tab (in the case 1676 // If we don't want to launch a new browser window or tab (in the case
1674 // of an automation request), we are done here. 1677 // of an automation request), we are done here.
1675 if (!silent_launch) { 1678 if (!silent_launch) {
1676 IsProcessStartup is_process_startup = process_startup ? 1679 IsProcessStartup is_process_startup = process_startup ?
1677 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; 1680 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP;
1678 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 1681 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
1679 IS_FIRST_RUN : IS_NOT_FIRST_RUN; 1682 IS_FIRST_RUN : IS_NOT_FIRST_RUN;
1680 // Launch the last used profile with the full command line, and the other 1683 // If this is the first launch, or the user has exited the browser by
1681 // opened profiles without the URLs to launch. 1684 // closing all windows for all profiles, there are no last used profiles. In
1682 CommandLine command_line_without_urls(command_line.GetProgram()); 1685 // that case, launch the |last_used_profile|. It will be the initial
1683 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); 1686 // profile, or the profile which owned the last window, respectively.
1684 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); 1687 if (last_opened_profiles.empty()) {
1685 switch_it != switches.end(); ++switch_it) { 1688 if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir,
1686 command_line_without_urls.AppendSwitchNative(switch_it->first, 1689 is_process_startup, is_first_run, return_code))
1687 switch_it->second);
1688 }
1689 if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir,
1690 is_process_startup, is_first_run, return_code))
1691 return false;
1692 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP;
1693
1694 for (Profiles::const_iterator it = last_opened_profiles.begin();
1695 it != last_opened_profiles.end(); ++it) {
1696 if (*it != last_used_profile &&
1697 !browser_init->LaunchBrowser(command_line_without_urls, *it,
1698 cur_dir, is_process_startup, is_first_run, return_code))
1699 return false; 1690 return false;
1691 } else {
1692 // Launch the last used profile with the full command line, and the other
1693 // opened profiles without the URLs to launch.
1694 CommandLine command_line_without_urls(command_line.GetProgram());
1695 const CommandLine::SwitchMap& switches = command_line.GetSwitches();
1696 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin();
1697 switch_it != switches.end(); ++switch_it) {
1698 command_line_without_urls.AppendSwitchNative(switch_it->first,
1699 switch_it->second);
1700 }
1701 // Launch the profiles in the order they became active.
1702 for (Profiles::const_iterator it = last_opened_profiles.begin();
1703 it != last_opened_profiles.end(); ++it) {
1704 if (!browser_init->LaunchBrowser((*it == last_used_profile) ?
1705 command_line : command_line_without_urls, *it, cur_dir,
1706 is_process_startup, is_first_run, return_code))
1707 return false;
1708 // We've launched at least one browser.
1709 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP;
1710 }
1700 } 1711 }
1701 } 1712 }
1702 return true; 1713 return true;
1703 } 1714 }
1704 1715
1705 template <class AutomationProviderClass> 1716 template <class AutomationProviderClass>
1706 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, 1717 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id,
1707 Profile* profile, 1718 Profile* profile,
1708 size_t expected_tabs) { 1719 size_t expected_tabs) {
1709 scoped_refptr<AutomationProviderClass> automation = 1720 scoped_refptr<AutomationProviderClass> automation =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1757
1747 Profile* profile = ProfileManager::GetLastUsedProfile(); 1758 Profile* profile = ProfileManager::GetLastUsedProfile();
1748 if (!profile) { 1759 if (!profile) {
1749 // We should only be able to get here if the profile already exists and 1760 // We should only be able to get here if the profile already exists and
1750 // has been created. 1761 // has been created.
1751 NOTREACHED(); 1762 NOTREACHED();
1752 return; 1763 return;
1753 } 1764 }
1754 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); 1765 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL);
1755 } 1766 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_init.h ('k') | chrome/browser/ui/browser_init_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698