Skip to content

Commit

Permalink
Move app_launcher.* out of chrome/browser/extensions and into apps/
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benwells@chromium.org committed Feb 12, 2013
1 parent b1c20f5 commit dc63aab
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 94 deletions.
6 changes: 5 additions & 1 deletion apps/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
78 changes: 32 additions & 46 deletions chrome/browser/extensions/app_launcher.cc → apps/app_launcher.cc
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// 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 "chrome/browser/extensions/app_launcher.h"
#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 "chrome/common/pref_names.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 extensions {
namespace apps {

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(UpdatePrefAndCallCallbackOnUI, result, completion_callback));
}
#endif

} // namespace

enum AppLauncherState {
APP_LAUNCHER_UNKNOWN,
APP_LAUNCHER_ENABLED,
Expand All @@ -66,7 +46,31 @@ AppLauncherState SynchronousAppLauncherChecks() {
#endif
}

void UpdateIsAppLauncherEnabled(
#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));

Expand All @@ -92,30 +96,12 @@ void UpdateIsAppLauncherEnabled(
#endif
}

bool IsAppLauncherEnabled() {
bool WasAppLauncherEnabled() {
PrefService* prefs = g_browser_process->local_state();
// In some tests, the prefs aren't initialised, but the NTP still needs to
// work.
// In some tests, the prefs aren't initialised.
if (!prefs)
return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
return prefs->GetBoolean(prefs::kAppLauncherIsEnabled);
}

namespace app_launcher {

void RegisterPrefs(PrefRegistrySimple* registry) {
// 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().
//
// This pref is just a cache of the value from the registry from last time
// Chrome ran. To avoid having the NTP block on a registry check, it guesses
// that the value hasn't changed since last time it was checked, using this
// preference.
bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED;
registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled);
}

} // namespace app_launcher

} // namespace extensions
} // namespace apps
28 changes: 16 additions & 12 deletions chrome/browser/extensions/app_launcher.h → apps/app_launcher.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// 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_BROWSER_EXTENSIONS_APP_LAUNCHER_H_
#define CHROME_BROWSER_EXTENSIONS_APP_LAUNCHER_H_
#ifndef CHROME_APPS_APP_LAUNCHER_H_
#define CHROME_APPS_APP_LAUNCHER_H_

#include "base/basictypes.h"
#include "base/callback_forward.h"

class PrefRegistrySimple;

namespace extensions {
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 UpdateIsAppLauncherEnabled(
void GetIsAppLauncherEnabled(
const OnAppLauncherEnabledCompleted& completion_callback);

// returns value of pref. 'was app launcher enabled last time i checked'.
bool IsAppLauncherEnabled();

namespace app_launcher {
void RegisterPrefs(PrefRegistrySimple* registry);
}
// Returns whether the app launcher was enabled the last time it was checked.
bool WasAppLauncherEnabled();

} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_APP_LAUNCHER_H_
#endif // CHROME_APPS_APP_LAUNCHER_H_
6 changes: 6 additions & 0 deletions apps/apps.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
17 changes: 17 additions & 0 deletions apps/pref_names.cc
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions apps/pref_names.h
Original file line number Diff line number Diff line change
@@ -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_
25 changes: 25 additions & 0 deletions apps/prefs.cc
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions apps/prefs.h
Original file line number Diff line number Diff line change
@@ -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_
3 changes: 3 additions & 0 deletions chrome/browser/extensions/api/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+apps",
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"

#include "apps/app_launcher.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
Expand All @@ -14,7 +15,6 @@
#include "base/values.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/app_launcher.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_prefs.h"
Expand Down Expand Up @@ -458,7 +458,7 @@ bool CompleteInstallFunction::RunImpl() {
}

void CompleteInstallFunction::AfterMaybeInstallAppLauncher(bool ok) {
UpdateIsAppLauncherEnabled(base::Bind(
apps::GetIsAppLauncherEnabled(base::Bind(
&CompleteInstallFunction::OnGetAppLauncherEnabled, this,
approval_->extension_id));
}
Expand Down Expand Up @@ -580,7 +580,7 @@ void GetWebGLStatusFunction::OnFeatureCheck(bool feature_allowed) {
}

bool GetIsLauncherEnabledFunction::RunImpl() {
UpdateIsAppLauncherEnabled(base::Bind(
apps::GetIsAppLauncherEnabled(base::Bind(
&GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted, this));
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/prefs/browser_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/prefs/browser_prefs.h"

#include "apps/prefs.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/about_flags.h"
Expand All @@ -21,7 +22,6 @@
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include "chrome/browser/extensions/app_launcher.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_web_ui.h"
Expand Down Expand Up @@ -159,10 +159,10 @@ void RegisterLocalState(PrefService* local_state,
registry->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0);

// Please keep this list alphabetized.
apps::RegisterPrefs(registry);
browser_shutdown::RegisterPrefs(registry);
BrowserProcessImpl::RegisterPrefs(registry);
chrome::RegisterScreenshotPrefs(registry);
extensions::app_launcher::RegisterPrefs(registry);
ExternalProtocolHandler::RegisterPrefs(registry);
FlagsUI::RegisterPrefs(registry);
geolocation::RegisterPrefs(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_install_ui_android.h"
#include "chrome/browser/ui/android/extensions/extension_install_ui_android.h"

#include "base/logging.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_
#ifndef CHROME_BROWSER_UI_ANDROID_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_
#define CHROME_BROWSER_UI_ANDROID_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_

#include "chrome/browser/extensions/extension_install_ui.h"

Expand All @@ -23,4 +23,4 @@ class ExtensionInstallUIAndroid : public ExtensionInstallUI {
DISALLOW_COPY_AND_ASSIGN(ExtensionInstallUIAndroid);
};

#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_
#endif // CHROME_BROWSER_UI_ANDROID_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_
Loading

0 comments on commit dc63aab

Please sign in to comment.