summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-09 00:36:17 +0000
committerrickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-09 00:36:17 +0000
commit70dd60bfabf67faab1041ce3e927bf207e12cc12 (patch)
tree5ff499596652b89988bab8e9dab3afa692c24ebc
parente7f249b1630ebd949f11a466ce523d069550f5a4 (diff)
downloadchromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.zip
chromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.tar.gz
chromium_src-70dd60bfabf67faab1041ce3e927bf207e12cc12.tar.bz2
Follow pattern used for Linux and Windows to move the appropriate bits of Mac code to the file thread.
BUG=59265 TEST=none This patch also splits platform-specific LaunchOnStartup code to platform-specific files, eliminating #if blocks from the primary source file. Review URL: http://codereview.chromium.org/5368002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68678 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/background_mode_manager.cc207
-rw-r--r--chrome/browser/background_mode_manager.h12
-rw-r--r--chrome/browser/background_mode_manager_chromeos.cc16
-rw-r--r--chrome/browser/background_mode_manager_linux.cc116
-rw-r--r--chrome/browser/background_mode_manager_mac.mm78
-rw-r--r--chrome/browser/background_mode_manager_win.cc85
-rw-r--r--chrome/browser/prefs/browser_prefs.cc1
-rw-r--r--chrome/chrome_browser.gypi4
-rw-r--r--chrome/common/pref_names.cc5
-rw-r--r--chrome/common/pref_names.h2
10 files changed, 304 insertions, 222 deletions
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc
index ad3d0a7..1b70886 100644
--- a/chrome/browser/background_mode_manager.cc
+++ b/chrome/browser/background_mode_manager.cc
@@ -6,9 +6,7 @@
#include "app/resource_bundle.h"
#include "base/base_paths.h"
#include "base/command_line.h"
-#include "base/file_path.h"
#include "base/logging.h"
-#include "base/path_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/background_application_list_model.h"
@@ -18,7 +16,6 @@
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/shell_integration.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "chrome/common/chrome_switches.h"
@@ -26,147 +23,10 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
-#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-#if defined(OS_LINUX)
-#include <unistd.h>
-#include "base/environment.h"
-#include "base/file_util.h"
-#include "base/nix/xdg_util.h"
-#include "base/task.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/common/chrome_version_info.h"
-#endif
-
-#if defined(OS_MACOSX)
-#include "base/mac_util.h"
-#endif
-
-#if defined(TOOLKIT_GTK)
-#include "chrome/browser/gtk/gtk_util.h"
-#endif
-
-#if defined(OS_LINUX)
-static const FilePath::CharType kAutostart[] = "autostart";
-static const FilePath::CharType kConfig[] = ".config";
-static const char kXdgConfigHome[] = "XDG_CONFIG_HOME";
-#endif
-
-#if defined(OS_WIN)
-#include "base/win/registry.h"
-const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER;
-const wchar_t* kBackgroundModeRegistrySubkey =
- L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
-const wchar_t* kBackgroundModeRegistryKeyName = L"chromium";
-#endif
-
-#if defined(OS_LINUX)
-namespace {
-
-FilePath GetAutostartDirectory(base::Environment* environment) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- FilePath result =
- base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
- result = result.Append(kAutostart);
- return result;
-}
-
-FilePath GetAutostartFilename(base::Environment* environment) {
- FilePath directory = GetAutostartDirectory(environment);
- return directory.Append(ShellIntegration::GetDesktopName(environment));
-}
-
-} // namespace
-#endif // defined(OS_LINUX)
-
-#if defined(OS_WIN) || defined(OS_LINUX)
-class DisableLaunchOnStartupTask : public Task {
- public:
- virtual void Run() {
-#if defined(OS_LINUX)
- scoped_ptr<base::Environment> environment(base::Environment::Create());
- if (!file_util::Delete(GetAutostartFilename(environment.get()), false)) {
- LOG(WARNING) << "Failed to deregister launch on login.";
- }
-#elif defined(OS_WIN)
- const wchar_t* key_name = kBackgroundModeRegistryKeyName;
- base::win::RegKey read_key(kBackgroundModeRegistryRootKey,
- kBackgroundModeRegistrySubkey, KEY_READ);
- base::win::RegKey write_key(kBackgroundModeRegistryRootKey,
- kBackgroundModeRegistrySubkey, KEY_WRITE);
- if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name))
- LOG(WARNING) << "Failed to deregister launch on login.";
-#endif
- }
-};
-#endif // defined(OS_WIN) || defined(OS_LINUX)
-
-// TODO(rickcam): Bug 56280: Share implementation with ShellIntegration
-#if defined(OS_WIN) || defined(OS_LINUX)
-class EnableLaunchOnStartupTask : public Task {
- public:
- virtual void Run() {
-#if defined(OS_LINUX)
- scoped_ptr<base::Environment> environment(base::Environment::Create());
- scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo());
- FilePath autostart_directory = GetAutostartDirectory(environment.get());
- FilePath autostart_file = GetAutostartFilename(environment.get());
- if (!file_util::DirectoryExists(autostart_directory) &&
- !file_util::CreateDirectory(autostart_directory)) {
- LOG(WARNING)
- << "Failed to register launch on login. No autostart directory.";
- return;
- }
- std::string wrapper_script;
- if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) {
- LOG(WARNING)
- << "Failed to register launch on login. CHROME_WRAPPER not set.";
- return;
- }
- std::string autostart_file_contents =
- "[Desktop Entry]\n"
- "Type=Application\n"
- "Terminal=false\n"
- "Exec=" + wrapper_script +
- " --enable-background-mode --no-startup-window\n"
- "Name=" + version_info->Name() + "\n";
- std::string::size_type content_length = autostart_file_contents.length();
- if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
- content_length) !=
- static_cast<int>(content_length)) {
- LOG(WARNING) << "Failed to register launch on login. Failed to write "
- << autostart_file.value();
- file_util::Delete(GetAutostartFilename(environment.get()), false);
- }
-#elif defined(OS_WIN)
- // TODO(rickcam): Bug 53597: Make RegKey mockable.
- // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile.
- const wchar_t* key_name = kBackgroundModeRegistryKeyName;
- base::win::RegKey read_key(kBackgroundModeRegistryRootKey,
- kBackgroundModeRegistrySubkey, KEY_READ);
- base::win::RegKey write_key(kBackgroundModeRegistryRootKey,
- kBackgroundModeRegistrySubkey, KEY_WRITE);
- FilePath executable;
- if (!PathService::Get(base::FILE_EXE, &executable))
- return;
- std::wstring new_value = executable.value() + L" --no-startup-window";
- if (read_key.ValueExists(key_name)) {
- std::wstring current_value;
- if (read_key.ReadValue(key_name, &current_value) &&
- (current_value == new_value)) {
- return;
- }
- }
- if (!write_key.WriteValue(key_name, new_value.c_str()))
- LOG(WARNING) << "Failed to register launch on login.";
-#endif
- }
-};
-#endif // defined(OS_WIN) || defined(OS_LINUX)
-
void BackgroundModeManager::OnApplicationDataChanged(
const Extension* extension) {
UpdateContextMenuEntryIcon(extension);
@@ -245,15 +105,6 @@ BackgroundModeManager::~BackgroundModeManager() {
EndBackgroundMode();
}
-bool BackgroundModeManager::IsLaunchOnStartupResetAllowed() {
- return profile_->GetPrefs()->GetBoolean(prefs::kLaunchOnStartupResetAllowed);
-}
-
-void BackgroundModeManager::SetLaunchOnStartupResetAllowed(bool allowed) {
- profile_->GetPrefs()->SetBoolean(prefs::kLaunchOnStartupResetAllowed,
- allowed);
-}
-
void BackgroundModeManager::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -380,45 +231,6 @@ void BackgroundModeManager::OnBackgroundAppUninstalled() {
EnableLaunchOnStartup(false);
}
-void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
- // This functionality is only defined for default profile, currently.
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
- return;
-#if defined(OS_WIN) || defined(OS_LINUX)
- if (should_launch) {
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- new EnableLaunchOnStartupTask());
- } else {
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- new DisableLaunchOnStartupTask());
- }
-#elif defined(OS_MACOSX)
- if (should_launch) {
- // Return if Chrome is already a Login Item (avoid overriding user choice).
- if (mac_util::CheckLoginItemStatus(NULL))
- return;
-
- mac_util::AddToLoginItems(true); // Hide on startup.
-
- // Remember we set Login Item, not the user - so we can reset it later.
- SetLaunchOnStartupResetAllowed(true);
- } else {
- // If we didn't set Login Item, don't mess with it.
- if (!IsLaunchOnStartupResetAllowed())
- return;
- SetLaunchOnStartupResetAllowed(false);
-
- // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden'
- // flag - most likely user has modified the setting, don't override it.
- bool is_hidden = false;
- if (!mac_util::CheckLoginItemStatus(&is_hidden) || !is_hidden)
- return;
-
- mac_util::RemoveFromLoginItems();
- }
-#endif
-}
-
void BackgroundModeManager::CreateStatusTrayIcon() {
// Only need status icons on windows/linux. ChromeOS doesn't allow exiting
// Chrome and Mac can use the dock icon instead.
@@ -462,19 +274,7 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() {
// Add About item
menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
-
- // Add Preferences item
-#if defined(OS_CHROMEOS)
- menu->AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS);
-#elif defined(TOOLKIT_GTK)
- string16 preferences = gtk_util::GetStockPreferencesMenuLabel();
- if (!preferences.empty())
- menu->AddItem(IDC_OPTIONS, preferences);
- else
- menu->AddItemWithStringId(IDC_OPTIONS, IDS_PREFERENCES);
-#else
- menu->AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS);
-#endif
+ menu->AddItem(IDC_OPTIONS, GetPreferencesMenuLabel());
menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
menu->AddSeparator();
int application_position = 0;
@@ -560,11 +360,6 @@ Browser* BackgroundModeManager::GetBrowserWindow() {
}
// static
-void BackgroundModeManager::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterBooleanPref(prefs::kLaunchOnStartupResetAllowed, false);
-}
-
-// static
bool BackgroundModeManager::IsBackgroundModeEnabled(
const CommandLine* command_line) {
diff --git a/chrome/browser/background_mode_manager.h b/chrome/browser/background_mode_manager.h
index 6da40ec..9407d4a 100644
--- a/chrome/browser/background_mode_manager.h
+++ b/chrome/browser/background_mode_manager.h
@@ -44,8 +44,6 @@ class BackgroundModeManager
BackgroundModeManager(Profile* profile, CommandLine* command_line);
virtual ~BackgroundModeManager();
- static void RegisterUserPrefs(PrefService* prefs);
-
static bool IsBackgroundModeEnabled(const CommandLine* command_line);
private:
@@ -95,12 +93,6 @@ class BackgroundModeManager
// launch-on-startup is disabled if appropriate.
void OnBackgroundAppUninstalled();
- // Returns true if chrome has set "launch on startup" property for itself
- // earlier and is allowed to reset it later, reducing likelihood of
- // overriding user choices.
- bool IsLaunchOnStartupResetAllowed();
- void SetLaunchOnStartupResetAllowed(bool allowed);
-
// Called to make sure that our launch-on-startup mode is properly set.
// (virtual so we can override for tests).
virtual void EnableLaunchOnStartup(bool should_launch);
@@ -119,6 +111,10 @@ class BackgroundModeManager
// manually, or all apps have been loaded).
void EndKeepAliveForStartup();
+ // Return an appropriate name for a Preferences menu entry. Preferences is
+ // sometimes called Options or Settings.
+ string16 GetPreferencesMenuLabel();
+
// Create a status tray icon to allow the user to shutdown Chrome when running
// in background mode. Virtual to enable testing.
virtual void CreateStatusTrayIcon();
diff --git a/chrome/browser/background_mode_manager_chromeos.cc b/chrome/browser/background_mode_manager_chromeos.cc
new file mode 100644
index 0000000..8439f18
--- /dev/null
+++ b/chrome/browser/background_mode_manager_chromeos.cc
@@ -0,0 +1,16 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/background_mode_manager.h"
+
+#include "app/l10n_util.h"
+#include "grit/generated_resources.h"
+
+void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
+ NOTREACHED();
+}
+
+string16 BackgroundModeManager::GetPreferencesMenuLabel() {
+ return l10n_util::GetStringUTF16(IDS_SETTINGS);
+}
diff --git a/chrome/browser/background_mode_manager_linux.cc b/chrome/browser/background_mode_manager_linux.cc
new file mode 100644
index 0000000..3d998a6
--- /dev/null
+++ b/chrome/browser/background_mode_manager_linux.cc
@@ -0,0 +1,116 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <unistd.h>
+
+#include "app/l10n_util.h"
+#include "base/command_line.h"
+#include "base/environment.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/nix/xdg_util.h"
+#include "base/task.h"
+#include "chrome/browser/background_mode_manager.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/gtk/gtk_util.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/shell_integration.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/pref_names.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+class DisableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+class EnableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+static const FilePath::CharType kAutostart[] = "autostart";
+static const FilePath::CharType kConfig[] = ".config";
+static const char kXdgConfigHome[] = "XDG_CONFIG_HOME";
+
+FilePath GetAutostartDirectory(base::Environment* environment) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ FilePath result =
+ base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
+ result = result.Append(kAutostart);
+ return result;
+}
+
+FilePath GetAutostartFilename(base::Environment* environment) {
+ FilePath directory = GetAutostartDirectory(environment);
+ return directory.Append(ShellIntegration::GetDesktopName(environment));
+}
+
+} // namespace
+
+void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
+ // This functionality is only defined for default profile, currently.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
+ return;
+ if (should_launch) {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new EnableLaunchOnStartupTask());
+ } else {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new DisableLaunchOnStartupTask());
+ }
+}
+
+void DisableLaunchOnStartupTask::Run() {
+ scoped_ptr<base::Environment> environment(base::Environment::Create());
+ if (!file_util::Delete(GetAutostartFilename(environment.get()), false)) {
+ NOTREACHED() << "Failed to deregister launch on login.";
+ }
+}
+
+// TODO(rickcam): Bug 56280: Share implementation with ShellIntegration
+void EnableLaunchOnStartupTask::Run() {
+ scoped_ptr<base::Environment> environment(base::Environment::Create());
+ scoped_ptr<chrome::VersionInfo> version_info(new chrome::VersionInfo());
+ FilePath autostart_directory = GetAutostartDirectory(environment.get());
+ FilePath autostart_file = GetAutostartFilename(environment.get());
+ if (!file_util::DirectoryExists(autostart_directory) &&
+ !file_util::CreateDirectory(autostart_directory)) {
+ NOTREACHED()
+ << "Failed to register launch on login. No autostart directory.";
+ return;
+ }
+ std::string wrapper_script;
+ if (!environment->GetVar("CHROME_WRAPPER", &wrapper_script)) {
+ LOG(WARNING)
+ << "Failed to register launch on login. CHROME_WRAPPER not set.";
+ return;
+ }
+ std::string autostart_file_contents =
+ "[Desktop Entry]\n"
+ "Type=Application\n"
+ "Terminal=false\n"
+ "Exec=" + wrapper_script +
+ " --enable-background-mode --no-startup-window\n"
+ "Name=" + version_info->Name() + "\n";
+ std::string::size_type content_length = autostart_file_contents.length();
+ if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
+ content_length) !=
+ static_cast<int>(content_length)) {
+ NOTREACHED() << "Failed to register launch on login. Failed to write "
+ << autostart_file.value();
+ file_util::Delete(GetAutostartFilename(environment.get()), false);
+ }
+}
+
+string16 BackgroundModeManager::GetPreferencesMenuLabel() {
+ string16 result = gtk_util::GetStockPreferencesMenuLabel();
+ if (!result.empty())
+ return result;
+ return l10n_util::GetStringUTF16(IDS_PREFERENCES);
+}
diff --git a/chrome/browser/background_mode_manager_mac.mm b/chrome/browser/background_mode_manager_mac.mm
new file mode 100644
index 0000000..cc6ab4b
--- /dev/null
+++ b/chrome/browser/background_mode_manager_mac.mm
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/l10n_util.h"
+#include "base/command_line.h"
+#include "base/mac_util.h"
+#include "chrome/browser/background_mode_manager.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/common/app_mode_common_mac.h"
+#include "chrome/common/chrome_switches.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+class DisableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+class EnableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+const CFStringRef kLaunchOnStartupResetAllowedPrefsKey =
+ CFSTR("LaunchOnStartupResetAllowed");
+
+void DisableLaunchOnStartupTask::Run() {
+ Boolean key_exists_and_has_valid_format; // ignored
+ if (!CFPreferencesGetAppBooleanValue(kLaunchOnStartupResetAllowedPrefsKey,
+ app_mode::kAppPrefsID,
+ &key_exists_and_has_valid_format))
+ return;
+
+ CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey,
+ kCFBooleanFalse,
+ app_mode::kAppPrefsID);
+
+ // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden'
+ // flag - most likely user has modified the setting, don't override it.
+ bool is_hidden = false;
+ if (!mac_util::CheckLoginItemStatus(&is_hidden) || !is_hidden)
+ return;
+
+ mac_util::RemoveFromLoginItems();
+}
+
+void EnableLaunchOnStartupTask::Run() {
+ // Return if Chrome is already a Login Item (avoid overriding user choice).
+ if (mac_util::CheckLoginItemStatus(NULL))
+ return;
+
+ mac_util::AddToLoginItems(true); // Hide on startup.
+ CFPreferencesSetAppValue(kLaunchOnStartupResetAllowedPrefsKey,
+ kCFBooleanTrue,
+ app_mode::kAppPrefsID);
+}
+
+} // namespace
+
+void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
+ // This functionality is only defined for default profile, currently.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
+ return;
+
+ if (should_launch) {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new EnableLaunchOnStartupTask());
+ } else {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new DisableLaunchOnStartupTask());
+ }
+}
+
+string16 BackgroundModeManager::GetPreferencesMenuLabel() {
+ return l10n_util::GetStringUTF16(IDS_OPTIONS);
+}
diff --git a/chrome/browser/background_mode_manager_win.cc b/chrome/browser/background_mode_manager_win.cc
new file mode 100644
index 0000000..2f10843
--- /dev/null
+++ b/chrome/browser/background_mode_manager_win.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/l10n_util.h"
+#include "base/base_paths.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/task.h"
+#include "base/win/registry.h"
+#include "chrome/browser/background_mode_manager.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/common/chrome_switches.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+class DisableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+class EnableLaunchOnStartupTask : public Task {
+ public:
+ virtual void Run();
+};
+
+const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER;
+const wchar_t* kBackgroundModeRegistrySubkey =
+ L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
+const wchar_t* kBackgroundModeRegistryKeyName = L"chromium";
+
+void DisableLaunchOnStartupTask::Run() {
+ const wchar_t* key_name = kBackgroundModeRegistryKeyName;
+ base::win::RegKey read_key(kBackgroundModeRegistryRootKey,
+ kBackgroundModeRegistrySubkey, KEY_READ);
+ base::win::RegKey write_key(kBackgroundModeRegistryRootKey,
+ kBackgroundModeRegistrySubkey, KEY_WRITE);
+ if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name))
+ NOTREACHED() << "Failed to deregister launch on login.";
+}
+
+void EnableLaunchOnStartupTask::Run() {
+ // TODO(rickcam): Bug 53597: Make RegKey mockable.
+ // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile.
+ const wchar_t* key_name = kBackgroundModeRegistryKeyName;
+ base::win::RegKey read_key(kBackgroundModeRegistryRootKey,
+ kBackgroundModeRegistrySubkey, KEY_READ);
+ base::win::RegKey write_key(kBackgroundModeRegistryRootKey,
+ kBackgroundModeRegistrySubkey, KEY_WRITE);
+ FilePath executable;
+ if (!PathService::Get(base::FILE_EXE, &executable))
+ return;
+ std::wstring new_value = executable.value() + L" --no-startup-window";
+ if (read_key.ValueExists(key_name)) {
+ std::wstring current_value;
+ if (read_key.ReadValue(key_name, &current_value) &&
+ (current_value == new_value)) {
+ return;
+ }
+ }
+ if (!write_key.WriteValue(key_name, new_value.c_str()))
+ NOTREACHED() << "Failed to register launch on login.";
+}
+
+} // namespace
+
+void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
+ // This functionality is only defined for default profile, currently.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
+ return;
+ if (should_launch) {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new EnableLaunchOnStartupTask());
+ } else {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ new DisableLaunchOnStartupTask());
+ }
+}
+
+string16 BackgroundModeManager::GetPreferencesMenuLabel() {
+ return l10n_util::GetStringUTF16(IDS_OPTIONS);
+}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index d79981d..df68921 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -112,7 +112,6 @@ void RegisterLocalState(PrefService* local_state) {
void RegisterUserPrefs(PrefService* user_prefs) {
// User prefs
AutoFillManager::RegisterUserPrefs(user_prefs);
- BackgroundModeManager::RegisterUserPrefs(user_prefs);
SessionStartupPref::RegisterUserPrefs(user_prefs);
Browser::RegisterUserPrefs(user_prefs);
PasswordManager::RegisterUserPrefs(user_prefs);
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 7459e0d..859d8a0 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -267,6 +267,10 @@
'browser/background_contents_service.h',
'browser/background_mode_manager.cc',
'browser/background_mode_manager.h',
+ 'browser/background_mode_manager_chromeos.cc',
+ 'browser/background_mode_manager_linux.cc',
+ 'browser/background_mode_manager_mac.mm',
+ 'browser/background_mode_manager_win.cc',
'browser/background_page_tracker.cc',
'browser/background_page_tracker.h',
'browser/blocked_content_container.cc',
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index d58e4da..4799a7f 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -759,11 +759,6 @@ const char kPreferencesWindowPlacement[] = "preferences.window_placement";
// renderer's in-memory cache of objects.
const char kMemoryCacheSize[] = "renderer.memory_cache.size";
-// Boolean that records if chrome has set "launch on startup" property for
-// itself earlier and is allowed to reset it later, reducing likelihood of
-// overriding user choices.
-const char kLaunchOnStartupResetAllowed[] = "launch_on_startup_reset_allowed";
-
// String which specifies where to download files to by default.
const char kDownloadDefaultDirectory[] = "download.default_directory";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 46d50ce..376c905 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -274,8 +274,6 @@ extern const char kKeywordEditorWindowPlacement[];
extern const char kPreferencesWindowPlacement[];
extern const char kMemoryCacheSize[];
-extern const char kLaunchOnStartupResetAllowed[];
-
extern const char kDownloadDefaultDirectory[];
extern const char kDownloadExtensionsToOpen[];
extern const char kDownloadDirUpgraded[];