diff options
| author | prasadt@chromium.org <prasadt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 00:57:48 +0000 |
|---|---|---|
| committer | prasadt@chromium.org <prasadt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 00:57:48 +0000 |
| commit | 2ce1d31d6c4c46ad185c49fbe8496396694f57c7 (patch) | |
| tree | 63cb38f8c0cea76664ebc2d4f5e08237d5ef33df /chrome/browser/browser_process_impl.cc | |
| parent | cd92d9ae828e3054af4582e3da8302cf6ad19e2e (diff) | |
| download | chromium_src-2ce1d31d6c4c46ad185c49fbe8496396694f57c7.zip chromium_src-2ce1d31d6c4c46ad185c49fbe8496396694f57c7.tar.gz chromium_src-2ce1d31d6c4c46ad185c49fbe8496396694f57c7.tar.bz2 | |
Detect new instance of the browser when running in the background in persistent
mode, shutdown and restart the new instance. This is already done for Windows,
this CL enables the functionality for Linux.
We don't yet have a unit test for this. Local testing is done by:
1) Reducing the timer to 30 seconds.
2) Changing BrowserList::IsInPersistentMode to return true.
3) Setting BrowserProcessImpl::autoupdate_timer_ to 30 seconds interval.
4) Running "touch" command on chrome exe to pretend there is an update.
BUG=40975
TEST=none
Review URL: http://codereview.chromium.org/1633021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_process_impl.cc')
| -rw-r--r-- | chrome/browser/browser_process_impl.cc | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index ac623a5..05ea69f 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -4,6 +4,8 @@ #include "chrome/browser/browser_process_impl.h" +#include <map> + #include "app/clipboard/clipboard.h" #include "app/l10n_util.h" #include "base/command_line.h" @@ -63,6 +65,12 @@ #include "chrome/common/render_messages.h" #endif +#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +// How often to check if the persistent instance of Chrome needs to restart +// to install an update. +static const int kUpdateCheckIntervalHours = 6; +#endif + BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) : created_resource_dispatcher_host_(false), created_metrics_service_(false), @@ -448,14 +456,14 @@ void BrowserProcessImpl::CheckForInspectorFiles() { NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck)); } -#if defined(OS_WIN) +#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) void BrowserProcessImpl::StartAutoupdateTimer() { autoupdate_timer_.Start( - TimeDelta::FromHours(google_update::kUpdateCheckInvervalHours), + TimeDelta::FromHours(kUpdateCheckIntervalHours), this, &BrowserProcessImpl::OnAutoupdateTimer); } -#endif // OS_WIN +#endif #if defined(IPC_MESSAGE_LOG_ENABLED) @@ -508,8 +516,8 @@ void BrowserProcessImpl::DoInspectorFilesCheck() { have_inspector_files_ = result; } -#if defined(OS_WIN) // Linux doesn't do rename on restart, and Mac is currently - // not supported. +// Mac is currently not supported. +#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) bool BrowserProcessImpl::CanAutorestartForUpdate() const { // Check if browser is in the background and if it needs to be restarted to @@ -531,13 +539,13 @@ const char* const kSwitchesToRemoveOnAutorestart[] = { void BrowserProcessImpl::RestartPersistentInstance() { CommandLine* old_cl = CommandLine::ForCurrentProcess(); - CommandLine new_cl(old_cl->GetProgram()); + scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); std::map<std::string, CommandLine::StringType> switches = old_cl->GetSwitches(); // Remove the keys that we shouldn't pass through during restart. - for (int i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { + for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { switches.erase(kSwitchesToRemoveOnAutorestart[i]); } @@ -547,28 +555,29 @@ void BrowserProcessImpl::RestartPersistentInstance() { switches.begin(); i != switches.end(); ++i) { CommandLine::StringType switch_value = i->second; if (switch_value.length() > 0) { - new_cl.AppendSwitchWithValue(i->first, i->second); + new_cl->AppendSwitchWithValue(i->first, i->second); } else { - new_cl.AppendSwitch(i->first); + new_cl->AppendSwitch(i->first); } } // TODO(atwilson): Uncomment the following two lines to add the "persistence" // switch when the corresponding CL is committed. - // if (!new_cl.HasSwitch(switches::kLongLivedExtensions)) - // new_cl.AppendSwitch(switches::kLongLivedExtensions); + // if (!new_cl->HasSwitch(switches::kLongLivedExtensions)) + // new_cl->AppendSwitch(switches::kLongLivedExtensions); - if (Upgrade::RelaunchChromeBrowser(new_cl)) { - BrowserList::CloseAllBrowsersAndExit(); - } else { - DLOG(ERROR) << "Could not restart browser for autoupdate."; - } + DLOG(WARNING) << "Shutting down current instance of the browser."; + BrowserList::CloseAllBrowsersAndExit(); + + // Transfer ownership to Upgrade. + Upgrade::SetNewCommandLine(new_cl.release()); } void BrowserProcessImpl::OnAutoupdateTimer() { if (CanAutorestartForUpdate()) { + DLOG(WARNING) << "Detected update. Restarting browser."; RestartPersistentInstance(); } } -#endif +#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
