| Index: chrome/installer/util/auto_launch_util.cc
|
| ===================================================================
|
| --- chrome/installer/util/auto_launch_util.cc (revision 132169)
|
| +++ chrome/installer/util/auto_launch_util.cc (working copy)
|
| @@ -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 @@
|
| // 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 @@
|
| 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,50 @@
|
| }
|
| 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;
|
| }
|
|
|
| -void SetWillLaunchAtLogin(bool auto_launch,
|
| - const FilePath& application_path,
|
| - const string16& profile_directory) {
|
| +bool LaunchWithWindowAtLoginRequested(const FilePath& application_path,
|
| + const string16& profile_directory) {
|
| + return WillLaunchAtLoginWithSwitch(application_path,
|
| + profile_directory,
|
| + switches::kAutoLaunchAtStartup);
|
| +}
|
| +
|
| +bool LaunchInBackgroundAtLoginRequested(const FilePath& application_path) {
|
| + // 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);
|
| +}
|
| +
|
| +void SetWillLaunchAtLogin(const FilePath& application_path,
|
| + const string16& profile_directory,
|
| + FlagSetting auto_start_feature,
|
| + FlagSetting background_mode) {
|
| string16 key_name(ProfileToKeyName(profile_directory));
|
|
|
| + // Check which feature should be enabled.
|
| + bool auto_start =
|
| + auto_start_feature == FLAG_ENABLE ||
|
| + (auto_start_feature == 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 (auto_start || in_background) {
|
| FilePath path(application_path);
|
| if (path.empty()) {
|
| if (!PathService::Get(base::DIR_EXE, &path)) {
|
| @@ -91,25 +145,33 @@
|
| 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 (auto_start) {
|
| + 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 +179,38 @@
|
| }
|
| }
|
|
|
| +void DisableAllAutostartFeatures(const string16& profile_directory) {
|
| + DisableAutoStartAtLogin(profile_directory);
|
| + DisableBackgroundModeAtLogin();
|
| +}
|
| +
|
| +void EnableAutoStartAtLogin(const FilePath& application_path,
|
| + const string16& profile_directory) {
|
| + SetWillLaunchAtLogin(
|
| + application_path, profile_directory, FLAG_ENABLE, FLAG_PRESERVE);
|
| +}
|
| +
|
| +void DisableAutoStartAtLogin(const string16& profile_directory) {
|
| + SetWillLaunchAtLogin(
|
| + FilePath(), profile_directory, FLAG_DISABLE, FLAG_PRESERVE);
|
| +}
|
| +
|
| +void EnableBackgroundModeAtLogin() {
|
| + // 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 DisableBackgroundModeAtLogin() {
|
| + SetWillLaunchAtLogin(FilePath(),
|
| + ASCIIToUTF16(chrome::kInitialProfile),
|
| + FLAG_PRESERVE,
|
| + FLAG_DISABLE);
|
| +}
|
| +
|
| } // namespace auto_launch_util
|
|
|