Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / apps / app_launcher.cc
blob77a75fc858e85be68a55ac581d3e457f2ce636b2
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"
16 #if defined(OS_WIN)
17 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
18 #include "chrome/installer/util/browser_distribution.h"
19 #endif
21 namespace apps {
23 namespace {
25 enum AppLauncherState {
26 APP_LAUNCHER_UNKNOWN,
27 APP_LAUNCHER_ENABLED,
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;
36 #else
37 #if defined(USE_ASH)
38 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
39 return APP_LAUNCHER_ENABLED;
40 #endif
41 PrefService* prefs = g_browser_process->local_state();
42 // In some tests, the prefs aren't initialised.
43 if (!prefs)
44 return APP_LAUNCHER_UNKNOWN;
45 return prefs->GetBoolean(prefs::kAppLauncherHasBeenEnabled) ?
46 APP_LAUNCHER_ENABLED : APP_LAUNCHER_DISABLED;
47 #endif
50 } // namespace
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);
64 return;
66 NOTREACHED();
69 bool WasAppLauncherEnabled() {
70 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
73 } // namespace apps