summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_process_impl.cc
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 19:42:54 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 19:42:54 +0000
commit404df1613316a15634d5ba70fdbf32c85c0032e4 (patch)
treef6bab7adf02b7f785aa2101466a32b5eee8404df /chrome/browser/browser_process_impl.cc
parentfc33e999e1c6426050e231d8dfcc38ddd3deb375 (diff)
downloadchromium_src-404df1613316a15634d5ba70fdbf32c85c0032e4.zip
chromium_src-404df1613316a15634d5ba70fdbf32c85c0032e4.tar.gz
chromium_src-404df1613316a15634d5ba70fdbf32c85c0032e4.tar.bz2
This is a new version of the older patch. Main changes include:
1. Rebased to a never Git revision to make things easier to land. 2. Chrome will now preserve the command line switches except for those that are blacklisted. 3. Fixed a race condition that would cause the browser to think it didn't exit cleanly after it's been restarted. 4. Fixed minor nits and omissions (indentation, etc). This patch adds a timer which fires every 6 hours and checks whether the browser is in the "persistent" (background) mode, and whether there's an update pending restart. If both conditions are true, the browser is restarted with blacklisted command line keys and all loose values stripped. In order to restart the browser in the background mode, the --long-lived-extensions key is also added to the command line. This change is Windows-only, and it won't become fully functional until Drew (atwilson) checks in his work that enables Chrome to go into background. Review URL: http://codereview.chromium.org/1617001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43989 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_process_impl.cc')
-rw-r--r--chrome/browser/browser_process_impl.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index afaf666..be8b601 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -12,6 +12,7 @@
#include "base/thread.h"
#include "base/waitable_event.h"
#include "chrome/browser/appcache/chrome_appcache_service.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_main.h"
#include "chrome/browser/browser_process_sub_thread.h"
#include "chrome/browser/browser_trial.h"
@@ -21,6 +22,7 @@
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/download/save_file_manager.h"
+#include "chrome/browser/first_run.h"
#include "chrome/browser/google_url_tracker.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/in_process_webkit/dom_storage_context.h"
@@ -47,6 +49,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "chrome/installer/util/google_update_constants.h"
#include "ipc/ipc_logging.h"
#include "webkit/database/database_tracker.h"
@@ -444,6 +447,15 @@ void BrowserProcessImpl::CheckForInspectorFiles() {
NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
}
+#if defined(OS_WIN)
+void BrowserProcessImpl::StartAutoupdateTimer() {
+ autoupdate_timer_.Start(
+ TimeDelta::FromHours(google_update::kUpdateCheckInvervalHours),
+ this,
+ &BrowserProcessImpl::OnAutoupdateTimer);
+}
+#endif // OS_WIN
+
#if defined(IPC_MESSAGE_LOG_ENABLED)
void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
@@ -494,3 +506,68 @@ void BrowserProcessImpl::DoInspectorFilesCheck() {
have_inspector_files_ = result;
}
+
+#if defined(OS_WIN) // Linux doesn't do rename on restart, and Mac is currently
+ // not supported.
+
+bool BrowserProcessImpl::CanAutorestartForUpdate() const {
+ // Check if browser is in the background and if it needs to be restarted to
+ // apply a pending update.
+ return BrowserList::IsInPersistentMode() && Upgrade::IsUpdatePendingRestart();
+}
+
+// Switches enumerated here will be removed when a background instance of
+// Chrome restarts itself. If your key is designed to only be used once,
+// or if it does not make sense when restarting a background instance to
+// pick up an automatic update, be sure to add it to this list.
+const char* const kSwitchesToRemoveOnAutorestart[] = {
+ switches::kApp,
+ switches::kFirstRun,
+ switches::kImport,
+ switches::kImportFromFile,
+ switches::kMakeDefaultBrowser
+};
+
+void BrowserProcessImpl::RestartPersistentInstance() {
+ CommandLine* old_cl = CommandLine::ForCurrentProcess();
+ CommandLine new_cl(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++) {
+ switches.erase(kSwitchesToRemoveOnAutorestart[i]);
+ }
+
+ // Append the rest of the switches (along with their values, if any)
+ // to the new command line
+ for (std::map<std::string, CommandLine::StringType>::const_iterator i =
+ switches.begin(); i != switches.end(); ++i) {
+ CommandLine::StringType switch_value = i->second;
+ if (switch_value.length() > 0) {
+ new_cl.AppendSwitchWithValue(i->first, i->second);
+ } else {
+ 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 (Upgrade::RelaunchChromeBrowser(new_cl)) {
+ BrowserList::CloseAllBrowsersAndExit();
+ } else {
+ DLOG(ERROR) << "Could not restart browser for autoupdate.";
+ }
+}
+
+void BrowserProcessImpl::OnAutoupdateTimer() {
+ if (CanAutorestartForUpdate()) {
+ RestartPersistentInstance();
+ }
+}
+
+#endif