Commit 121e8899 authored by reillyg's avatar reillyg Committed by Commit bot

Split Blacklist from ExtensionSystem.

This patch removes another service from ExtensionSystem that can easily
be its own browser context keyed service. If the ExtensionPrefs
dependency Blacklist can be removed it could be promoted to a true
singleton.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#302496}
parent 1446adbe
......@@ -455,7 +455,7 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlockedByPolicy) {
IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlacklistedForMalware) {
// Mock a BLACKLISTED_MALWARE return status.
extensions::TestBlacklist blacklist_tester(
ExtensionSystem::Get(profile())->blacklist());
extensions::Blacklist::Get(profile()));
blacklist_tester.SetBlacklistState(
kDefaultAppId, extensions::BLACKLISTED_MALWARE, false);
......@@ -468,7 +468,7 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlacklistedForMalware) {
IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, BlacklistStateUnknown) {
// Mock a BLACKLISTED_MALWARE return status.
extensions::TestBlacklist blacklist_tester(
ExtensionSystem::Get(profile())->blacklist());
extensions::Blacklist::Get(profile()));
blacklist_tester.SetBlacklistState(
kDefaultAppId, extensions::BLACKLISTED_UNKNOWN, false);
......
......@@ -14,6 +14,7 @@
#include "base/stl_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/blacklist_factory.h"
#include "chrome/browser/extensions/blacklist_state_fetcher.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_util.h"
......@@ -180,6 +181,11 @@ Blacklist::Blacklist(ExtensionPrefs* prefs) {
Blacklist::~Blacklist() {
}
// static
Blacklist* Blacklist::Get(content::BrowserContext* context) {
return BlacklistFactory::GetForBrowserContext(context);
}
void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids,
const GetBlacklistedIDsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
......@@ -16,10 +16,15 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/safe_browsing/database_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/blacklist_state.h"
namespace content {
class BrowserContext;
}
namespace extensions {
class BlacklistStateFetcher;
......@@ -27,7 +32,8 @@ class Extension;
class ExtensionPrefs;
// The blacklist of extensions backed by safe browsing.
class Blacklist : public content::NotificationObserver,
class Blacklist : public KeyedService,
public content::NotificationObserver,
public base::SupportsWeakPtr<Blacklist> {
public:
class Observer {
......@@ -71,6 +77,8 @@ class Blacklist : public content::NotificationObserver,
~Blacklist() override;
static Blacklist* Get(content::BrowserContext* context);
// From the set of extension IDs passed in via |ids|, asynchronously checks
// which are blacklisted and includes them in the resulting map passed
// via |callback|, which will be sent on the caller's message loop. The values
......
// Copyright 2014 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/blacklist.h"
#include "chrome/browser/extensions/blacklist_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extensions_browser_client.h"
using content::BrowserContext;
namespace extensions {
// static
Blacklist* BlacklistFactory::GetForBrowserContext(BrowserContext* context) {
return static_cast<Blacklist*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
BlacklistFactory* BlacklistFactory::GetInstance() {
return Singleton<BlacklistFactory>::get();
}
BlacklistFactory::BlacklistFactory()
: BrowserContextKeyedServiceFactory(
"Blacklist",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(extensions::ExtensionPrefsFactory::GetInstance());
}
BlacklistFactory::~BlacklistFactory() {
}
KeyedService* BlacklistFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
return new Blacklist(ExtensionPrefs::Get(context));
}
BrowserContext* BlacklistFactory::GetBrowserContextToUse(
BrowserContext* context) const {
// Redirected in incognito.
return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
}
} // namespace extensions
// Copyright 2014 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_BLACKLIST_FACTORY_H_
#define CHROME_BROWSER_EXTENSIONS_BLACKLIST_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace extensions {
class Blacklist;
class BlacklistFactory : public BrowserContextKeyedServiceFactory {
public:
static Blacklist* GetForBrowserContext(content::BrowserContext* context);
static BlacklistFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<BlacklistFactory>;
BlacklistFactory();
virtual ~BlacklistFactory();
// BrowserContextKeyedServiceFactory
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
virtual content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(BlacklistFactory);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_FACTORY_H_
......@@ -114,8 +114,7 @@ void ExtensionInstallChecker::OnRequirementsCheckDone(
void ExtensionInstallChecker::CheckBlacklistState() {
DCHECK(extension_.get());
extensions::Blacklist* blacklist =
ExtensionSystem::Get(profile_)->blacklist();
extensions::Blacklist* blacklist = Blacklist::Get(profile_);
blacklist->IsBlacklisted(
extension_->id(),
base::Bind(&ExtensionInstallChecker::OnBlacklistStateCheckDone,
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/blacklist_factory.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/profile.h"
......@@ -45,6 +46,7 @@ ExtensionSystemSharedFactory::ExtensionSystemSharedFactory()
DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance());
DependsOn(ProcessManagerFactory::GetInstance());
DependsOn(RendererStartupHelperFactory::GetInstance());
DependsOn(BlacklistFactory::GetInstance());
}
ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() {
......
......@@ -15,7 +15,6 @@
#include "base/strings/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/extensions/blacklist.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/declarative_user_script_master.h"
#include "chrome/browser/extensions/error_console/error_console.h"
......@@ -118,8 +117,6 @@ void ExtensionSystemImpl::Shared::InitPrefs() {
profile_->GetPath().AppendASCII(extensions::kRulesStoreName),
false));
blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_)));
#if defined(OS_CHROMEOS)
const user_manager::User* user =
user_manager::UserManager::Get()->GetActiveUser();
......@@ -319,7 +316,7 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
CommandLine::ForCurrentProcess(),
profile_->GetPath().AppendASCII(extensions::kInstallDirectoryName),
ExtensionPrefs::Get(profile_),
blacklist_.get(),
Blacklist::Get(profile_),
autoupdate_enabled,
extensions_enabled,
&ready_));
......@@ -449,10 +446,6 @@ EventRouter* ExtensionSystemImpl::Shared::event_router() {
return event_router_.get();
}
Blacklist* ExtensionSystemImpl::Shared::blacklist() {
return blacklist_.get();
}
ErrorConsole* ExtensionSystemImpl::Shared::error_console() {
return error_console_.get();
}
......@@ -553,10 +546,6 @@ EventRouter* ExtensionSystemImpl::event_router() {
return shared_->event_router();
}
Blacklist* ExtensionSystemImpl::blacklist() {
return shared_->blacklist();
}
const OneShotEvent& ExtensionSystemImpl::ready() const {
return shared_->ready();
}
......
......@@ -45,7 +45,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
LazyBackgroundTaskQueue* lazy_background_task_queue() override; // shared
InfoMap* info_map() override; // shared
EventRouter* event_router() override; // shared
Blacklist* blacklist() override; // shared
ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override;
QuotaService* quota_service() override; // shared
......@@ -90,7 +89,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
RuntimeData* runtime_data();
ManagementPolicy* management_policy();
SharedUserScriptMaster* shared_user_script_master();
Blacklist* blacklist();
InfoMap* info_map();
LazyBackgroundTaskQueue* lazy_background_task_queue();
EventRouter* event_router();
......@@ -124,7 +122,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
// per extension. Managers are instantiated the first time the declarative
// API is used by an extension to request content scripts.
ScopedVector<DeclarativeUserScriptMaster> declarative_user_script_masters_;
scoped_ptr<Blacklist> blacklist_;
scoped_ptr<RuntimeData> runtime_data_;
// ExtensionService depends on StateStore, Blacklist and RuntimeData.
scoped_ptr<ExtensionService> extension_service_;
......
......@@ -87,7 +87,6 @@ ExtensionService* TestExtensionSystem::CreateExtensionService(
scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
value_store_ = value_store.get();
state_store_.reset(new StateStore(profile_, value_store.Pass()));
blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_)));
management_policy_.reset(new ManagementPolicy());
management_policy_->RegisterProviders(
ExtensionManagementFactory::GetForBrowserContext(profile_)
......@@ -97,7 +96,7 @@ ExtensionService* TestExtensionSystem::CreateExtensionService(
command_line,
install_directory,
ExtensionPrefs::Get(profile_),
blacklist_.get(),
Blacklist::Get(profile_),
autoupdate_enabled,
true,
&ready_));
......@@ -146,10 +145,6 @@ void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) {
EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); }
Blacklist* TestExtensionSystem::blacklist() {
return blacklist_.get();
}
ErrorConsole* TestExtensionSystem::error_console() {
return error_console_.get();
}
......
......@@ -66,7 +66,6 @@ class TestExtensionSystem : public ExtensionSystem {
LazyBackgroundTaskQueue* lazy_background_task_queue() override;
void SetEventRouter(scoped_ptr<EventRouter> event_router);
EventRouter* event_router() override;
Blacklist* blacklist() override;
ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override;
QuotaService* quota_service() override;
......@@ -92,7 +91,6 @@ class TestExtensionSystem : public ExtensionSystem {
// A pointer to the TestingValueStore owned by |state_store_|.
TestingValueStore* value_store_;
ScopedVector<DeclarativeUserScriptMaster> declarative_user_script_masters_;
scoped_ptr<Blacklist> blacklist_;
scoped_ptr<ManagementPolicy> management_policy_;
scoped_ptr<RuntimeData> runtime_data_;
scoped_ptr<ExtensionService> extension_service_;
......
......@@ -496,6 +496,8 @@
'browser/extensions/app_sync_data.h',
'browser/extensions/blacklist.cc',
'browser/extensions/blacklist.h',
'browser/extensions/blacklist_factory.cc',
'browser/extensions/blacklist_factory.h',
'browser/extensions/blacklist_state_fetcher.cc',
'browser/extensions/blacklist_state_fetcher.h',
'browser/extensions/blob_reader.cc',
......
......@@ -29,7 +29,6 @@ class BrowserContext;
namespace extensions {
class Blacklist;
class ContentVerifier;
class DeclarativeUserScriptMaster;
class ErrorConsole;
......@@ -93,9 +92,6 @@ class ExtensionSystem : public KeyedService {
// The EventRouter is created at startup.
virtual EventRouter* event_router() = 0;
// The blacklist is created at startup.
virtual Blacklist* blacklist() = 0;
// The ErrorConsole is created at startup.
virtual ErrorConsole* error_console() = 0;
......
......@@ -58,10 +58,6 @@ EventRouter* MockExtensionSystem::event_router() {
return NULL;
}
Blacklist* MockExtensionSystem::blacklist() {
return NULL;
}
ErrorConsole* MockExtensionSystem::error_console() {
return NULL;
}
......
......@@ -36,7 +36,6 @@ class MockExtensionSystem : public ExtensionSystem {
InfoMap* info_map() override;
LazyBackgroundTaskQueue* lazy_background_task_queue() override;
EventRouter* event_router() override;
Blacklist* blacklist() override;
ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override;
QuotaService* quota_service() override;
......
......@@ -141,10 +141,6 @@ EventRouter* ShellExtensionSystem::event_router() {
return event_router_.get();
}
Blacklist* ShellExtensionSystem::blacklist() {
return NULL;
}
ErrorConsole* ShellExtensionSystem::error_console() {
return NULL;
}
......
......@@ -62,7 +62,6 @@ class ShellExtensionSystem : public ExtensionSystem {
InfoMap* info_map() override;
LazyBackgroundTaskQueue* lazy_background_task_queue() override;
EventRouter* event_router() override;
Blacklist* blacklist() override;
ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override;
QuotaService* quota_service() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment