OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/base_paths.h" |
| 6 #include "base/file_path.h" |
| 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" |
| 9 #include "base/win/registry.h" |
| 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/background_mode_manager.h" |
| 12 #include "grit/generated_resources.h" |
| 13 |
| 14 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; |
| 15 const wchar_t* kBackgroundModeRegistrySubkey = |
| 16 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; |
| 17 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; |
| 18 |
| 19 void BackgroundModeManager::DisableLaunchOnStartupTask::Run() { |
| 20 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 21 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 22 kBackgroundModeRegistrySubkey, KEY_READ); |
| 23 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 24 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 25 if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name)) |
| 26 LOG(WARNING) << "Failed to deregister launch on login."; |
| 27 } |
| 28 |
| 29 void BackgroundModeManager::EnableLaunchOnStartupTask::Run() { |
| 30 // TODO(rickcam): Bug 53597: Make RegKey mockable. |
| 31 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. |
| 32 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 33 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 34 kBackgroundModeRegistrySubkey, KEY_READ); |
| 35 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 36 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 37 FilePath executable; |
| 38 if (!PathService::Get(base::FILE_EXE, &executable)) |
| 39 return; |
| 40 std::wstring new_value = executable.value() + L" --no-startup-window"; |
| 41 if (read_key.ValueExists(key_name)) { |
| 42 std::wstring current_value; |
| 43 if (read_key.ReadValue(key_name, ¤t_value) && |
| 44 (current_value == new_value)) { |
| 45 return; |
| 46 } |
| 47 } |
| 48 if (!write_key.WriteValue(key_name, new_value.c_str())) |
| 49 LOG(WARNING) << "Failed to register launch on login."; |
| 50 } |
| 51 |
| 52 void BackgroundModeManager::AddPreferencesItem(menus::SimpleMenuModel* menu) { |
| 53 menu->AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); |
| 54 } |
OLD | NEW |