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

Side by Side Diff: apps/app_launcher.cc

Issue 12095052: Move app_launcher.* out of chrome/browser/extensions and into apps/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved switches back Created 7 years, 10 months 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/app_launcher.h" 5 #include "apps/app_launcher.h"
6 6
7 #include "apps/prefs.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/threading/sequenced_worker_pool.h" 9 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include "chrome/installer/launcher_support/chrome_launcher_support.h" 16 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
17 #include "chrome/installer/util/browser_distribution.h" 17 #include "chrome/installer/util/browser_distribution.h"
18 #endif 18 #endif
19 19
20 namespace extensions { 20 namespace apps {
21 21
22 namespace { 22 namespace {
23 23
24 #if defined(OS_WIN)
25 void UpdatePrefAndCallCallbackOnUI(
26 bool result,
27 const OnAppLauncherEnabledCompleted& completion_callback) {
28 PrefService* prefs = g_browser_process->local_state();
29 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result);
30 completion_callback.Run(result);
31 }
32
33 void IsAppLauncherInstalledOnBlockingPool(
34 const OnAppLauncherEnabledCompleted& completion_callback) {
35 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
36 bool result = chrome_launcher_support::IsAppLauncherPresent();
37 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
38 base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
39 }
40 #endif
41
42 } // namespace
43
44 enum AppLauncherState { 24 enum AppLauncherState {
45 APP_LAUNCHER_UNKNOWN, 25 APP_LAUNCHER_UNKNOWN,
46 APP_LAUNCHER_ENABLED, 26 APP_LAUNCHER_ENABLED,
47 APP_LAUNCHER_DISABLED, 27 APP_LAUNCHER_DISABLED,
48 }; 28 };
49 29
50 AppLauncherState SynchronousAppLauncherChecks() { 30 AppLauncherState SynchronousAppLauncherChecks() {
51 #if defined(USE_ASH) 31 #if defined(USE_ASH)
52 return APP_LAUNCHER_ENABLED; 32 return APP_LAUNCHER_ENABLED;
53 #elif !defined(OS_WIN) 33 #elif !defined(OS_WIN)
54 return APP_LAUNCHER_DISABLED; 34 return APP_LAUNCHER_DISABLED;
55 #else 35 #else
56 if (CommandLine::ForCurrentProcess()->HasSwitch( 36 if (CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kShowAppListShortcut)) { 37 switches::kShowAppListShortcut)) {
58 return APP_LAUNCHER_ENABLED; 38 return APP_LAUNCHER_ENABLED;
59 } 39 }
60 40
61 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) 41 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported())
62 return APP_LAUNCHER_DISABLED; 42 return APP_LAUNCHER_DISABLED;
63 43
64 return APP_LAUNCHER_UNKNOWN; 44 return APP_LAUNCHER_UNKNOWN;
65 #endif 45 #endif
66 } 46 }
67 47
68 void UpdateIsAppLauncherEnabled( 48 #if defined(OS_WIN)
tfarina 2013/02/01 15:08:24 nit: please, avoid using if defs in cross-platform
benwells 2013/02/08 07:18:00 Yes I agree. I am planning to make this change onc
49 void UpdatePrefAndCallCallbackOnUI(
50 bool result,
51 const OnAppLauncherEnabledCompleted& completion_callback) {
52 PrefService* prefs = g_browser_process->local_state();
53 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result);
54 completion_callback.Run(result);
55 }
56
57 void IsAppLauncherInstalledOnBlockingPool(
58 const OnAppLauncherEnabledCompleted& completion_callback) {
59 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
60 bool result = chrome_launcher_support::IsAppLauncherPresent();
61 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
62 base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
63 }
64 #endif
65
66 } // namespace
67
68 bool MaybeIsAppLauncherEnabled() {
69 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
70 }
71
72 void GetIsAppLauncherEnabled(
69 const OnAppLauncherEnabledCompleted& completion_callback) { 73 const OnAppLauncherEnabledCompleted& completion_callback) {
70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71 75
72 AppLauncherState state = SynchronousAppLauncherChecks(); 76 AppLauncherState state = SynchronousAppLauncherChecks();
73 77
74 if (state != APP_LAUNCHER_UNKNOWN) { 78 if (state != APP_LAUNCHER_UNKNOWN) {
75 bool is_enabled = state == APP_LAUNCHER_ENABLED; 79 bool is_enabled = state == APP_LAUNCHER_ENABLED;
76 PrefService* prefs = g_browser_process->local_state(); 80 PrefService* prefs = g_browser_process->local_state();
77 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled); 81 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled);
78 completion_callback.Run(is_enabled); 82 completion_callback.Run(is_enabled);
79 return; 83 return;
80 } 84 }
81 85
82 #if defined(OS_WIN) 86 #if defined(OS_WIN)
83 content::BrowserThread::PostBlockingPoolTask( 87 content::BrowserThread::PostBlockingPoolTask(
84 FROM_HERE, 88 FROM_HERE,
85 base::Bind(&IsAppLauncherInstalledOnBlockingPool, 89 base::Bind(&IsAppLauncherInstalledOnBlockingPool,
86 completion_callback)); 90 completion_callback));
87 #else 91 #else
88 // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on 92 // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
89 // !defined(OS_WIN), so this path is never reached. 93 // !defined(OS_WIN), so this path is never reached.
90 NOTREACHED(); 94 NOTREACHED();
91 #endif 95 #endif
92 } 96 }
93 97
94 bool IsAppLauncherEnabled() { 98 bool WasAppLauncherEnabled() {
95 PrefService* prefs = g_browser_process->local_state(); 99 PrefService* prefs = g_browser_process->local_state();
96 // In some tests, the prefs aren't initialised, but the NTP still needs to 100 // In some tests, the prefs aren't initialised.
97 // work.
98 if (!prefs) 101 if (!prefs)
99 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; 102 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
100 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); 103 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
101 } 104 }
102 105
103 namespace app_launcher { 106 } // namespace apps
104
105 void RegisterPrefs(PrefServiceSimple* pref_service) {
106 // If it is impossible to synchronously determine whether the app launcher is
107 // enabled, assume it is disabled. Anything that needs to know the absolute
108 // truth should call UpdateIsAppLauncherEnabled().
109 //
110 // This pref is just a cache of the value from the registry from last time
111 // Chrome ran. To avoid having the NTP block on a registry check, it guesses
112 // that the value hasn't changed since last time it was checked, using this
113 // preference.
114 bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
115 pref_service->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled);
116 }
117
118 } // namespace app_launcher
119
120 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698