Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5048)

Unified Diff: chrome/installer/util/auto_launch_util.cc

Issue 9972012: Resolve the conflict that auto-launch has with the background mode feature (part 1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)
@@ -23,6 +23,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 +61,9 @@
ASCIIToWide("_") + ASCIIToWide(hash_string);
}
-bool WillLaunchAtLogin(const FilePath& application_path,
- const string16& profile_directory) {
+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 +80,35 @@
}
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) {
+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 +120,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 +154,31 @@
}
}
+void DisableAllAutostartFeatures(const string16& profile_directory) {
+ DisableAutoStartAtLogin(profile_directory);
+ DisableBackgroundModeAtLogin(profile_directory);
+}
+
+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(const FilePath& application_path,
+ const string16& profile_directory) {
+ SetWillLaunchAtLogin(
+ application_path, profile_directory, FLAG_PRESERVE, FLAG_ENABLE);
+}
+
+void DisableBackgroundModeAtLogin(const string16& profile_directory) {
rpetterson 2012/04/17 01:02:11 I'm concerned this won't have the effect you're lo
Finnur 2012/04/17 12:27:45 If you look at SetWillLaunchAtLogin you'll see tha
+ SetWillLaunchAtLogin(
+ FilePath(), profile_directory, FLAG_PRESERVE, FLAG_DISABLE);
+}
+
} // namespace auto_launch_util
« chrome/installer/util/auto_launch_util.h ('K') | « chrome/installer/util/auto_launch_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698