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

Side by Side Diff: chrome/browser/background/background_mode_manager_mac.mm

Issue 8680017: base::Bind: Convert BackgroundModeManager Tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win build fix. Created 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h"
5 #include "base/command_line.h" 6 #include "base/command_line.h"
6 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
7 #include "chrome/browser/background/background_mode_manager.h" 8 #include "chrome/browser/background/background_mode_manager.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
17 18
18 namespace { 19 namespace {
19 20
20 class DisableLaunchOnStartupTask : public Task { 21 void DisableLaunchOnStartupCallback() {
21 public:
22 virtual void Run();
23 };
24
25 class EnableLaunchOnStartupTask : public Task {
26 public:
27 virtual void Run();
28 };
29
30 class SetUserCreatedLoginItemPrefTask : public Task {
31 public:
32 virtual void Run();
33 };
34
35 void DisableLaunchOnStartupTask::Run() {
36 // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden' 22 // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden'
37 // flag - most likely user has modified the setting, don't override it. 23 // flag - most likely user has modified the setting, don't override it.
38 bool is_hidden = false; 24 bool is_hidden = false;
39 if (!base::mac::CheckLoginItemStatus(&is_hidden) || !is_hidden) 25 if (!base::mac::CheckLoginItemStatus(&is_hidden) || !is_hidden)
40 return; 26 return;
41 27
42 base::mac::RemoveFromLoginItems(); 28 base::mac::RemoveFromLoginItems();
43 } 29 }
44 30
45 void EnableLaunchOnStartupTask::Run() { 31 void EnableLaunchOnStartupCallback() {
46 // Return if Chrome is already a Login Item (avoid overriding user choice). 32 // Return if Chrome is already a Login Item (avoid overriding user choice).
47 if (base::mac::CheckLoginItemStatus(NULL)) { 33 if (base::mac::CheckLoginItemStatus(NULL)) {
48 // Call back to the UI thread to set our preference so we don't delete the 34 // Call back to the UI thread to set our preference so we don't delete the
49 // user's login item when we disable launch on startup. There's a race 35 // user's login item when we disable launch on startup. There's a race
50 // condition here if the user disables launch on startup before our callback 36 // condition here if the user disables launch on startup before our callback
51 // is run, but the user can manually disable "Open At Login" via the dock if 37 // is run, but the user can manually disable "Open At Login" via the dock if
52 // this happens. 38 // this happens.
53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
54 new SetUserCreatedLoginItemPrefTask()); 40 base::Bind(SetUserCreatedLoginItemPrefCallback));
55 return; 41 return;
56 } 42 }
57 43
58 base::mac::AddToLoginItems(true); // Hide on startup. 44 base::mac::AddToLoginItems(true); // Hide on startup.
59 } 45 }
60 46
61 void SetUserCreatedLoginItemPrefTask::Run() { 47 void SetUserCreatedLoginItemPrefCallback() {
62 PrefService* service = g_browser_process->local_state(); 48 PrefService* service = g_browser_process->local_state();
63 service->SetBoolean(prefs::kUserCreatedLoginItem, true); 49 service->SetBoolean(prefs::kUserCreatedLoginItem, true);
64 } 50 }
65 51
66 } // namespace 52 } // namespace
67 53
68 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { 54 void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
69 // This functionality is only defined for default profile, currently. 55 // This functionality is only defined for default profile, currently.
70 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir)) 56 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
71 return; 57 return;
72 58
73 if (should_launch) { 59 if (should_launch) {
74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 60 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
75 new EnableLaunchOnStartupTask()); 61 base::Bind(EnableLaunchOnStartupCallback));
76 } else { 62 } else {
77 PrefService* service = g_browser_process->local_state(); 63 PrefService* service = g_browser_process->local_state();
78 if (service->GetBoolean(prefs::kUserCreatedLoginItem)) { 64 if (service->GetBoolean(prefs::kUserCreatedLoginItem)) {
79 // We didn't create the login item, so nothing to do here. 65 // We didn't create the login item, so nothing to do here.
80 service->ClearPref(prefs::kUserCreatedLoginItem); 66 service->ClearPref(prefs::kUserCreatedLoginItem);
81 return; 67 return;
82 } 68 }
83 // Call to the File thread to remove the login item since it requires 69 // Call to the File thread to remove the login item since it requires
84 // accessing the disk. 70 // accessing the disk.
85 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 71 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
86 new DisableLaunchOnStartupTask()); 72 base::Bind(DisableLaunchOnStartupCallback));
87 } 73 }
88 } 74 }
89 75
90 void BackgroundModeManager::DisplayAppInstalledNotification( 76 void BackgroundModeManager::DisplayAppInstalledNotification(
91 const Extension* extension) { 77 const Extension* extension) {
92 // TODO(atwilson): Display a platform-appropriate notification here. 78 // TODO(atwilson): Display a platform-appropriate notification here.
93 // http://crbug.com/74970 79 // http://crbug.com/74970
94 } 80 }
95 81
96 string16 BackgroundModeManager::GetPreferencesMenuLabel() { 82 string16 BackgroundModeManager::GetPreferencesMenuLabel() {
97 return l10n_util::GetStringUTF16(IDS_OPTIONS); 83 return l10n_util::GetStringUTF16(IDS_OPTIONS);
98 } 84 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager_gtk.cc ('k') | chrome/browser/background/background_mode_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698