Index: chrome/browser/background_mode_manager_win.cc |
diff --git a/chrome/browser/background_mode_manager_win.cc b/chrome/browser/background_mode_manager_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..66bdcb17215e7c05bc8b9d9a7dec5f27943e0ba4 |
--- /dev/null |
+++ b/chrome/browser/background_mode_manager_win.cc |
@@ -0,0 +1,54 @@ |
+// 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 "base/base_paths.h" |
+#include "base/file_path.h" |
+#include "base/logging.h" |
+#include "base/path_service.h" |
+#include "base/win/registry.h" |
+#include "chrome/app/chrome_command_ids.h" |
+#include "chrome/browser/background_mode_manager.h" |
+#include "grit/generated_resources.h" |
+ |
+const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; |
+const wchar_t* kBackgroundModeRegistrySubkey = |
+ L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; |
+const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; |
+ |
+void BackgroundModeManager::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)) |
+ LOG(WARNING) << "Failed to deregister launch on login."; |
+} |
+ |
+void BackgroundModeManager::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, ¤t_value) && |
+ (current_value == new_value)) { |
+ return; |
+ } |
+ } |
+ if (!write_key.WriteValue(key_name, new_value.c_str())) |
+ LOG(WARNING) << "Failed to register launch on login."; |
+} |
+ |
+void BackgroundModeManager::AddPreferencesItem(menus::SimpleMenuModel* menu) { |
+ menu->AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); |
+} |