| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "base/base_paths.h" | 6 #include "base/base_paths.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 const wchar_t* kBackgroundModeRegistrySubkey = | 31 const wchar_t* kBackgroundModeRegistrySubkey = |
| 32 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | 32 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; |
| 33 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; | 33 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; |
| 34 | 34 |
| 35 void DisableLaunchOnStartupTask::Run() { | 35 void DisableLaunchOnStartupTask::Run() { |
| 36 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | 36 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 37 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | 37 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 38 kBackgroundModeRegistrySubkey, KEY_READ); | 38 kBackgroundModeRegistrySubkey, KEY_READ); |
| 39 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | 39 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 40 kBackgroundModeRegistrySubkey, KEY_WRITE); | 40 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 41 if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name)) | 41 if (read_key.ValueExists(key_name)) { |
| 42 NOTREACHED() << "Failed to deregister launch on login."; | 42 LONG result = write_key.DeleteValue(key_name); |
| 43 DCHECK_EQ(ERROR_SUCCESS, result) << |
| 44 "Failed to deregister launch on login. error: " << result; |
| 45 } |
| 43 } | 46 } |
| 44 | 47 |
| 45 void EnableLaunchOnStartupTask::Run() { | 48 void EnableLaunchOnStartupTask::Run() { |
| 46 // TODO(rickcam): Bug 53597: Make RegKey mockable. | 49 // TODO(rickcam): Bug 53597: Make RegKey mockable. |
| 47 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. | 50 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. |
| 48 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | 51 const wchar_t* key_name = kBackgroundModeRegistryKeyName; |
| 49 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | 52 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, |
| 50 kBackgroundModeRegistrySubkey, KEY_READ); | 53 kBackgroundModeRegistrySubkey, KEY_READ); |
| 51 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | 54 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, |
| 52 kBackgroundModeRegistrySubkey, KEY_WRITE); | 55 kBackgroundModeRegistrySubkey, KEY_WRITE); |
| 53 FilePath executable; | 56 FilePath executable; |
| 54 if (!PathService::Get(base::FILE_EXE, &executable)) | 57 if (!PathService::Get(base::FILE_EXE, &executable)) |
| 55 return; | 58 return; |
| 56 std::wstring new_value = executable.value() + L" --no-startup-window"; | 59 std::wstring new_value = executable.value() + L" --no-startup-window"; |
| 57 if (read_key.ValueExists(key_name)) { | 60 if (read_key.ValueExists(key_name)) { |
| 58 std::wstring current_value; | 61 std::wstring current_value; |
| 59 if (read_key.ReadValue(key_name, ¤t_value) && | 62 if ((read_key.ReadValue(key_name, ¤t_value) == ERROR_SUCCESS) && |
| 60 (current_value == new_value)) { | 63 (current_value == new_value)) { |
| 61 return; | 64 return; |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 if (!write_key.WriteValue(key_name, new_value.c_str())) | 67 LONG result = write_key.WriteValue(key_name, new_value.c_str()); |
| 65 NOTREACHED() << "Failed to register launch on login."; | 68 DCHECK_EQ(ERROR_SUCCESS, result) << |
| 69 "Failed to register launch on login. error: " << result; |
| 66 } | 70 } |
| 67 | 71 |
| 68 } // namespace | 72 } // namespace |
| 69 | 73 |
| 70 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { | 74 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { |
| 71 // This functionality is only defined for default profile, currently. | 75 // This functionality is only defined for default profile, currently. |
| 72 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) | 76 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) |
| 73 return; | 77 return; |
| 74 if (should_launch) { | 78 if (should_launch) { |
| 75 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 79 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 76 new EnableLaunchOnStartupTask()); | 80 new EnableLaunchOnStartupTask()); |
| 77 } else { | 81 } else { |
| 78 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 82 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 79 new DisableLaunchOnStartupTask()); | 83 new DisableLaunchOnStartupTask()); |
| 80 } | 84 } |
| 81 } | 85 } |
| 82 | 86 |
| 83 string16 BackgroundModeManager::GetPreferencesMenuLabel() { | 87 string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
| 84 return l10n_util::GetStringUTF16(IDS_OPTIONS); | 88 return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| 85 } | 89 } |
| OLD | NEW |