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 "base/command_line.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/ui/host_desktop.h"
14 #include "content/public/browser/browser_thread.h"
17 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
18 #include "chrome/installer/util/browser_distribution.h"
25 enum AppLauncherState
{
28 APP_LAUNCHER_DISABLED
,
31 AppLauncherState
SynchronousAppLauncherChecks() {
32 #if defined(USE_ASH) && !defined(OS_WIN)
33 return APP_LAUNCHER_ENABLED
;
34 #elif !defined(OS_WIN)
35 return APP_LAUNCHER_DISABLED
;
38 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
)
39 return APP_LAUNCHER_ENABLED
;
41 PrefService
* prefs
= g_browser_process
->local_state();
42 // In some tests, the prefs aren't initialised.
44 return APP_LAUNCHER_UNKNOWN
;
45 return prefs
->GetBoolean(prefs::kAppLauncherHasBeenEnabled
) ?
46 APP_LAUNCHER_ENABLED
: APP_LAUNCHER_DISABLED
;
52 bool MaybeIsAppLauncherEnabled() {
53 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED
;
56 void GetIsAppLauncherEnabled(
57 const OnAppLauncherEnabledCompleted
& completion_callback
) {
58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
60 AppLauncherState state
= SynchronousAppLauncherChecks();
62 if (state
!= APP_LAUNCHER_UNKNOWN
) {
63 completion_callback
.Run(state
== APP_LAUNCHER_ENABLED
);
69 bool WasAppLauncherEnabled() {
70 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED
;