OLD | NEW |
1 // Copyright 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 "apps/app_launcher.h" | 5 #include "apps/app_launcher.h" |
6 | 6 |
7 #include "apps/pref_names.h" | 7 #include "apps/pref_names.h" |
8 #include "apps/switches.h" | |
9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
10 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
13 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
16 | 15 |
17 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
18 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 17 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
19 #include "chrome/installer/util/browser_distribution.h" | 18 #include "chrome/installer/util/browser_distribution.h" |
20 #endif | 19 #endif |
21 | 20 |
22 namespace apps { | 21 namespace apps { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 enum AppLauncherState { | 25 enum AppLauncherState { |
27 APP_LAUNCHER_UNKNOWN, | 26 APP_LAUNCHER_UNKNOWN, |
28 APP_LAUNCHER_ENABLED, | 27 APP_LAUNCHER_ENABLED, |
29 APP_LAUNCHER_DISABLED, | 28 APP_LAUNCHER_DISABLED, |
30 }; | 29 }; |
31 | 30 |
32 AppLauncherState SynchronousAppLauncherChecks() { | 31 AppLauncherState SynchronousAppLauncherChecks() { |
33 #if defined(USE_ASH) && !defined(OS_WIN) | 32 #if defined(USE_ASH) && !defined(OS_WIN) |
34 return APP_LAUNCHER_ENABLED; | 33 return APP_LAUNCHER_ENABLED; |
35 #elif !defined(OS_WIN) | 34 #elif !defined(OS_WIN) |
36 return APP_LAUNCHER_DISABLED; | 35 return APP_LAUNCHER_DISABLED; |
37 #else | 36 #else |
38 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
39 switches::kShowAppListShortcut)) { | |
40 return APP_LAUNCHER_ENABLED; | |
41 } | |
42 | |
43 #if defined(USE_ASH) | 37 #if defined(USE_ASH) |
44 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 38 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
45 return APP_LAUNCHER_ENABLED; | 39 return APP_LAUNCHER_ENABLED; |
46 #endif | 40 #endif |
47 | 41 PrefService* prefs = g_browser_process->local_state(); |
48 if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) | 42 // In some tests, the prefs aren't initialised. |
49 return APP_LAUNCHER_DISABLED; | 43 if (!prefs) |
50 | 44 return APP_LAUNCHER_UNKNOWN; |
51 return APP_LAUNCHER_UNKNOWN; | 45 return prefs->GetBoolean(prefs::kAppLauncherHasBeenEnabled) ? |
| 46 APP_LAUNCHER_ENABLED : APP_LAUNCHER_DISABLED; |
52 #endif | 47 #endif |
53 } | 48 } |
54 | 49 |
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); | |
62 } | |
63 | |
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)); | |
70 } | |
71 #endif | |
72 | |
73 } // namespace | 50 } // namespace |
74 | 51 |
75 bool MaybeIsAppLauncherEnabled() { | 52 bool MaybeIsAppLauncherEnabled() { |
76 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; | 53 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; |
77 } | 54 } |
78 | 55 |
79 void GetIsAppLauncherEnabled( | 56 void GetIsAppLauncherEnabled( |
80 const OnAppLauncherEnabledCompleted& completion_callback) { | 57 const OnAppLauncherEnabledCompleted& completion_callback) { |
81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
82 | 59 |
83 AppLauncherState state = SynchronousAppLauncherChecks(); | 60 AppLauncherState state = SynchronousAppLauncherChecks(); |
84 | 61 |
85 if (state != APP_LAUNCHER_UNKNOWN) { | 62 if (state != APP_LAUNCHER_UNKNOWN) { |
86 bool is_enabled = state == APP_LAUNCHER_ENABLED; | 63 completion_callback.Run(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; | 64 return; |
91 } | 65 } |
92 | |
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(); | 66 NOTREACHED(); |
102 #endif | |
103 } | 67 } |
104 | 68 |
105 bool WasAppLauncherEnabled() { | 69 bool WasAppLauncherEnabled() { |
106 PrefService* prefs = g_browser_process->local_state(); | 70 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; |
107 // In some tests, the prefs aren't initialised. | |
108 if (!prefs) | |
109 return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; | |
110 return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); | |
111 } | 71 } |
112 | 72 |
113 } // namespace apps | 73 } // namespace apps |
OLD | NEW |