Chromium Code Reviews| Index: chrome/browser/ui/browser_init.cc |
| diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc |
| index d59e0bf1f5c25108aeb338bcba5f720991933c83..031e4ab726be568af939fc99f97b7b62b32c5f27 100644 |
| --- a/chrome/browser/ui/browser_init.cc |
| +++ b/chrome/browser/ui/browser_init.cc |
| @@ -45,7 +45,6 @@ |
| #include "chrome/browser/notifications/desktop_notification_service.h" |
| #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| -#include "chrome/browser/prefs/session_startup_pref.h" |
| #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" |
| #include "chrome/browser/printing/print_dialog_cloud.h" |
| @@ -465,24 +464,6 @@ bool SessionCrashedInfoBarDelegate::Accept() { |
| // Utility functions ---------------------------------------------------------- |
| -SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, |
| - Profile* profile) { |
| - SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); |
| - if (command_line.HasSwitch(switches::kRestoreLastSession) || |
| - BrowserInit::WasRestarted()) { |
| - pref.type = SessionStartupPref::LAST; |
| - } |
| - if (pref.type == SessionStartupPref::LAST && |
| - IncognitoModePrefs::ShouldLaunchIncognito(command_line, |
| - profile->GetPrefs())) { |
| - // We don't store session information when incognito. If the user has |
| - // chosen to restore last session and launched incognito, fallback to |
| - // default launch behavior. |
| - pref.type = SessionStartupPref::DEFAULT; |
| - } |
| - return pref; |
| -} |
| - |
| enum LaunchMode { |
| LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. |
| LM_AS_WEBAPP, // Launched as a installed web application. |
| @@ -641,6 +622,9 @@ BrowserInit::BrowserInit() {} |
| BrowserInit::~BrowserInit() {} |
| +// static |
| +bool BrowserInit::was_restarted_read_ = false; |
| + |
| void BrowserInit::AddFirstRunTab(const GURL& url) { |
| first_run_tabs_.push_back(url); |
| } |
| @@ -735,18 +719,36 @@ bool BrowserInit::WasRestarted() { |
| // Stores the value of the preference kWasRestarted had when it was read. |
| static bool was_restarted = false; |
| - // True if we have already read and reset the preference kWasRestarted. |
| - static bool was_restarted_read = false; |
| - |
| - if (!was_restarted_read) { |
| + if (!was_restarted_read_) { |
| PrefService* pref_service = g_browser_process->local_state(); |
| was_restarted = pref_service->GetBoolean(prefs::kWasRestarted); |
| pref_service->SetBoolean(prefs::kWasRestarted, false); |
| - was_restarted_read = true; |
| + was_restarted_read_ = true; |
| } |
| return was_restarted; |
| } |
| +// static |
| +SessionStartupPref BrowserInit::GetSessionStartupPref( |
| + const CommandLine& command_line, |
| + Profile* profile) { |
| + SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); |
| + if (command_line.HasSwitch(switches::kRestoreLastSession) || |
| + BrowserInit::WasRestarted()) { |
| + pref.type = SessionStartupPref::LAST; |
| + } |
| + if (pref.type == SessionStartupPref::LAST && |
| + IncognitoModePrefs::ShouldLaunchIncognito(command_line, |
| + profile->GetPrefs())) { |
| + // We don't store session information when incognito. If the user has |
| + // chosen to restore last session and launched incognito, fallback to |
| + // default launch behavior. |
| + pref.type = SessionStartupPref::DEFAULT; |
| + } |
| + return pref; |
| +} |
| + |
| + |
| // BrowserInit::LaunchWithProfile::Tab ---------------------------------------- |
| BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} |
| @@ -1686,16 +1688,23 @@ bool BrowserInit::ProcessCmdLineImpl( |
| command_line_without_urls.AppendSwitchNative(switch_it->first, |
| switch_it->second); |
| } |
| - if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir, |
| - is_process_startup, is_first_run, return_code)) |
| - return false; |
| - is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP; |
| - |
| + // Launch the profiles in the order they became active. |
| for (Profiles::const_iterator it = last_opened_profiles.begin(); |
| it != last_opened_profiles.end(); ++it) { |
| - if (*it != last_used_profile && |
| - !browser_init->LaunchBrowser(command_line_without_urls, *it, |
| - cur_dir, is_process_startup, is_first_run, return_code)) |
| + if (!browser_init->LaunchBrowser((*it == last_used_profile) ? |
| + command_line : command_line_without_urls, *it, cur_dir, |
| + is_process_startup, is_first_run, return_code)) |
| + return false; |
| + // We've launched at least one browser. |
| + is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP; |
| + } |
| + // If this is the first launch, there are no last used or last opened |
| + // profiles. In that case, |last_used_profile| will be the initial profile |
| + // and |last_opened_profiles| will be empty. Launch the initial profile in |
| + // that case. |
| + if (last_opened_profiles.empty()) { |
|
Peter Kasting
2012/01/18 18:04:30
Nit: We might also want to DCHECK(is_first_run) in
marja
2012/01/19 08:38:23
Done.
marja
2012/01/19 10:27:02
Oops, I was wrong. The "first run" is not the only
|
| + if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir, |
| + is_process_startup, is_first_run, return_code)) |
| return false; |
| } |
| } |