Bluetooth: remove private members from BluetoothAdapter
[chromium-blink-merge.git] / apps / app_launcher.cc
blobb5c5fe9d0811db8d0fc8e717ad4332285243c18d
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
3 // found in the LICENSE file.
5 #include "apps/app_launcher.h"
7 #include "apps/pref_names.h"
8 #include "apps/switches.h"
9 #include "base/command_line.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/ui/host_desktop.h"
15 #include "content/public/browser/browser_thread.h"
17 #if defined(OS_WIN)
18 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
19 #include "chrome/installer/util/browser_distribution.h"
20 #endif
22 namespace apps {
24 namespace {
26 enum AppLauncherState {
27 APP_LAUNCHER_UNKNOWN,
28 APP_LAUNCHER_ENABLED,
29 APP_LAUNCHER_DISABLED,
32 AppLauncherState SynchronousAppLauncherChecks() {
33 #if defined(USE_ASH) && !defined(OS_WIN)
34 return APP_LAUNCHER_ENABLED;
35 #elif !defined(OS_WIN)
36 return APP_LAUNCHER_DISABLED;
37 #else
38 if (CommandLine::ForCurrentProcess()->HasSwitch(
39 switches::kShowAppListShortcut)) {
40 return APP_LAUNCHER_ENABLED;
43 #if defined(USE_ASH)
44 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
45 return APP_LAUNCHER_ENABLED;
46 #endif
48 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported())
49 return APP_LAUNCHER_DISABLED;
51 return APP_LAUNCHER_UNKNOWN;
52 #endif
55 #if defined(OS_WIN)
56 void UpdatePrefAndCallCallbackOnUI(
57 bool result,
58 const OnAppLauncherEnabledCompleted& completion_callback) {
59 PrefService* prefs = g_browser_process->local_state();
60 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result);
61 completion_callback.Run(result);
64 void IsAppLauncherInstalledOnBlockingPool(
65 const OnAppLauncherEnabledCompleted& completion_callback) {
66 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
67 bool result = chrome_launcher_support::IsAppLauncherPresent();
68 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
69 base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
71 #endif
73 } // namespace
75 bool MaybeIsAppLauncherEnabled() {
76 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
79 void GetIsAppLauncherEnabled(
80 const OnAppLauncherEnabledCompleted& completion_callback) {
81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
83 AppLauncherState state = SynchronousAppLauncherChecks();
85 if (state != APP_LAUNCHER_UNKNOWN) {
86 bool is_enabled = state == APP_LAUNCHER_ENABLED;
87 PrefService* prefs = g_browser_process->local_state();
88 prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled);
89 completion_callback.Run(is_enabled);
90 return;
93 #if defined(OS_WIN)
94 content::BrowserThread::PostBlockingPoolTask(
95 FROM_HERE,
96 base::Bind(&IsAppLauncherInstalledOnBlockingPool,
97 completion_callback));
98 #else
99 // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
100 // !defined(OS_WIN), so this path is never reached.
101 NOTREACHED();
102 #endif
105 bool WasAppLauncherEnabled() {
106 PrefService* prefs = g_browser_process->local_state();
107 // In some tests, the prefs aren't initialised.
108 if (!prefs)
109 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
110 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
113 } // namespace apps