Chromium Code Reviews| 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..6edf3f5558ee750f903b121891641bfdd3b38744 |
| --- /dev/null |
| +++ b/chrome/browser/background_mode_manager_win.cc |
| @@ -0,0 +1,82 @@ |
| +// 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/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.
|
| +#include "chrome/browser/background_mode_manager.h" |
| +#include "chrome/browser/browser_thread.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "grit/generated_resources.h" |
| + |
| +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 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() { |
| + 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 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."; |
|
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
|
| +} |
| + |
| +string16 BackgroundModeManager::GetPreferencesMenuLabel() { |
| + return l10n_util::GetStringUTF16(IDS_OPTIONS); |
| +} |