Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/background_mode_manager_win.cc

Issue 5368002: Move Mac LaunchOnStartup enable/disable to File thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eliminating excess header includes: Windows Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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, &current_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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698