Skip to content

Commit

Permalink
Add ExtensionsBrowserClient and AppSorting to app_shell
Browse files Browse the repository at this point in the history
This lets it run a little further when attempting to run an app.

BUG=None
TEST=None

Review URL: https://codereview.chromium.org/106033002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239311 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamescook@chromium.org committed Dec 7, 2013
1 parent 7eb7dc4 commit da762a8
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 36 deletions.
6 changes: 4 additions & 2 deletions apps/app_load_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "apps/shell_window_registry.h"
#include "chrome/browser/extensions/extension_prefs_factory.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
#include "extensions/browser/extensions_browser_client.h"

namespace apps {

Expand Down Expand Up @@ -51,7 +51,9 @@ bool AppLoadServiceFactory::ServiceIsCreatedWithBrowserContext() const {

content::BrowserContext* AppLoadServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
// Redirected in incognito.
return extensions::ExtensionsBrowserClient::Get()->
GetOriginalContext(context);
}

} // namespace apps
4 changes: 4 additions & 0 deletions apps/apps.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
'..',
],
'sources': [
'shell/app_shell_app_sorting.cc',
'shell/app_shell_app_sorting.h',
'shell/app_shell_browser_context.cc',
'shell_app_shell_browser_context.h',
'shell/app_shell_browser_main_parts.cc',
Expand All @@ -130,6 +132,8 @@
'shell/app_shell_content_browser_client.h',
'shell/app_shell_content_client.cc',
'shell/app_shell_content_client.h',
'shell/app_shell_extensions_browser_client.cc',
'shell/app_shell_extensions_browser_client.h',
'shell/app_shell_main_delegate.cc',
'shell/app_shell_main_delegate.h',
'shell/app_shell_main.cc',
Expand Down
1 change: 1 addition & 0 deletions apps/shell/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_rules = [
"-chrome",
"+chromeos",
"+components/user_prefs",
"+sync/api",
"+ui/shell",
"+webkit/common/user_agent/user_agent_util.h",

Expand Down
107 changes: 107 additions & 0 deletions apps/shell/app_shell_app_sorting.cc
Original file line number Diff line number Diff line change
@@ -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/shell/app_shell_app_sorting.h"

#include "sync/api/string_ordinal.h"

namespace {

// Ordinals for a single app on a single page.
const char kFirstApp[] = "a";
const char kNextApp[] = "b";
const char kFirstPage[] = "a";

} // namespace

namespace apps {

AppShellAppSorting::AppShellAppSorting() {
}

AppShellAppSorting::~AppShellAppSorting() {
}

void AppShellAppSorting::SetExtensionScopedPrefs(
extensions::ExtensionScopedPrefs* prefs) {
}

void AppShellAppSorting::SetExtensionSyncService(
ExtensionSyncService* extension_sync_service) {
}

void AppShellAppSorting::Initialize(
const extensions::ExtensionIdList& extension_ids) {
}

void AppShellAppSorting::FixNTPOrdinalCollisions() {
}

void AppShellAppSorting::EnsureValidOrdinals(
const std::string& extension_id,
const syncer::StringOrdinal& suggested_page) {
}

void AppShellAppSorting::OnExtensionMoved(
const std::string& moved_extension_id,
const std::string& predecessor_extension_id,
const std::string& successor_extension_id) {
}

syncer::StringOrdinal AppShellAppSorting::GetAppLaunchOrdinal(
const std::string& extension_id) const {
return syncer::StringOrdinal(kFirstApp);
}

void AppShellAppSorting::SetAppLaunchOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_app_launch_ordinal) {
}

syncer::StringOrdinal AppShellAppSorting::CreateFirstAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const {
return syncer::StringOrdinal(kFirstApp);
}

syncer::StringOrdinal AppShellAppSorting::CreateNextAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const {
return syncer::StringOrdinal(kNextApp);
}

syncer::StringOrdinal AppShellAppSorting::CreateFirstAppPageOrdinal() const {
return syncer::StringOrdinal(kFirstPage);
}

syncer::StringOrdinal AppShellAppSorting::GetNaturalAppPageOrdinal() const {
return syncer::StringOrdinal(kFirstPage);
}

syncer::StringOrdinal AppShellAppSorting::GetPageOrdinal(
const std::string& extension_id) const {
return syncer::StringOrdinal(kFirstPage);
}

void AppShellAppSorting::SetPageOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_page_ordinal) {
}

void AppShellAppSorting::ClearOrdinals(const std::string& extension_id) {
}

int AppShellAppSorting::PageStringOrdinalAsInteger(
const syncer::StringOrdinal& page_ordinal) const {
return 0;
}

syncer::StringOrdinal AppShellAppSorting::PageIntegerAsStringOrdinal(
size_t page_index) {
return syncer::StringOrdinal(kFirstPage);
}

void AppShellAppSorting::MarkExtensionAsHidden(
const std::string& extension_id) {
}

} // namespace apps
64 changes: 64 additions & 0 deletions apps/shell/app_shell_app_sorting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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_SHELL_APP_SHELL_APP_SORTING_H_
#define APPS_SHELL_APP_SHELL_APP_SORTING_H_

#include "base/compiler_specific.h"
#include "extensions/browser/app_sorting.h"

namespace apps {

// A stub AppSorting. Since app_shell only runs a single app we don't need to
// sort them.
class AppShellAppSorting : public extensions::AppSorting {
public:
AppShellAppSorting();
virtual ~AppShellAppSorting();

// extensions::AppSorting overrides:
virtual void SetExtensionScopedPrefs(extensions::ExtensionScopedPrefs* prefs)
OVERRIDE;
virtual void SetExtensionSyncService(
ExtensionSyncService* extension_sync_service) OVERRIDE;
virtual void Initialize(
const extensions::ExtensionIdList& extension_ids) OVERRIDE;
virtual void FixNTPOrdinalCollisions() OVERRIDE;
virtual void EnsureValidOrdinals(
const std::string& extension_id,
const syncer::StringOrdinal& suggested_page) OVERRIDE;
virtual void OnExtensionMoved(
const std::string& moved_extension_id,
const std::string& predecessor_extension_id,
const std::string& successor_extension_id) OVERRIDE;
virtual syncer::StringOrdinal GetAppLaunchOrdinal(
const std::string& extension_id) const OVERRIDE;
virtual void SetAppLaunchOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_app_launch_ordinal) OVERRIDE;
virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const OVERRIDE;
virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const OVERRIDE;
virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const OVERRIDE;
virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const OVERRIDE;
virtual syncer::StringOrdinal GetPageOrdinal(
const std::string& extension_id) const OVERRIDE;
virtual void SetPageOrdinal(
const std::string& extension_id,
const syncer::StringOrdinal& new_page_ordinal) OVERRIDE;
virtual void ClearOrdinals(const std::string& extension_id) OVERRIDE;
virtual int PageStringOrdinalAsInteger(
const syncer::StringOrdinal& page_ordinal) const OVERRIDE;
virtual syncer::StringOrdinal PageIntegerAsStringOrdinal(
size_t page_index) OVERRIDE;
virtual void MarkExtensionAsHidden(const std::string& extension_id) OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(AppShellAppSorting);
};

} // namespace apps

#endif // APPS_SHELL_APP_SHELL_APP_SORTING_H_
23 changes: 0 additions & 23 deletions apps/shell/app_shell_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#include "apps/shell/app_shell_browser_context.h"

#include "apps/app_load_service_factory.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/pref_service_factory.h"
#include "base/prefs/testing_pref_store.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"

namespace {

Expand All @@ -18,11 +13,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
apps::AppLoadServiceFactory::GetInstance();
}

// See chrome::RegisterProfilePrefs() in chrome/browser/prefs/browser_prefs.cc
void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) {
// TODO(jamescook): ExtensionPrefs::RegisterProfilePrefs(registry)
}

} // namespace

namespace apps {
Expand All @@ -33,19 +23,6 @@ namespace apps {
AppShellBrowserContext::AppShellBrowserContext()
: content::ShellBrowserContext(false, NULL) {
EnsureBrowserContextKeyedServiceFactoriesBuilt();

base::PrefServiceFactory factory;
factory.set_user_prefs(new TestingPrefStore);
factory.set_extension_prefs(new TestingPrefStore);
// app_shell should not require syncable preferences, but for now we need to
// recycle some of the RegisterProfilePrefs() code in Chrome.
// TODO(jamescook): Convert this to user_prefs::PrefRegistrySimple.
user_prefs::PrefRegistrySyncable* pref_registry =
new user_prefs::PrefRegistrySyncable;
// Prefs should be registered before the PrefService is created.
RegisterPrefs(pref_registry);
prefs_ = factory.Create(pref_registry).Pass();
user_prefs::UserPrefs::Set(this, prefs_.get());
}

AppShellBrowserContext::~AppShellBrowserContext() {
Expand Down
4 changes: 0 additions & 4 deletions apps/shell/app_shell_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "base/compiler_specific.h"
#include "content/shell/browser/shell_browser_context.h"

class PrefService;

namespace apps {

// The BrowserContext used by the content, apps and extensions systems in
Expand All @@ -32,8 +30,6 @@ class AppShellBrowserContext : public content::ShellBrowserContext {
virtual void ProfileFunctionCallOnNonProfileBrowserContext9();

private:
scoped_ptr<PrefService> prefs_;

DISALLOW_COPY_AND_ASSIGN(AppShellBrowserContext);
};

Expand Down
10 changes: 8 additions & 2 deletions apps/shell/app_shell_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "apps/app_load_service.h"
#include "apps/shell/app_shell_browser_context.h"
#include "apps/shell/app_shell_extensions_browser_client.h"
#include "apps/shell/web_view_window.h"
#include "base/command_line.h"
#include "base/file_util.h"
Expand Down Expand Up @@ -93,11 +94,14 @@ void AppShellBrowserMainParts::PreMainMessageLoopRun() {

// TODO(jamescook): Initialize chromeos::UserManager.

// TODO(jamescook): Initialize ExtensionsClient and ExtensionsBrowserClient.

// Initialize our "profile" equivalent.
browser_context_.reset(new AppShellBrowserContext);

// TODO(jamescook): Initialize ExtensionsClient.
extensions_browser_client_.reset(
new AppShellExtensionsBrowserClient(browser_context_.get()));
extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());

// TODO(jamescook): Initialize policy::ProfilePolicyConnector.
// TODO(jamescook): Initialize ExtensionSystem and InitForRegularProfile.
// TODO(jamescook): CreateBrowserContextServices using
Expand Down Expand Up @@ -127,6 +131,8 @@ bool AppShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
}

void AppShellBrowserMainParts::PostMainMessageLoopRun() {
extensions::ExtensionsBrowserClient::Set(NULL);
extensions_browser_client_.reset();
browser_context_.reset();
wm_test_helper_.reset();
aura::Env::DeleteInstance();
Expand Down
2 changes: 2 additions & 0 deletions apps/shell/app_shell_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WMTestHelper;
namespace apps {

class AppShellBrowserContext;
class AppShellExtensionsBrowserClient;

// Handles initialization of AppShell.
class AppShellBrowserMainParts : public content::BrowserMainParts {
Expand Down Expand Up @@ -59,6 +60,7 @@ class AppShellBrowserMainParts : public content::BrowserMainParts {

private:
scoped_ptr<AppShellBrowserContext> browser_context_;
scoped_ptr<AppShellExtensionsBrowserClient> extensions_browser_client_;

// Enable a minimal set of views::corewm to be initialized.
scoped_ptr<wm::WMTestHelper> wm_test_helper_;
Expand Down
Loading

0 comments on commit da762a8

Please sign in to comment.