Chromium Code Reviews| 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 "app/l10n_util.h" | |
| 6 #include "base/base_paths.h" | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/task.h" | |
| 12 #include "base/win/registry.h" | |
| 13 #include "chrome/app/chrome_command_ids.h" | |
|
Andrew T Wilson (Slow)
2010/12/04 18:49:48
Remove chrome_command_ids?
The wrong rickcam account
2010/12/07 22:59:57
Done.
| |
| 14 #include "chrome/browser/background_mode_manager.h" | |
| 15 #include "chrome/browser/browser_thread.h" | |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "grit/generated_resources.h" | |
| 18 | |
| 19 class DisableLaunchOnStartupTask : public Task { | |
| 20 public: | |
| 21 virtual void Run(); | |
| 22 }; | |
| 23 | |
| 24 class EnableLaunchOnStartupTask : public Task { | |
| 25 public: | |
| 26 virtual void Run(); | |
| 27 }; | |
| 28 | |
| 29 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; | |
| 30 const wchar_t* kBackgroundModeRegistrySubkey = | |
| 31 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | |
| 32 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium"; | |
| 33 | |
| 34 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { | |
| 35 // This functionality is only defined for default profile, currently. | |
| 36 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) | |
| 37 return; | |
| 38 if (should_launch) { | |
| 39 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 40 new EnableLaunchOnStartupTask()); | |
| 41 } else { | |
| 42 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 43 new DisableLaunchOnStartupTask()); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void DisableLaunchOnStartupTask::Run() { | |
| 48 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | |
| 49 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | |
| 50 kBackgroundModeRegistrySubkey, KEY_READ); | |
| 51 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | |
| 52 kBackgroundModeRegistrySubkey, KEY_WRITE); | |
| 53 if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name)) | |
| 54 LOG(WARNING) << "Failed to deregister launch on login."; | |
| 55 } | |
| 56 | |
| 57 void EnableLaunchOnStartupTask::Run() { | |
| 58 // TODO(rickcam): Bug 53597: Make RegKey mockable. | |
| 59 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. | |
| 60 const wchar_t* key_name = kBackgroundModeRegistryKeyName; | |
| 61 base::win::RegKey read_key(kBackgroundModeRegistryRootKey, | |
| 62 kBackgroundModeRegistrySubkey, KEY_READ); | |
| 63 base::win::RegKey write_key(kBackgroundModeRegistryRootKey, | |
| 64 kBackgroundModeRegistrySubkey, KEY_WRITE); | |
| 65 FilePath executable; | |
| 66 if (!PathService::Get(base::FILE_EXE, &executable)) | |
| 67 return; | |
| 68 std::wstring new_value = executable.value() + L" --no-startup-window"; | |
| 69 if (read_key.ValueExists(key_name)) { | |
| 70 std::wstring current_value; | |
| 71 if (read_key.ReadValue(key_name, ¤t_value) && | |
| 72 (current_value == new_value)) { | |
| 73 return; | |
| 74 } | |
| 75 } | |
| 76 if (!write_key.WriteValue(key_name, new_value.c_str())) | |
| 77 LOG(WARNING) << "Failed to register launch on login."; | |
|
Andrew T Wilson (Slow)
2010/12/04 18:49:48
NOT_REACHED here also?
The wrong rickcam account
2010/12/07 22:59:57
Done. Also got the one 23-lines earlier as part o
| |
| 78 } | |
| 79 | |
| 80 string16 BackgroundModeManager::GetPreferencesMenuLabel() { | |
| 81 return l10n_util::GetStringUTF16(IDS_OPTIONS); | |
| 82 } | |
| OLD | NEW |