summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 06:15:10 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-12 06:15:10 +0000
commitdc63aab9a03d091b4c88a0967d19f52a61212e16 (patch)
tree41ddfc74523057a226abca2ddfd52e83a00e75ae /apps
parentb1c20f53f919d5d14694562b659d0957fcd30997 (diff)
downloadchromium_src-dc63aab9a03d091b4c88a0967d19f52a61212e16.zip
chromium_src-dc63aab9a03d091b4c88a0967d19f52a61212e16.tar.gz
chromium_src-dc63aab9a03d091b4c88a0967d19f52a61212e16.tar.bz2
Move app_launcher.* out of chrome/browser/extensions and into apps/
This change also moves some UI code from chrome/browser/extensions into /chrome/browser/ui/, and cleans up the app_launcher.* code. BUG=159366 Review URL: https://chromiumcodereview.appspot.com/12095052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181875 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/DEPS6
-rw-r--r--apps/app_launcher.cc107
-rw-r--r--apps/app_launcher.h38
-rw-r--r--apps/apps.gypi6
-rw-r--r--apps/pref_names.cc17
-rw-r--r--apps/pref_names.h18
-rw-r--r--apps/prefs.cc25
-rw-r--r--apps/prefs.h17
8 files changed, 233 insertions, 1 deletions
diff --git a/apps/DEPS b/apps/DEPS
index 980e672..0fc9ed2 100644
--- a/apps/DEPS
+++ b/apps/DEPS
@@ -2,9 +2,13 @@ include_rules = [
"+base",
"+content",
# Temporary allowed includes.
- # TODO(benwells): remove these.
+ # TODO(benwells): remove these (http://crbug.com/159366)
+ "+chrome/browser/browser_process.h",
"+chrome/browser/extensions",
+ "+chrome/browser/prefs",
"+chrome/browser/profiles",
"+chrome/common/chrome_notification_types.h",
+ "+chrome/common/chrome_switches.h",
"+chrome/common/extensions",
+ "+chrome/installer",
]
diff --git a/apps/app_launcher.cc b/apps/app_launcher.cc
new file mode 100644
index 0000000..73011bc
--- /dev/null
+++ b/apps/app_launcher.cc
@@ -0,0 +1,107 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_launcher.h"
+
+#include "apps/pref_names.h"
+#include "base/command_line.h"
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/browser/browser_thread.h"
+
+#if defined(OS_WIN)
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+#include "chrome/installer/util/browser_distribution.h"
+#endif
+
+namespace apps {
+
+namespace {
+
+enum AppLauncherState {
+ APP_LAUNCHER_UNKNOWN,
+ APP_LAUNCHER_ENABLED,
+ APP_LAUNCHER_DISABLED,
+};
+
+AppLauncherState SynchronousAppLauncherChecks() {
+#if defined(USE_ASH)
+ return APP_LAUNCHER_ENABLED;
+#elif !defined(OS_WIN)
+ return APP_LAUNCHER_DISABLED;
+#else
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kShowAppListShortcut)) {
+ return APP_LAUNCHER_ENABLED;
+ }
+
+ if (!BrowserDistribution::GetDistribution()->AppHostIsSupported())
+ return APP_LAUNCHER_DISABLED;
+
+ return APP_LAUNCHER_UNKNOWN;
+#endif
+}
+
+#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(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
+}
+#endif
+
+} // namespace
+
+bool MaybeIsAppLauncherEnabled() {
+ return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
+}
+
+void GetIsAppLauncherEnabled(
+ 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;
+ }
+
+#if defined(OS_WIN)
+ content::BrowserThread::PostBlockingPoolTask(
+ FROM_HERE,
+ base::Bind(&IsAppLauncherInstalledOnBlockingPool,
+ completion_callback));
+#else
+ // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on
+ // !defined(OS_WIN), so this path is never reached.
+ NOTREACHED();
+#endif
+}
+
+bool WasAppLauncherEnabled() {
+ PrefService* prefs = g_browser_process->local_state();
+ // In some tests, the prefs aren't initialised.
+ if (!prefs)
+ return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
+ return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
+}
+
+} // namespace apps
diff --git a/apps/app_launcher.h b/apps/app_launcher.h
new file mode 100644
index 0000000..b6bbed3
--- /dev/null
+++ b/apps/app_launcher.h
@@ -0,0 +1,38 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_APPS_APP_LAUNCHER_H_
+#define CHROME_APPS_APP_LAUNCHER_H_
+
+#include "base/basictypes.h"
+#include "base/callback_forward.h"
+
+class PrefRegistrySimple;
+
+namespace apps {
+
+// Called on the UI thread after determining if the launcher is enabled. A
+// boolean flag is passed, which is true if the app launcher is enabled.
+typedef base::Callback<void(bool)> OnAppLauncherEnabledCompleted;
+
+// A synchronous check to determine if the app launcher is enabled. If the
+// registry needs to be determined to find an accurate answer, this function
+// will NOT do so; instead if will default to false (the app launcher is not
+// enabled).
+// This function does not use the cached preference of whether the launcher
+// was enabled or not.
+bool MaybeIsAppLauncherEnabled();
+
+// Determine whether the app launcher is enabled or not. This may involve a trip
+// to a blocking thread. |completion_callback| is called when an answer is
+// ready. This needs to be called on the UI thread.
+void GetIsAppLauncherEnabled(
+ const OnAppLauncherEnabledCompleted& completion_callback);
+
+// Returns whether the app launcher was enabled the last time it was checked.
+bool WasAppLauncherEnabled();
+
+} // namespace extensions
+
+#endif // CHROME_APPS_APP_LAUNCHER_H_
diff --git a/apps/apps.gypi b/apps/apps.gypi
index 43f9cc5..257195d 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -22,10 +22,16 @@
'<(INTERMEDIATE_DIR)',
],
'sources': [
+ 'app_launcher.cc',
+ 'app_launcher.h',
'app_restore_service.cc',
'app_restore_service.h',
'app_restore_service_factory.cc',
'app_restore_service_factory.h',
+ 'pref_names.cc',
+ 'pref_names.h',
+ 'prefs.cc',
+ 'prefs.h',
],
'conditions': [
['enable_extensions==0', {
diff --git a/apps/pref_names.cc b/apps/pref_names.cc
new file mode 100644
index 0000000..15a33f9
--- /dev/null
+++ b/apps/pref_names.cc
@@ -0,0 +1,17 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/pref_names.h"
+
+namespace apps {
+
+namespace prefs {
+
+// Local state caching knowledge of whether the app launcher is installed.
+const char kAppLauncherIsEnabled[] =
+ "apps.app_launcher.should_show_apps_page";
+
+} // namespace prefs
+
+} // namespace apps
diff --git a/apps/pref_names.h b/apps/pref_names.h
new file mode 100644
index 0000000..1cca82f
--- /dev/null
+++ b/apps/pref_names.h
@@ -0,0 +1,18 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_PREF_NAMES_H_
+#define APPS_PREF_NAMES_H_
+
+namespace apps {
+
+namespace prefs {
+
+extern const char kAppLauncherIsEnabled[];
+
+} // namespace prefs
+
+} // namespace apps
+
+#endif // APPS_PREF_NAMES_H_
diff --git a/apps/prefs.cc b/apps/prefs.cc
new file mode 100644
index 0000000..b883fbb
--- /dev/null
+++ b/apps/prefs.cc
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/prefs.h"
+
+#include "apps/app_launcher.h"
+#include "apps/pref_names.h"
+#include "base/prefs/pref_registry_simple.h"
+
+namespace apps {
+
+void RegisterPrefs(PrefRegistrySimple* registry) {
+ // This pref is a cache of the value from the registry the last time it was
+ // checked.
+ //
+ // During the pref initialization, 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
+ // GetIsAppLauncherEnabled().
+ registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled,
+ MaybeIsAppLauncherEnabled());
+}
+
+} // namespace apps
diff --git a/apps/prefs.h b/apps/prefs.h
new file mode 100644
index 0000000..3734860
--- /dev/null
+++ b/apps/prefs.h
@@ -0,0 +1,17 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_PREFS_H_
+#define APPS_PREFS_H_
+
+class PrefRegistrySimple;
+
+namespace apps {
+
+// Register preferences for the apps system.
+void RegisterPrefs(PrefRegistrySimple* registry);
+
+} // namespace apps
+
+#endif // APPS_PREFS_H_