Index: chrome/browser/extensions/app_launcher.cc |
diff --git a/chrome/browser/extensions/app_launcher.cc b/chrome/browser/extensions/app_launcher.cc |
index 788179459fbb781c33362f356d282feaab0c39e8..2338281630a8c80dfbc3e074f60900ab734e20a9 100644 |
--- a/chrome/browser/extensions/app_launcher.cc |
+++ b/chrome/browser/extensions/app_launcher.cc |
@@ -6,7 +6,10 @@ |
#include "base/command_line.h" |
#include "base/threading/sequenced_worker_pool.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.h" |
#include "content/public/browser/browser_thread.h" |
#if defined(OS_WIN) |
@@ -19,34 +22,61 @@ namespace extensions { |
namespace { |
#if defined(OS_WIN) |
+void UpdatePrefAndCallCallbackOnUI( |
+ bool result, |
+ const OnAppLauncherEnabledCompleted& completion_callback) { |
+ PrefService* prefs = g_browser_process->local_state(); |
+ prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result); |
+ completion_callback.Run(result); |
+} |
+ |
void IsAppLauncherInstalledOnBlockingPool( |
const OnAppLauncherEnabledCompleted& completion_callback) { |
DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
bool result = chrome_launcher_support::IsAppLauncherPresent(); |
- content::BrowserThread::PostTask(content::BrowserThread::UI, |
- FROM_HERE, |
- base::Bind(completion_callback, result)); |
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback)); |
} |
#endif |
} // namespace |
-void GetIsAppLauncherEnabled( |
- const OnAppLauncherEnabledCompleted& completion_callback) { |
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+enum AppLauncherState { |
+ APP_LAUNCHER_UNKNOWN, |
+ APP_LAUNCHER_ENABLED, |
+ APP_LAUNCHER_DISABLED, |
+}; |
+ |
+AppLauncherState SynchronousAppLauncherChecks() { |
#if defined(OS_CHROMEOS) |
Evan Stade
2013/01/24 18:40:17
should this be USE_ASH?
jeremya
2013/01/25 00:06:19
Yeah, I think that makes sense. Changed.
|
- completion_callback.Run(true); |
+ return APP_LAUNCHER_ENABLED; |
#elif !defined(OS_WIN) |
- completion_callback.Run(false); |
+ return APP_LAUNCHER_DISABLED; |
#else |
if (CommandLine::ForCurrentProcess()->HasSwitch( |
switches::kShowAppListShortcut)) { |
- completion_callback.Run(true); |
- return; |
+ return APP_LAUNCHER_ENABLED; |
} |
if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) { |
- completion_callback.Run(false); |
+ return APP_LAUNCHER_DISABLED; |
+ } |
Evan Stade
2013/01/24 18:40:17
nit: no curlies
jeremya
2013/01/25 00:06:19
Done.
|
+ |
+ return APP_LAUNCHER_UNKNOWN; |
+#endif |
+} |
+ |
+void UpdateIsAppLauncherEnabled( |
+ const OnAppLauncherEnabledCompleted& completion_callback) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ |
+ AppLauncherState state = SynchronousAppLauncherChecks(); |
+ |
+ if (state != APP_LAUNCHER_UNKNOWN) { |
+ bool is_enabled = state == APP_LAUNCHER_ENABLED; |
+ PrefService* prefs = g_browser_process->local_state(); |
+ prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled); |
+ completion_callback.Run(is_enabled); |
return; |
} |
@@ -54,7 +84,21 @@ void GetIsAppLauncherEnabled( |
FROM_HERE, |
base::Bind(&IsAppLauncherInstalledOnBlockingPool, |
completion_callback)); |
-#endif |
} |
+bool IsAppLauncherEnabled() { |
+ PrefService* prefs = g_browser_process->local_state(); |
+ return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); |
+} |
+ |
+namespace app_launcher { |
Evan Stade
2013/01/24 18:40:17
\n
|
+void RegisterPrefs(PrefServiceSimple* pref_service) { |
+ // If it is impossible to synchronously determine whether the app launcher is |
+ // enabled, assume it is disabled. Anything that needs to know the absolute |
+ // truth should call UpdateIsAppLauncherEnabled(). |
+ bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; |
+ pref_service->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled); |
Evan Stade
2013/01/24 18:40:17
would be nice to explain a bit more why this is ne
jeremya
2013/01/25 00:06:19
Done.
|
+} |
Evan Stade
2013/01/24 18:40:17
\n
|
+} // namespace app_launcher |
+ |
} // namespace extensions |