Commit 22114a38 authored by reillyg's avatar reillyg Committed by Commit bot

Split WarningService from ExtensionSystem.

This patch removes both the WarningService accessors from
ExtensionSystem and also the ExtensionWarningBadgeService instance
that it created as this can be built automatically for every
BrowserContext simply by declaring so in its new factory.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#302438}
parent 382af461
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "chrome/browser/extensions/extension_storage_monitor_factory.h" #include "chrome/browser/extensions/extension_storage_monitor_factory.h"
#include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/extension_toolbar_model_factory.h" #include "chrome/browser/extensions/extension_toolbar_model_factory.h"
#include "chrome/browser/extensions/extension_warning_badge_service_factory.h"
#include "chrome/browser/extensions/extension_web_ui_override_registrar.h" #include "chrome/browser/extensions/extension_web_ui_override_registrar.h"
#include "chrome/browser/extensions/install_tracker_factory.h" #include "chrome/browser/extensions/install_tracker_factory.h"
#include "chrome/browser/extensions/menu_manager_factory.h" #include "chrome/browser/extensions/menu_manager_factory.h"
...@@ -103,6 +104,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -103,6 +104,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::ExtensionStorageMonitorFactory::GetInstance(); extensions::ExtensionStorageMonitorFactory::GetInstance();
extensions::ExtensionSystemFactory::GetInstance(); extensions::ExtensionSystemFactory::GetInstance();
extensions::ExtensionToolbarModelFactory::GetInstance(); extensions::ExtensionToolbarModelFactory::GetInstance();
extensions::ExtensionWarningBadgeServiceFactory::GetInstance();
extensions::ExtensionWebUIOverrideRegistrar::GetFactoryInstance(); extensions::ExtensionWebUIOverrideRegistrar::GetFactoryInstance();
extensions::FeedbackPrivateAPI::GetFactoryInstance(); extensions::FeedbackPrivateAPI::GetFactoryInstance();
extensions::FontSettingsAPI::GetFactoryInstance(); extensions::FontSettingsAPI::GetFactoryInstance();
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_warning_badge_service.h"
#include "chrome/browser/extensions/install_verifier.h" #include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/extensions/navigation_observer.h" #include "chrome/browser/extensions/navigation_observer.h"
#include "chrome/browser/extensions/shared_module_service.h" #include "chrome/browser/extensions/shared_module_service.h"
...@@ -55,8 +54,6 @@ ...@@ -55,8 +54,6 @@
#include "extensions/browser/quota_service.h" #include "extensions/browser/quota_service.h"
#include "extensions/browser/runtime_data.h" #include "extensions/browser/runtime_data.h"
#include "extensions/browser/state_store.h" #include "extensions/browser/state_store.h"
#include "extensions/browser/warning_service.h"
#include "extensions/browser/warning_set.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h" #include "extensions/common/extension_urls.h"
...@@ -383,11 +380,6 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { ...@@ -383,11 +380,6 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
// Make the chrome://extension-icon/ resource available. // Make the chrome://extension-icon/ resource available.
content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_)); content::URLDataSource::Add(profile_, new ExtensionIconSource(profile_));
warning_service_.reset(new WarningService(profile_));
extension_warning_badge_service_.reset(
new ExtensionWarningBadgeService(profile_));
warning_service_->AddObserver(
extension_warning_badge_service_.get());
error_console_.reset(new ErrorConsole(profile_)); error_console_.reset(new ErrorConsole(profile_));
quota_service_.reset(new QuotaService); quota_service_.reset(new QuotaService);
...@@ -411,10 +403,6 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { ...@@ -411,10 +403,6 @@ void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) {
} }
void ExtensionSystemImpl::Shared::Shutdown() { void ExtensionSystemImpl::Shared::Shutdown() {
if (warning_service_) {
warning_service_->RemoveObserver(
extension_warning_badge_service_.get());
}
if (content_verifier_.get()) if (content_verifier_.get())
content_verifier_->Shutdown(); content_verifier_->Shutdown();
if (extension_service_) if (extension_service_)
...@@ -461,10 +449,6 @@ EventRouter* ExtensionSystemImpl::Shared::event_router() { ...@@ -461,10 +449,6 @@ EventRouter* ExtensionSystemImpl::Shared::event_router() {
return event_router_.get(); return event_router_.get();
} }
WarningService* ExtensionSystemImpl::Shared::warning_service() {
return warning_service_.get();
}
Blacklist* ExtensionSystemImpl::Shared::blacklist() { Blacklist* ExtensionSystemImpl::Shared::blacklist() {
return blacklist_.get(); return blacklist_.get();
} }
...@@ -569,10 +553,6 @@ EventRouter* ExtensionSystemImpl::event_router() { ...@@ -569,10 +553,6 @@ EventRouter* ExtensionSystemImpl::event_router() {
return shared_->event_router(); return shared_->event_router();
} }
WarningService* ExtensionSystemImpl::warning_service() {
return shared_->warning_service();
}
Blacklist* ExtensionSystemImpl::blacklist() { Blacklist* ExtensionSystemImpl::blacklist() {
return shared_->blacklist(); return shared_->blacklist();
} }
......
...@@ -16,7 +16,6 @@ namespace extensions { ...@@ -16,7 +16,6 @@ namespace extensions {
class ContentVerifier; class ContentVerifier;
class DeclarativeUserScriptMaster; class DeclarativeUserScriptMaster;
class ExtensionSystemSharedFactory; class ExtensionSystemSharedFactory;
class ExtensionWarningBadgeService;
class NavigationObserver; class NavigationObserver;
class SharedUserScriptMaster; class SharedUserScriptMaster;
class StateStoreNotificationObserver; class StateStoreNotificationObserver;
...@@ -46,7 +45,6 @@ class ExtensionSystemImpl : public ExtensionSystem { ...@@ -46,7 +45,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
LazyBackgroundTaskQueue* lazy_background_task_queue() override; // shared LazyBackgroundTaskQueue* lazy_background_task_queue() override; // shared
InfoMap* info_map() override; // shared InfoMap* info_map() override; // shared
EventRouter* event_router() override; // shared EventRouter* event_router() override; // shared
WarningService* warning_service() override;
Blacklist* blacklist() override; // shared Blacklist* blacklist() override; // shared
ErrorConsole* error_console() override; ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override; InstallVerifier* install_verifier() override;
...@@ -96,7 +94,6 @@ class ExtensionSystemImpl : public ExtensionSystem { ...@@ -96,7 +94,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
InfoMap* info_map(); InfoMap* info_map();
LazyBackgroundTaskQueue* lazy_background_task_queue(); LazyBackgroundTaskQueue* lazy_background_task_queue();
EventRouter* event_router(); EventRouter* event_router();
WarningService* warning_service();
ErrorConsole* error_console(); ErrorConsole* error_console();
InstallVerifier* install_verifier(); InstallVerifier* install_verifier();
QuotaService* quota_service(); QuotaService* quota_service();
...@@ -134,8 +131,6 @@ class ExtensionSystemImpl : public ExtensionSystem { ...@@ -134,8 +131,6 @@ class ExtensionSystemImpl : public ExtensionSystem {
scoped_ptr<ManagementPolicy> management_policy_; scoped_ptr<ManagementPolicy> management_policy_;
// extension_info_map_ needs to outlive process_manager_. // extension_info_map_ needs to outlive process_manager_.
scoped_refptr<InfoMap> extension_info_map_; scoped_refptr<InfoMap> extension_info_map_;
scoped_ptr<WarningService> warning_service_;
scoped_ptr<ExtensionWarningBadgeService> extension_warning_badge_service_;
scoped_ptr<ErrorConsole> error_console_; scoped_ptr<ErrorConsole> error_console_;
scoped_ptr<InstallVerifier> install_verifier_; scoped_ptr<InstallVerifier> install_verifier_;
scoped_ptr<QuotaService> quota_service_; scoped_ptr<QuotaService> quota_service_;
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_warning_badge_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/global_error/global_error.h" #include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "extensions/browser/extension_system.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace extensions { namespace extensions {
...@@ -87,14 +87,20 @@ int ErrorBadge::GetMenuItemCommandID() { ...@@ -87,14 +87,20 @@ int ErrorBadge::GetMenuItemCommandID() {
} // namespace } // namespace
ExtensionWarningBadgeService::ExtensionWarningBadgeService(Profile* profile) ExtensionWarningBadgeService::ExtensionWarningBadgeService(Profile* profile)
: profile_(profile) { : profile_(profile), warning_service_observer_(this) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
warning_service_observer_.Add(WarningService::Get(profile_));
} }
ExtensionWarningBadgeService::~ExtensionWarningBadgeService() {} ExtensionWarningBadgeService::~ExtensionWarningBadgeService() {}
// static
ExtensionWarningBadgeService* ExtensionWarningBadgeService::Get(
content::BrowserContext* context) {
return ExtensionWarningBadgeServiceFactory::GetForBrowserContext(context);
}
void ExtensionWarningBadgeService::SuppressCurrentWarnings() { void ExtensionWarningBadgeService::SuppressCurrentWarnings() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
size_t old_size = suppressed_warnings_.size(); size_t old_size = suppressed_warnings_.size();
...@@ -107,7 +113,7 @@ void ExtensionWarningBadgeService::SuppressCurrentWarnings() { ...@@ -107,7 +113,7 @@ void ExtensionWarningBadgeService::SuppressCurrentWarnings() {
} }
const WarningSet& ExtensionWarningBadgeService::GetCurrentWarnings() const { const WarningSet& ExtensionWarningBadgeService::GetCurrentWarnings() const {
return ExtensionSystem::Get(profile_)->warning_service()->warnings(); return WarningService::Get(profile_)->warnings();
} }
void ExtensionWarningBadgeService::ExtensionWarningsChanged() { void ExtensionWarningBadgeService::ExtensionWarningsChanged() {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/warning_service.h" #include "extensions/browser/warning_service.h"
#include "extensions/browser/warning_set.h" #include "extensions/browser/warning_set.h"
...@@ -18,12 +19,15 @@ namespace extensions { ...@@ -18,12 +19,15 @@ namespace extensions {
// A service that is responsible for showing an extension warning badge on the // A service that is responsible for showing an extension warning badge on the
// wrench menu. // wrench menu.
class ExtensionWarningBadgeService : public WarningService::Observer, class ExtensionWarningBadgeService : public KeyedService,
public WarningService::Observer,
public base::NonThreadSafe { public base::NonThreadSafe {
public: public:
explicit ExtensionWarningBadgeService(Profile* profile); explicit ExtensionWarningBadgeService(Profile* profile);
virtual ~ExtensionWarningBadgeService(); virtual ~ExtensionWarningBadgeService();
static ExtensionWarningBadgeService* Get(content::BrowserContext* context);
// Black lists all currently active extension warnings, so that they do not // Black lists all currently active extension warnings, so that they do not
// trigger a warning badge again for the life-time of the browsing session. // trigger a warning badge again for the life-time of the browsing session.
void SuppressCurrentWarnings(); void SuppressCurrentWarnings();
...@@ -41,6 +45,9 @@ class ExtensionWarningBadgeService : public WarningService::Observer, ...@@ -41,6 +45,9 @@ class ExtensionWarningBadgeService : public WarningService::Observer,
Profile* profile_; Profile* profile_;
ScopedObserver<WarningService, WarningService::Observer>
warning_service_observer_;
// Warnings that do not trigger a badge on the wrench menu. // Warnings that do not trigger a badge on the wrench menu.
WarningSet suppressed_warnings_; WarningSet suppressed_warnings_;
......
// 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/extension_warning_badge_service_factory.h"
#include "chrome/browser/extensions/extension_warning_badge_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/warning_service_factory.h"
using content::BrowserContext;
namespace extensions {
// static
ExtensionWarningBadgeService*
ExtensionWarningBadgeServiceFactory::GetForBrowserContext(
BrowserContext* context) {
return static_cast<ExtensionWarningBadgeService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
ExtensionWarningBadgeServiceFactory*
ExtensionWarningBadgeServiceFactory::GetInstance() {
return Singleton<ExtensionWarningBadgeServiceFactory>::get();
}
ExtensionWarningBadgeServiceFactory::ExtensionWarningBadgeServiceFactory()
: BrowserContextKeyedServiceFactory(
"ExtensionWarningBadgeService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(WarningServiceFactory::GetInstance());
}
ExtensionWarningBadgeServiceFactory::~ExtensionWarningBadgeServiceFactory() {
}
KeyedService* ExtensionWarningBadgeServiceFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
return new ExtensionWarningBadgeService(static_cast<Profile*>(context));
}
BrowserContext* ExtensionWarningBadgeServiceFactory::GetBrowserContextToUse(
BrowserContext* context) const {
// Redirected in incognito.
return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
}
bool ExtensionWarningBadgeServiceFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
} // 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_EXTENSION_WARNING_BADGE_SERVICE_FACTORY_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_BADGE_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace extensions {
class ExtensionWarningBadgeService;
class ExtensionWarningBadgeServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static ExtensionWarningBadgeService* GetForBrowserContext(
content::BrowserContext* context);
static ExtensionWarningBadgeServiceFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<ExtensionWarningBadgeServiceFactory>;
ExtensionWarningBadgeServiceFactory();
~ExtensionWarningBadgeServiceFactory() override;
// BrowserContextKeyedServiceFactory implementation
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
DISALLOW_COPY_AND_ASSIGN(ExtensionWarningBadgeServiceFactory);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_BADGE_SERVICE_FACTORY_H_
...@@ -146,10 +146,6 @@ void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) { ...@@ -146,10 +146,6 @@ void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) {
EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); } EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); }
WarningService* TestExtensionSystem::warning_service() {
return NULL;
}
Blacklist* TestExtensionSystem::blacklist() { Blacklist* TestExtensionSystem::blacklist() {
return blacklist_.get(); return blacklist_.get();
} }
......
...@@ -66,7 +66,6 @@ class TestExtensionSystem : public ExtensionSystem { ...@@ -66,7 +66,6 @@ class TestExtensionSystem : public ExtensionSystem {
LazyBackgroundTaskQueue* lazy_background_task_queue() override; LazyBackgroundTaskQueue* lazy_background_task_queue() override;
void SetEventRouter(scoped_ptr<EventRouter> event_router); void SetEventRouter(scoped_ptr<EventRouter> event_router);
EventRouter* event_router() override; EventRouter* event_router() override;
WarningService* warning_service() override;
Blacklist* blacklist() override; Blacklist* blacklist() override;
ErrorConsole* error_console() override; ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override; InstallVerifier* install_verifier() override;
......
...@@ -884,7 +884,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData( ...@@ -884,7 +884,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
// Add the extensions to the results structure. // Add the extensions to the results structure.
base::ListValue* extensions_list = new base::ListValue(); base::ListValue* extensions_list = new base::ListValue();
WarningService* warnings = ExtensionSystem::Get(profile)->warning_service(); WarningService* warnings = WarningService::Get(profile);
ExtensionRegistry* registry = ExtensionRegistry::Get(profile); ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
const ExtensionSet& enabled_set = registry->enabled_extensions(); const ExtensionSet& enabled_set = registry->enabled_extensions();
...@@ -1355,8 +1355,7 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() { ...@@ -1355,8 +1355,7 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() {
content::WebContentsObserver::Observe(web_ui()->GetWebContents()); content::WebContentsObserver::Observe(web_ui()->GetWebContents());
warning_service_observer_.Add( warning_service_observer_.Add(WarningService::Get(profile));
ExtensionSystem::Get(profile)->warning_service());
error_console_observer_.Add(ErrorConsole::Get(profile)); error_console_observer_.Add(ErrorConsole::Get(profile));
......
...@@ -664,6 +664,8 @@ ...@@ -664,6 +664,8 @@
'browser/extensions/extension_view_host_mac.mm', 'browser/extensions/extension_view_host_mac.mm',
'browser/extensions/extension_warning_badge_service.cc', 'browser/extensions/extension_warning_badge_service.cc',
'browser/extensions/extension_warning_badge_service.h', 'browser/extensions/extension_warning_badge_service.h',
'browser/extensions/extension_warning_badge_service_factory.cc',
'browser/extensions/extension_warning_badge_service_factory.h',
'browser/extensions/extension_web_ui.cc', 'browser/extensions/extension_web_ui.cc',
'browser/extensions/extension_web_ui.h', 'browser/extensions/extension_web_ui.h',
'browser/extensions/extension_web_ui_override_registrar.cc', 'browser/extensions/extension_web_ui_override_registrar.cc',
......
...@@ -480,6 +480,8 @@ source_set("browser") { ...@@ -480,6 +480,8 @@ source_set("browser") {
"view_type_utils.h", "view_type_utils.h",
"warning_service.cc", "warning_service.cc",
"warning_service.h", "warning_service.h",
"warning_service_factory.cc",
"warning_service_factory.h",
"warning_set.cc", "warning_set.cc",
"warning_set.h", "warning_set.h",
] ]
......
...@@ -41,12 +41,10 @@ class InstallVerifier; ...@@ -41,12 +41,10 @@ class InstallVerifier;
class LazyBackgroundTaskQueue; class LazyBackgroundTaskQueue;
class ManagementPolicy; class ManagementPolicy;
class OneShotEvent; class OneShotEvent;
class ProcessManager;
class QuotaService; class QuotaService;
class RuntimeData; class RuntimeData;
class SharedUserScriptMaster; class SharedUserScriptMaster;
class StateStore; class StateStore;
class WarningService;
// ExtensionSystem manages the lifetime of many of the services used by the // ExtensionSystem manages the lifetime of many of the services used by the
// extensions and apps system, and it handles startup and shutdown as needed. // extensions and apps system, and it handles startup and shutdown as needed.
...@@ -95,9 +93,6 @@ class ExtensionSystem : public KeyedService { ...@@ -95,9 +93,6 @@ class ExtensionSystem : public KeyedService {
// The EventRouter is created at startup. // The EventRouter is created at startup.
virtual EventRouter* event_router() = 0; virtual EventRouter* event_router() = 0;
// The WarningService is created at startup.
virtual WarningService* warning_service() = 0;
// The blacklist is created at startup. // The blacklist is created at startup.
virtual Blacklist* blacklist() = 0; virtual Blacklist* blacklist() = 0;
......
...@@ -58,10 +58,6 @@ EventRouter* MockExtensionSystem::event_router() { ...@@ -58,10 +58,6 @@ EventRouter* MockExtensionSystem::event_router() {
return NULL; return NULL;
} }
WarningService* MockExtensionSystem::warning_service() {
return NULL;
}
Blacklist* MockExtensionSystem::blacklist() { Blacklist* MockExtensionSystem::blacklist() {
return NULL; return NULL;
} }
......
...@@ -36,7 +36,6 @@ class MockExtensionSystem : public ExtensionSystem { ...@@ -36,7 +36,6 @@ class MockExtensionSystem : public ExtensionSystem {
InfoMap* info_map() override; InfoMap* info_map() override;
LazyBackgroundTaskQueue* lazy_background_task_queue() override; LazyBackgroundTaskQueue* lazy_background_task_queue() override;
EventRouter* event_router() override; EventRouter* event_router() override;
WarningService* warning_service() override;
Blacklist* blacklist() override; Blacklist* blacklist() override;
ErrorConsole* error_console() override; ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override; InstallVerifier* install_verifier() override;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/warning_service_factory.h"
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -25,6 +25,11 @@ WarningService::WarningService(content::BrowserContext* browser_context) ...@@ -25,6 +25,11 @@ WarningService::WarningService(content::BrowserContext* browser_context)
WarningService::~WarningService() {} WarningService::~WarningService() {}
// static
WarningService* WarningService::Get(content::BrowserContext* browser_context) {
return WarningServiceFactory::GetForBrowserContext(browser_context);
}
void WarningService::ClearWarnings( void WarningService::ClearWarnings(
const std::set<Warning::WarningType>& types) { const std::set<Warning::WarningType>& types) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
...@@ -95,8 +100,7 @@ void WarningService::NotifyWarningsOnUI( ...@@ -95,8 +100,7 @@ void WarningService::NotifyWarningsOnUI(
return; return;
} }
WarningService* warning_service = WarningService* warning_service = WarningService::Get(browser_context);
ExtensionSystem::Get(browser_context)->warning_service();
warning_service->AddWarnings(warnings); warning_service->AddWarnings(warnings);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/warning_set.h" #include "extensions/browser/warning_set.h"
...@@ -31,7 +32,8 @@ class ExtensionRegistry; ...@@ -31,7 +32,8 @@ class ExtensionRegistry;
// conflicting modifications of network requests by extensions, slow extensions, // conflicting modifications of network requests by extensions, slow extensions,
// etc.) trigger a warning badge in the UI and and provide means to resolve // etc.) trigger a warning badge in the UI and and provide means to resolve
// them. This class must be used on the UI thread only. // them. This class must be used on the UI thread only.
class WarningService : public ExtensionRegistryObserver, class WarningService : public KeyedService,
public ExtensionRegistryObserver,
public base::NonThreadSafe { public base::NonThreadSafe {
public: public:
class Observer { class Observer {
...@@ -44,6 +46,10 @@ class WarningService : public ExtensionRegistryObserver, ...@@ -44,6 +46,10 @@ class WarningService : public ExtensionRegistryObserver,
explicit WarningService(content::BrowserContext* browser_context); explicit WarningService(content::BrowserContext* browser_context);
~WarningService() override; ~WarningService() override;
// Get the instance of the WarningService for |browser_context|.
// Redirected in incognito.
static WarningService* Get(content::BrowserContext* browser_context);
// Clears all warnings of types contained in |types| and notifies observers // Clears all warnings of types contained in |types| and notifies observers
// of the changed warnings. // of the changed warnings.
void ClearWarnings(const std::set<Warning::WarningType>& types); void ClearWarnings(const std::set<Warning::WarningType>& types);
......
// 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 "extensions/browser/warning_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/warning_service.h"
using content::BrowserContext;
namespace extensions {
// static
WarningService* WarningServiceFactory::GetForBrowserContext(
BrowserContext* context) {
return static_cast<WarningService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
WarningServiceFactory* WarningServiceFactory::GetInstance() {
return Singleton<WarningServiceFactory>::get();
}
WarningServiceFactory::WarningServiceFactory()
: BrowserContextKeyedServiceFactory(
"WarningService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ExtensionRegistryFactory::GetInstance());
}
WarningServiceFactory::~WarningServiceFactory() {
}
KeyedService* WarningServiceFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
return new WarningService(context);
}
BrowserContext* WarningServiceFactory::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 EXTENSIONS_BROWSER_WARNING_SERVICE_FACTORY_H_
#define EXTENSIONS_BROWSER_WARNING_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace extensions {
class WarningService;
class WarningServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static WarningService* GetForBrowserContext(content::BrowserContext* context);
static WarningServiceFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<WarningServiceFactory>;
WarningServiceFactory();
~WarningServiceFactory() override;
// BrowserContextKeyedServiceFactory implementation
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(WarningServiceFactory);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_WARNING_SERVICE_FACTORY_H_
...@@ -758,6 +758,8 @@ ...@@ -758,6 +758,8 @@
'browser/view_type_utils.h', 'browser/view_type_utils.h',
'browser/warning_service.cc', 'browser/warning_service.cc',
'browser/warning_service.h', 'browser/warning_service.h',
'browser/warning_service_factory.cc',
'browser/warning_service_factory.h',
'browser/warning_set.cc', 'browser/warning_set.cc',
'browser/warning_set.h', 'browser/warning_set.h',
], ],
......
...@@ -141,10 +141,6 @@ EventRouter* ShellExtensionSystem::event_router() { ...@@ -141,10 +141,6 @@ EventRouter* ShellExtensionSystem::event_router() {
return event_router_.get(); return event_router_.get();
} }
WarningService* ShellExtensionSystem::warning_service() {
return NULL;
}
Blacklist* ShellExtensionSystem::blacklist() { Blacklist* ShellExtensionSystem::blacklist() {
return NULL; return NULL;
} }
......
...@@ -62,7 +62,6 @@ class ShellExtensionSystem : public ExtensionSystem { ...@@ -62,7 +62,6 @@ class ShellExtensionSystem : public ExtensionSystem {
InfoMap* info_map() override; InfoMap* info_map() override;
LazyBackgroundTaskQueue* lazy_background_task_queue() override; LazyBackgroundTaskQueue* lazy_background_task_queue() override;
EventRouter* event_router() override; EventRouter* event_router() override;
WarningService* warning_service() override;
Blacklist* blacklist() override; Blacklist* blacklist() override;
ErrorConsole* error_console() override; ErrorConsole* error_console() override;
InstallVerifier* install_verifier() override; InstallVerifier* install_verifier() 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