summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 09:35:38 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 09:35:38 +0000
commitc149b9198168ca08da0a30d4fb63f0eb232d6001 (patch)
treea01d50991492a1d81b661cf0f67995aa0b44ba71 /chrome/installer
parent82d3954ae9ccbd99fc48b99296e70f63dc883010 (diff)
downloadchromium_src-c149b9198168ca08da0a30d4fb63f0eb232d6001.zip
chromium_src-c149b9198168ca08da0a30d4fb63f0eb232d6001.tar.gz
chromium_src-c149b9198168ca08da0a30d4fb63f0eb232d6001.tar.bz2
Resolve the conflict that auto-launch has with the background mode feature.
The Auto-launch experiment writes to the Run Registry key on Windows asking for Chrome to be started at login. The BackgroundModeManager writes to another Run Registry key asking for Chrome to be started without a window. We need to consolidate this into one Run key that specifies which feature you want as a command line flag to chrome.exe and make sure if a window is requested, then a window is shown (BackgroundModeManager doesn't care if the window is shown or not). BUG=123139, 53600 TEST=QA has testing instructions on how to test the experimental auto-launch feature (requires branded build). Not sure about testing instructions for background mode. Review URL: https://chromiumcodereview.appspot.com/9972012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/setup/install.cc7
-rw-r--r--chrome/installer/setup/uninstall.cc8
-rw-r--r--chrome/installer/util/auto_launch_util.cc172
-rw-r--r--chrome/installer/util/auto_launch_util.h76
4 files changed, 212 insertions, 51 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc
index a434478..2ceac7d 100644
--- a/chrome/installer/setup/install.cc
+++ b/chrome/installer/setup/install.cc
@@ -450,10 +450,9 @@ InstallStatus InstallOrUpdateProduct(
installer::master_preferences::kAutoLaunchChrome,
&auto_launch_chrome);
if (auto_launch_chrome) {
- auto_launch_util::SetWillLaunchAtLogin(
- true,
- installer_state.target_path(),
- ASCIIToUTF16(chrome::kInitialProfile));
+ auto_launch_util::EnableForegroundStartAtLogin(
+ ASCIIToUTF16(chrome::kInitialProfile),
+ installer_state.target_path());
}
}
}
diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc
index cb80ee8..836b384 100644
--- a/chrome/installer/setup/uninstall.cc
+++ b/chrome/installer/setup/uninstall.cc
@@ -777,12 +777,8 @@ InstallStatus UninstallProduct(const InstallationState& original_state,
if (is_chrome) {
ClearRlzProductState();
- if (auto_launch_util::WillLaunchAtLogin(
- installer_state.target_path(),
- ASCIIToUTF16(chrome::kInitialProfile))) {
- auto_launch_util::SetWillLaunchAtLogin(
- false, FilePath(), ASCIIToUTF16(chrome::kInitialProfile));
- }
+ auto_launch_util::DisableAllAutoStartFeatures(
+ ASCIIToUTF16(chrome::kInitialProfile));
}
// First delete shortcuts from Start->Programs, Desktop & Quick Launch.
diff --git a/chrome/installer/util/auto_launch_util.cc b/chrome/installer/util/auto_launch_util.cc
index 1904697..fdbf96e 100644
--- a/chrome/installer/util/auto_launch_util.cc
+++ b/chrome/installer/util/auto_launch_util.cc
@@ -11,6 +11,7 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/win/win_util.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/installer/util/browser_distribution.h"
@@ -23,6 +24,15 @@ namespace auto_launch_util {
// The prefix of the Chrome Auto-launch key under the Run key.
const wchar_t kAutolaunchKeyValue[] = L"GoogleChromeAutoLaunch";
+// We use one Run key with flags specifying which feature we want to start up.
+// When we change our Run key we need to specify what we want to do with each
+// flag. This lists the possible actions we can take with the flags.
+enum FlagSetting {
+ FLAG_DISABLE, // Disable the flag.
+ FLAG_ENABLE, // Enable the flag.
+ FLAG_PRESERVE, // Preserve the value that the flag has currently.
+};
+
// A helper function that takes a |profile_path| and builds a registry key
// name to use when deciding where to read/write the auto-launch value
// to/from. It takes into account the name of the profile (so that different
@@ -52,8 +62,18 @@ string16 ProfileToKeyName(const string16& profile_directory) {
ASCIIToWide("_") + ASCIIToWide(hash_string);
}
-bool WillLaunchAtLogin(const FilePath& application_path,
- const string16& profile_directory) {
+// Returns whether the Chrome executable specified in |application_path| is set
+// to auto-launch at computer startup with a given |command_line_switch|.
+// NOTE: |application_path| is optional and should be blank in most cases (as
+// it will default to the application path of the current executable).
+// |profile_directory| is the name of the directory (leaf, not the full path)
+// that contains the profile that should be opened at computer startup.
+// |command_line_switch| is the switch we are optionally interested in and, if
+// not blank, must be present for the function to return true. If blank, it acts
+// like a wildcard.
+bool WillLaunchAtLoginWithSwitch(const FilePath& application_path,
+ const string16& profile_directory,
+ const std::string& command_line_switch) {
string16 key_name(ProfileToKeyName(profile_directory));
string16 autolaunch;
if (!base::win::ReadCommandFromAutoRun(
@@ -70,16 +90,86 @@ bool WillLaunchAtLogin(const FilePath& application_path,
}
chrome_exe = chrome_exe.Append(installer::kChromeExe);
- return autolaunch.find(chrome_exe.value()) != string16::npos;
+ if (autolaunch.find(chrome_exe.value()) == string16::npos)
+ return false;
+
+ return command_line_switch.empty() ||
+ autolaunch.find(ASCIIToUTF16(command_line_switch)) != string16::npos;
+}
+
+bool AutoStartRequested(const string16& profile_directory,
+ bool window_requested,
+ const FilePath& application_path) {
+ if (window_requested) {
+ return WillLaunchAtLoginWithSwitch(application_path,
+ profile_directory,
+ switches::kAutoLaunchAtStartup);
+ } else {
+ // Background mode isn't profile specific, but is attached to the Run key
+ // for the Default profile.
+ return WillLaunchAtLoginWithSwitch(application_path,
+ ASCIIToUTF16(chrome::kInitialProfile),
+ switches::kNoStartupWindow);
+ }
+}
+
+bool CheckAndRemoveDeprecatedBackgroundModeSwitch() {
+ // For backwards compatibility we need to provide a migration path from the
+ // previously used key "chromium" that the BackgroundMode used to set, as it
+ // is incompatible with the new key (can't have two Run keys with
+ // conflicting switches).
+ string16 chromium = ASCIIToUTF16("chromium");
+ string16 value;
+ if (base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, chromium, &value)) {
+ if (value.find(ASCIIToUTF16(switches::kNoStartupWindow)) !=
+ string16::npos) {
+ base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, chromium);
+ return true;
+ }
+ }
+
+ return false;
}
-void SetWillLaunchAtLogin(bool auto_launch,
- const FilePath& application_path,
- const string16& profile_directory) {
+void SetWillLaunchAtLogin(const FilePath& application_path,
+ const string16& profile_directory,
+ FlagSetting foreground_mode,
+ FlagSetting background_mode) {
+ if (CheckAndRemoveDeprecatedBackgroundModeSwitch()) {
+ // We've found the deprecated switch, we must migrate it (unless background
+ // mode is being turned off).
+ if (profile_directory == ASCIIToUTF16(chrome::kInitialProfile) &&
+ background_mode == FLAG_PRESERVE) {
+ // Preserve in this case also covers the deprecated value, so we must
+ // explicitly turn the flag on and the rest will be taken care of below.
+ background_mode = FLAG_ENABLE;
+ } else {
+ // When we add support for multiple profiles for foreground mode we need
+ // to think about where to store the background mode switch. I think we
+ // need to store it with the Default profile (call SetWillLaunchAtLogin
+ // again specifying the Default profile), but concerns were raised in
+ // review.
+ NOTREACHED();
+ }
+ }
string16 key_name(ProfileToKeyName(profile_directory));
+ // Check which feature should be enabled.
+ bool in_foreground =
+ foreground_mode == FLAG_ENABLE ||
+ (foreground_mode == FLAG_PRESERVE &&
+ WillLaunchAtLoginWithSwitch(application_path,
+ profile_directory,
+ switches::kAutoLaunchAtStartup));
+ bool in_background =
+ background_mode == FLAG_ENABLE ||
+ (background_mode == FLAG_PRESERVE &&
+ WillLaunchAtLoginWithSwitch(application_path,
+ profile_directory,
+ switches::kNoStartupWindow));
+
// TODO(finnur): Convert this into a shortcut, instead of using the Run key.
- if (auto_launch) {
+ if (in_foreground || in_background) {
FilePath path(application_path);
if (path.empty()) {
if (!PathService::Get(base::DIR_EXE, &path)) {
@@ -91,25 +181,33 @@ void SetWillLaunchAtLogin(bool auto_launch,
cmd_line += path.value();
cmd_line += ASCIIToUTF16("\\");
cmd_line += installer::kChromeExe;
- cmd_line += ASCIIToUTF16("\" --");
- cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup);
+ cmd_line += ASCIIToUTF16("\"");
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kUserDataDir)) {
+ if (in_background) {
cmd_line += ASCIIToUTF16(" --");
- cmd_line += ASCIIToUTF16(switches::kUserDataDir);
+ cmd_line += ASCIIToUTF16(switches::kNoStartupWindow);
+ }
+ if (in_foreground) {
+ cmd_line += ASCIIToUTF16(" --");
+ cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup);
+
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kUserDataDir)) {
+ cmd_line += ASCIIToUTF16(" --");
+ cmd_line += ASCIIToUTF16(switches::kUserDataDir);
+ cmd_line += ASCIIToUTF16("=\"");
+ cmd_line +=
+ command_line.GetSwitchValuePath(switches::kUserDataDir).value();
+ cmd_line += ASCIIToUTF16("\"");
+ }
+
+ cmd_line += ASCIIToUTF16(" --");
+ cmd_line += ASCIIToUTF16(switches::kProfileDirectory);
cmd_line += ASCIIToUTF16("=\"");
- cmd_line +=
- command_line.GetSwitchValuePath(switches::kUserDataDir).value();
+ cmd_line += profile_directory;
cmd_line += ASCIIToUTF16("\"");
}
- cmd_line += ASCIIToUTF16(" --");
- cmd_line += ASCIIToUTF16(switches::kProfileDirectory);
- cmd_line += ASCIIToUTF16("=\"");
- cmd_line += profile_directory;
- cmd_line += ASCIIToUTF16("\"");
-
base::win::AddCommandToAutoRun(
HKEY_CURRENT_USER, key_name, cmd_line);
} else {
@@ -117,4 +215,38 @@ void SetWillLaunchAtLogin(bool auto_launch,
}
}
+void DisableAllAutoStartFeatures(const string16& profile_directory) {
+ DisableForegroundStartAtLogin(profile_directory);
+ DisableBackgroundStartAtLogin();
+}
+
+void EnableForegroundStartAtLogin(const string16& profile_directory,
+ const FilePath& application_path) {
+ SetWillLaunchAtLogin(
+ application_path, profile_directory, FLAG_ENABLE, FLAG_PRESERVE);
+}
+
+void DisableForegroundStartAtLogin(const string16& profile_directory) {
+ SetWillLaunchAtLogin(
+ FilePath(), profile_directory, FLAG_DISABLE, FLAG_PRESERVE);
+}
+
+void EnableBackgroundStartAtLogin() {
+ // Background mode isn't profile specific, but we specify the Default profile
+ // just to have a unique Run key to attach it to. FilePath is blank because
+ // this function is not called from the installer (see comments for
+ // EnableAutoStartAtLogin).
+ SetWillLaunchAtLogin(FilePath(),
+ ASCIIToUTF16(chrome::kInitialProfile),
+ FLAG_PRESERVE,
+ FLAG_ENABLE);
+}
+
+void DisableBackgroundStartAtLogin() {
+ SetWillLaunchAtLogin(FilePath(),
+ ASCIIToUTF16(chrome::kInitialProfile),
+ FLAG_PRESERVE,
+ FLAG_DISABLE);
+}
+
} // namespace auto_launch_util
diff --git a/chrome/installer/util/auto_launch_util.h b/chrome/installer/util/auto_launch_util.h
index bce8abd..977b28d 100644
--- a/chrome/installer/util/auto_launch_util.h
+++ b/chrome/installer/util/auto_launch_util.h
@@ -11,29 +11,63 @@
class FilePath;
// A namespace containing the platform specific implementation of setting Chrome
-// to launch on computer startup.
+// to launch at user login.
namespace auto_launch_util {
-// Returns whether the Chrome executable specified in |application_path| is set
-// to auto-launch at computer startup. NOTE: |application_path| is optional and
-// should be blank in most cases (as it will default to the application path of
-// the current executable). |profile_directory| is the name of the directory
-// (leaf, not the full path) that contains the profile that should be opened at
-// computer startup.
-bool WillLaunchAtLogin(const FilePath& application_path,
- const string16& profile_directory);
-
-// Configures whether the Chrome executable should auto-launch at computer
-// startup. |application_path| is needed when |auto_launch| is true AND when
-// the caller is not the process being set to auto-launch, ie. the installer.
-// This is because |application_path|, if left blank, defaults to the
-// application path of the current executable. If |auto_launch| is true, then it
-// will auto-launch, otherwise it will be configured not to. |profile_directory|
-// is the name of the directory (leaf, not the full path) that contains the
-// profile that should be opened at computer startup.
-void SetWillLaunchAtLogin(bool auto_launch,
- const FilePath& application_path,
- const string16& profile_directory);
+// Returns whether the Chrome executable in the directory |application_path| is
+// set to auto-start at user login.
+// |profile_directory| is the name of the directory (leaf, not the full path)
+// that contains the profile that should be opened at user login.
+// There are two flavors of auto-start, separated by whether a window is
+// requested at startup or not (called background mode). |window_requested|
+// specifies which flavor the caller is interested in.
+// NOTE: This function returns true only if the flavor the caller specifies has
+// been requested (or if both flavors have been requested). Therefore, it is
+// possible that Chrome auto-starts even if this function returns false (since
+// the other flavor might have been requested).
+// NOTE: Chrome being set to launch in the background (without a window)
+// does not necessarily mean that Chrome *will* launch without a window, since
+// when both flavors of the auto-start feature have been requested. In other
+// words, showing a window trumps not showing a window.
+// ALSO NOTE: |application_path| is optional and should be blank in most cases
+// (as it will default to the application path of the current executable).
+bool AutoStartRequested(const string16& profile_directory,
+ bool window_requested,
+ const FilePath& application_path);
+
+// Disables all auto-start features. |profile_directory| is the name of the
+// directory (leaf, not the full path) that contains the profile that was set
+// to be opened at user login.
+void DisableAllAutoStartFeatures(const string16& profile_directory);
+
+// Configures Chrome to auto-launch at user login and show a window. See also
+// EnableBackgroundStartAtLogin, which does the same, except without a window.
+// |profile_directory| is the name of the directory (leaf, not the full path)
+// that contains the profile that should be opened at user login.
+// |application_path| is needed when the caller is not the process being set to
+// auto-launch, ie. the installer. This is because |application_path|, if left
+// blank, defaults to the application path of the current executable.
+void EnableForegroundStartAtLogin(const string16& profile_directory,
+ const FilePath& application_path);
+
+// Disables auto-starting Chrome in foreground mode at user login.
+// |profile_directory| is the name of the directory (leaf, not the full path)
+// that contains the profile that was set to be opened at user login.
+// NOTE: Chrome may still launch if the other auto-start flavor is active
+// (background mode).
+void DisableForegroundStartAtLogin(const string16& profile_directory);
+
+// Requests that Chrome start in Background Mode at user login (without a
+// window being shown, except if EnableForegroundStartAtLogin has also been
+// called).
+// In short, EnableBackgroundStartAtLogin is the no-window version of calling
+// EnableForegroundStartAtLogin). If both are called, a window will be shown on
+// startup (foreground mode wins).
+void EnableBackgroundStartAtLogin();
+
+// Disables auto-starting Chrome in background mode at user login. Chrome may
+// still launch if the other auto-start flavor is active (foreground mode).
+void DisableBackgroundStartAtLogin();
} // namespace auto_launch_util