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

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: Fixed previous attempt to resolve merge conflict 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
« no previous file with comments | « chrome/browser/background_mode_manager_mac.mm ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/browser/background_mode_manager.h"
14 #include "chrome/browser/browser_thread.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "grit/generated_resources.h"
17
18 namespace {
19
20 class DisableLaunchOnStartupTask : public Task {
21 public:
22 virtual void Run();
23 };
24
25 class EnableLaunchOnStartupTask : public Task {
26 public:
27 virtual void Run();
28 };
29
30 const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER;
31 const wchar_t* kBackgroundModeRegistrySubkey =
32 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
33 const wchar_t* kBackgroundModeRegistryKeyName = L"chromium";
34
35 void DisableLaunchOnStartupTask::Run() {
36 const wchar_t* key_name = kBackgroundModeRegistryKeyName;
37 base::win::RegKey read_key(kBackgroundModeRegistryRootKey,
38 kBackgroundModeRegistrySubkey, KEY_READ);
39 base::win::RegKey write_key(kBackgroundModeRegistryRootKey,
40 kBackgroundModeRegistrySubkey, KEY_WRITE);
41 if (read_key.ValueExists(key_name) && !write_key.DeleteValue(key_name))
42 NOTREACHED() << "Failed to deregister launch on login.";
43 }
44
45 void EnableLaunchOnStartupTask::Run() {
46 // TODO(rickcam): Bug 53597: Make RegKey mockable.
47 // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile.
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 FilePath executable;
54 if (!PathService::Get(base::FILE_EXE, &executable))
55 return;
56 std::wstring new_value = executable.value() + L" --no-startup-window";
57 if (read_key.ValueExists(key_name)) {
58 std::wstring current_value;
59 if (read_key.ReadValue(key_name, &current_value) &&
60 (current_value == new_value)) {
61 return;
62 }
63 }
64 if (!write_key.WriteValue(key_name, new_value.c_str()))
65 NOTREACHED() << "Failed to register launch on login.";
66 }
67
68 } // namespace
69
70 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
71 // This functionality is only defined for default profile, currently.
72 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
73 return;
74 if (should_launch) {
75 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
76 new EnableLaunchOnStartupTask());
77 } else {
78 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
79 new DisableLaunchOnStartupTask());
80 }
81 }
82
83 string16 BackgroundModeManager::GetPreferencesMenuLabel() {
84 return l10n_util::GetStringUTF16(IDS_OPTIONS);
85 }
OLDNEW
« no previous file with comments | « chrome/browser/background_mode_manager_mac.mm ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698