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

Side by Side Diff: chrome/browser/extensions/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
(Empty)
1 // Copyright (c) 2013 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 "chrome/browser/extensions/app_launcher.h"
6
7 #include "base/command_line.h"
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/browser_thread.h"
14
15 #if defined(OS_WIN)
16 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
17 #include "chrome/installer/util/browser_distribution.h"
18 #endif
19
20 namespace extensions {
21
22 namespace {
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 {
45 APP_LAUNCHER_UNKNOWN,
46 APP_LAUNCHER_ENABLED,
47 APP_LAUNCHER_DISABLED,
48 };
49
50 AppLauncherState SynchronousAppLauncherChecks() {
51 #if defined(USE_ASH)
52 return APP_LAUNCHER_ENABLED;
53 #elif !defined(OS_WIN)
54 return APP_LAUNCHER_DISABLED;
55 #else
56 if (CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kShowAppListShortcut)) {
58 return APP_LAUNCHER_ENABLED;
59 }
60
61 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported())
62 return APP_LAUNCHER_DISABLED;
63
64 return APP_LAUNCHER_UNKNOWN;
65 #endif
66 }
67
68 void UpdateIsAppLauncherEnabled(
69 const OnAppLauncherEnabledCompleted& completion_callback) {
70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71
72 AppLauncherState state = SynchronousAppLauncherChecks();
73
74 if (state != APP_LAUNCHER_UNKNOWN) {
75 bool is_enabled = state == APP_LAUNCHER_ENABLED;
76 PrefService* prefs = g_browser_process->local_state();
77 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled);
78 completion_callback.Run(is_enabled);
79 return;
80 }
81
82 #if defined(OS_WIN)
83 content::BrowserThread::PostBlockingPoolTask(
84 FROM_HERE,
85 base::Bind(&IsAppLauncherInstalledOnBlockingPool,
86 completion_callback));
87 #else
88 // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
89 // !defined(OS_WIN), so this path is never reached.
90 NOTREACHED();
91 #endif
92 }
93
94 bool IsAppLauncherEnabled() {
95 PrefService* prefs = g_browser_process->local_state();
96 // In some tests, the prefs aren't initialised, but the NTP still needs to
97 // work.
98 if (!prefs)
99 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
100 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
101 }
102
103 namespace app_launcher {
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