diff options
author | juncai <juncai@chromium.org> | 2015-06-03 17:14:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-04 00:14:37 +0000 |
commit | cf52333148db8abf73adbb739480edaca3646fe5 (patch) | |
tree | 0c50247857c81587682dba497496abf0921093d7 /extensions | |
parent | b6e2e1cf2ab03954db07966f4bfd9f03763f6084 (diff) | |
download | chromium_src-cf52333148db8abf73adbb739480edaca3646fe5.zip chromium_src-cf52333148db8abf73adbb739480edaca3646fe5.tar.gz chromium_src-cf52333148db8abf73adbb739480edaca3646fe5.tar.bz2 |
Extract EventRouter from ExtensionSystem.
This patch removes event_router accessor from ExtensionSystem.
EventRouter is now a browser context keyed service.
BUG=496281
Review URL: https://codereview.chromium.org/1148983004
Cr-Commit-Position: refs/heads/master@{#332745}
Diffstat (limited to 'extensions')
21 files changed, 161 insertions, 128 deletions
diff --git a/extensions/browser/api/app_runtime/app_runtime_api.cc b/extensions/browser/api/app_runtime/app_runtime_api.cc index fba27b9..e606dbc 100644 --- a/extensions/browser/api/app_runtime/app_runtime_api.cc +++ b/extensions/browser/api/app_runtime/app_runtime_api.cc @@ -9,7 +9,6 @@ #include "base/values.h" #include "extensions/browser/event_router.h" #include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_system.h" #include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/granted_file_entry.h" #include "extensions/common/api/app_runtime.h" @@ -31,12 +30,11 @@ void DispatchOnEmbedRequestedEventImpl( content::BrowserContext* context) { scoped_ptr<base::ListValue> args(new base::ListValue()); args->Append(app_embedding_request_data.release()); - ExtensionSystem* system = ExtensionSystem::Get(context); scoped_ptr<Event> event( new Event(app_runtime::OnEmbedRequested::kEventName, args.Pass())); event->restrict_to_browser_context = context; - system->event_router()->DispatchEventWithLazyListener(extension_id, - event.Pass()); + EventRouter::Get(context) + ->DispatchEventWithLazyListener(extension_id, event.Pass()); ExtensionPrefs::Get(context) ->SetLastLaunchTime(extension_id, base::Time::Now()); diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc index 6e23721..72dacf7 100644 --- a/extensions/browser/api/runtime/runtime_api.cc +++ b/extensions/browser/api/runtime/runtime_api.cc @@ -107,7 +107,8 @@ void DispatchOnStartupEventImpl(BrowserContext* browser_context, scoped_ptr<base::ListValue> event_args(new base::ListValue()); scoped_ptr<Event> event( new Event(runtime::OnStartup::kEventName, event_args.Pass())); - system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); + EventRouter::Get(browser_context) + ->DispatchEventToExtension(extension_id, event.Pass()); } void SetUninstallURL(ExtensionPrefs* prefs, @@ -304,11 +305,11 @@ void RuntimeEventRouter::DispatchOnInstalledEvent( } else { info->SetString(kInstallReason, kInstallReasonInstall); } - DCHECK(system->event_router()); + EventRouter* event_router = EventRouter::Get(context); + DCHECK(event_router); scoped_ptr<Event> event( new Event(runtime::OnInstalled::kEventName, event_args.Pass())); - system->event_router()->DispatchEventWithLazyListener(extension_id, - event.Pass()); + event_router->DispatchEventWithLazyListener(extension_id, event.Pass()); if (old_version.IsValid()) { const Extension* extension = @@ -328,8 +329,8 @@ void RuntimeEventRouter::DispatchOnInstalledEvent( sm_info->SetString(kInstallId, extension_id); scoped_ptr<Event> sm_event( new Event(runtime::OnInstalled::kEventName, sm_event_args.Pass())); - system->event_router()->DispatchEventWithLazyListener((*i)->id(), - sm_event.Pass()); + event_router->DispatchEventWithLazyListener((*i)->id(), + sm_event.Pass()); } } } @@ -346,10 +347,11 @@ void RuntimeEventRouter::DispatchOnUpdateAvailableEvent( scoped_ptr<base::ListValue> args(new base::ListValue); args->Append(manifest->DeepCopy()); - DCHECK(system->event_router()); + EventRouter* event_router = EventRouter::Get(context); + DCHECK(event_router); scoped_ptr<Event> event( new Event(runtime::OnUpdateAvailable::kEventName, args.Pass())); - system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); + event_router->DispatchEventToExtension(extension_id, event.Pass()); } // static @@ -360,10 +362,11 @@ void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( return; scoped_ptr<base::ListValue> args(new base::ListValue); - DCHECK(system->event_router()); + EventRouter* event_router = EventRouter::Get(context); + DCHECK(event_router); scoped_ptr<Event> event( new Event(runtime::OnBrowserUpdateAvailable::kEventName, args.Pass())); - system->event_router()->BroadcastEvent(event.Pass()); + event_router->BroadcastEvent(event.Pass()); } // static @@ -378,9 +381,9 @@ void RuntimeEventRouter::DispatchOnRestartRequiredEvent( scoped_ptr<Event> event( new Event(runtime::OnRestartRequired::kEventName, core_api::runtime::OnRestartRequired::Create(reason))); - - DCHECK(system->event_router()); - system->event_router()->DispatchEventToExtension(app_id, event.Pass()); + EventRouter* event_router = EventRouter::Get(context); + DCHECK(event_router); + event_router->DispatchEventToExtension(app_id, event.Pass()); } // static diff --git a/extensions/browser/api/storage/settings_test_util.cc b/extensions/browser/api/storage/settings_test_util.cc index b5142f0..c3dc4a5 100644 --- a/extensions/browser/api/storage/settings_test_util.cc +++ b/extensions/browser/api/storage/settings_test_util.cc @@ -118,27 +118,6 @@ scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( return extension; } -// MockExtensionSystemWithEventRouter - -MockExtensionSystemWithEventRouter::MockExtensionSystemWithEventRouter( - content::BrowserContext* context) - : MockExtensionSystem(context) { -} - -MockExtensionSystemWithEventRouter::~MockExtensionSystemWithEventRouter() { -} - -KeyedService* MockExtensionSystemWithEventRouter::Build( - content::BrowserContext* context) { - return new MockExtensionSystemWithEventRouter(context); -} - -EventRouter* MockExtensionSystemWithEventRouter::event_router() { - if (!event_router_.get()) - event_router_.reset(new EventRouter(browser_context(), NULL)); - return event_router_.get(); -} - // ScopedSettingsFactory ScopedSettingsStorageFactory::ScopedSettingsStorageFactory() {} diff --git a/extensions/browser/api/storage/settings_test_util.h b/extensions/browser/api/storage/settings_test_util.h index 283fc46..0b23f60 100644 --- a/extensions/browser/api/storage/settings_test_util.h +++ b/extensions/browser/api/storage/settings_test_util.h @@ -56,25 +56,6 @@ scoped_refptr<const Extension> AddExtensionWithIdAndPermissions( Manifest::Type type, const std::set<std::string>& permissions); -// A MockExtensionSystem to serve an EventRouter. -// NOTE: New code should prefer using MockExtensionSystem directly. -class MockExtensionSystemWithEventRouter : public MockExtensionSystem { - public: - explicit MockExtensionSystemWithEventRouter(content::BrowserContext* context); - ~MockExtensionSystemWithEventRouter() override; - - // Factory method for SetTestingFactoryAndUse. - static KeyedService* Build(content::BrowserContext* context); - - // MockExtensionSystem overrides: - EventRouter* event_router() override; - - private: - scoped_ptr<EventRouter> event_router_; - - DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemWithEventRouter); -}; - // SettingsStorageFactory which acts as a wrapper for other factories. class ScopedSettingsStorageFactory : public SettingsStorageFactory { public: diff --git a/extensions/browser/api/storage/storage_api_unittest.cc b/extensions/browser/api/storage/storage_api_unittest.cc index a0845d9..0d2dc4d 100644 --- a/extensions/browser/api/storage/storage_api_unittest.cc +++ b/extensions/browser/api/storage/storage_api_unittest.cc @@ -15,9 +15,7 @@ #include "extensions/browser/api/storage/storage_frontend.h" #include "extensions/browser/api_unittest.h" #include "extensions/browser/event_router.h" -#include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_system.h" -#include "extensions/browser/mock_extension_system.h" +#include "extensions/browser/event_router_factory.h" #include "extensions/browser/test_extensions_browser_client.h" #include "extensions/browser/value_store/leveldb_value_store.h" #include "extensions/browser/value_store/value_store.h" @@ -37,6 +35,10 @@ KeyedService* CreateStorageFrontendForTesting( context); } +KeyedService* BuildEventRouter(content::BrowserContext* profile) { + return new extensions::EventRouter(profile, nullptr); +} + } // namespace class StorageApiUnittest : public ApiUnitTest { @@ -76,10 +78,8 @@ class StorageApiUnittest : public ApiUnitTest { }; TEST_F(StorageApiUnittest, RestoreCorruptedStorage) { - EventRouter event_router(browser_context(), nullptr); - MockExtensionSystem* system = static_cast<MockExtensionSystem*>( - ExtensionSystem::Get(browser_context())); - system->set_event_router(&event_router); + EventRouterFactory::GetInstance()->SetTestingFactory(browser_context(), + &BuildEventRouter); // Ensure a StorageFrontend can be created on demand. The StorageFrontend // will be owned by the KeyedService system. diff --git a/extensions/browser/browser_context_keyed_service_factories.cc b/extensions/browser/browser_context_keyed_service_factories.cc index 3eb3106..ee2a901 100644 --- a/extensions/browser/browser_context_keyed_service_factories.cc +++ b/extensions/browser/browser_context_keyed_service_factories.cc @@ -27,6 +27,7 @@ #include "extensions/browser/api/usb/usb_guid_map.h" #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" #include "extensions/browser/api/webcam_private/webcam_private_api.h" +#include "extensions/browser/event_router_factory.h" #include "extensions/browser/extension_message_filter.h" #include "extensions/browser/extension_prefs_factory.h" #include "extensions/browser/process_manager_factory.h" @@ -49,6 +50,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { core_api::TCPServerSocketEventDispatcher::GetFactoryInstance(); core_api::TCPSocketEventDispatcher::GetFactoryInstance(); core_api::UDPSocketEventDispatcher::GetFactoryInstance(); + EventRouterFactory::GetInstance(); ExtensionMessageFilter::EnsureShutdownNotifierFactoryBuilt(); ExtensionPrefsFactory::GetInstance(); HidDeviceManager::GetFactoryInstance(); diff --git a/extensions/browser/event_router.cc b/extensions/browser/event_router.cc index 6a8cf8d..71a0963 100644 --- a/extensions/browser/event_router.cc +++ b/extensions/browser/event_router.cc @@ -16,6 +16,7 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "extensions/browser/api_activity_monitor.h" +#include "extensions/browser/event_router_factory.h" #include "extensions/browser/extension_host.h" #include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_registry.h" @@ -136,7 +137,7 @@ void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, // static EventRouter* EventRouter::Get(content::BrowserContext* browser_context) { - return ExtensionSystem::Get(browser_context)->event_router(); + return EventRouterFactory::GetForBrowserContext(browser_context); } // static diff --git a/extensions/browser/event_router.h b/extensions/browser/event_router.h index aec74ed..6cd7df6 100644 --- a/extensions/browser/event_router.h +++ b/extensions/browser/event_router.h @@ -17,6 +17,7 @@ #include "base/memory/ref_counted.h" #include "base/scoped_observer.h" #include "base/values.h" +#include "components/keyed_service/core/keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/render_process_host_observer.h" @@ -44,7 +45,8 @@ struct Event; struct EventDispatchInfo; struct EventListenerInfo; -class EventRouter : public content::NotificationObserver, +class EventRouter : public KeyedService, + public content::NotificationObserver, public ExtensionRegistryObserver, public EventListenerMap::Delegate, public content::RenderProcessHostObserver { diff --git a/extensions/browser/event_router_factory.cc b/extensions/browser/event_router_factory.cc new file mode 100644 index 0000000..9dd0125 --- /dev/null +++ b/extensions/browser/event_router_factory.cc @@ -0,0 +1,52 @@ +// Copyright 2015 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/event_router_factory.h" + +#include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "content/public/browser/browser_context.h" +#include "extensions/browser/event_router.h" +#include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_prefs_factory.h" +#include "extensions/browser/extension_registry_factory.h" +#include "extensions/browser/extensions_browser_client.h" + +using content::BrowserContext; + +namespace extensions { + +// static +EventRouter* EventRouterFactory::GetForBrowserContext(BrowserContext* context) { + return static_cast<EventRouter*>( + GetInstance()->GetServiceForBrowserContext(context, true)); +} + +// static +EventRouterFactory* EventRouterFactory::GetInstance() { + return Singleton<EventRouterFactory>::get(); +} + +EventRouterFactory::EventRouterFactory() + : BrowserContextKeyedServiceFactory( + "EventRouter", + BrowserContextDependencyManager::GetInstance()) { + DependsOn(ExtensionRegistryFactory::GetInstance()); + DependsOn(ExtensionPrefsFactory::GetInstance()); +} + +EventRouterFactory::~EventRouterFactory() { +} + +KeyedService* EventRouterFactory::BuildServiceInstanceFor( + BrowserContext* context) const { + return new EventRouter(context, ExtensionPrefs::Get(context)); +} + +BrowserContext* EventRouterFactory::GetBrowserContextToUse( + BrowserContext* context) const { + // Redirected in incognito. + return ExtensionsBrowserClient::Get()->GetOriginalContext(context); +} + +} // namespace extensions diff --git a/extensions/browser/event_router_factory.h b/extensions/browser/event_router_factory.h new file mode 100644 index 0000000..a2ba6ff --- /dev/null +++ b/extensions/browser/event_router_factory.h @@ -0,0 +1,37 @@ +// Copyright 2015 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_EVENT_ROUTER_FACTORY_H_ +#define EXTENSIONS_BROWSER_EVENT_ROUTER_FACTORY_H_ + +#include "base/memory/singleton.h" +#include "components/keyed_service/content/browser_context_keyed_service_factory.h" + +namespace extensions { + +class EventRouter; + +class EventRouterFactory : public BrowserContextKeyedServiceFactory { + public: + static EventRouter* GetForBrowserContext(content::BrowserContext* context); + static EventRouterFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<EventRouterFactory>; + + EventRouterFactory(); + ~EventRouterFactory() override; + + // BrowserContextKeyedServiceFactory implementation + KeyedService* BuildServiceInstanceFor( + content::BrowserContext* context) const override; + content::BrowserContext* GetBrowserContextToUse( + content::BrowserContext* context) const override; + + DISALLOW_COPY_AND_ASSIGN(EventRouterFactory); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_EVENT_ROUTER_FACTORY_H_ diff --git a/extensions/browser/extension_message_filter.cc b/extensions/browser/extension_message_filter.cc index 2a67822..053d8ee 100644 --- a/extensions/browser/extension_message_filter.cc +++ b/extensions/browser/extension_message_filter.cc @@ -11,9 +11,7 @@ #include "content/public/browser/render_process_host.h" #include "extensions/browser/blob_holder.h" #include "extensions/browser/event_router.h" -#include "extensions/browser/extension_system.h" -#include "extensions/browser/extension_system_provider.h" -#include "extensions/browser/extensions_browser_client.h" +#include "extensions/browser/event_router_factory.h" #include "extensions/browser/process_manager.h" #include "extensions/browser/process_manager_factory.h" #include "extensions/common/extension.h" @@ -40,7 +38,7 @@ class ShutdownNotifierFactory ShutdownNotifierFactory() : BrowserContextKeyedServiceShutdownNotifierFactory( "ExtensionMessageFilter") { - DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); + DependsOn(EventRouterFactory::GetInstance()); DependsOn(ProcessManagerFactory::GetInstance()); } ~ShutdownNotifierFactory() override {} @@ -54,7 +52,7 @@ ExtensionMessageFilter::ExtensionMessageFilter(int render_process_id, content::BrowserContext* context) : BrowserMessageFilter(ExtensionMsgStart), render_process_id_(render_process_id), - extension_system_(ExtensionSystem::Get(context)), + event_router_(EventRouter::Get(context)), process_manager_(ProcessManager::Get(context)) { DCHECK_CURRENTLY_ON(BrowserThread::UI); shutdown_notifier_ = @@ -72,7 +70,7 @@ ExtensionMessageFilter::~ExtensionMessageFilter() { } void ExtensionMessageFilter::ShutdownOnUIThread() { - extension_system_ = nullptr; + event_router_ = nullptr; process_manager_ = nullptr; shutdown_notifier_.reset(); } @@ -103,7 +101,7 @@ void ExtensionMessageFilter::OnDestruct() const { bool ExtensionMessageFilter::OnMessageReceived(const IPC::Message& message) { // If we have been shut down already, return. - if (!extension_system_) + if (!event_router_) return true; bool handled = true; @@ -139,14 +137,13 @@ void ExtensionMessageFilter::OnExtensionAddListener( if (!process) return; - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; if (crx_file::id_util::IdIsValid(extension_id)) { - router->AddEventListener(event_name, process, extension_id); + event_router_->AddEventListener(event_name, process, extension_id); } else if (listener_url.is_valid()) { - router->AddEventListenerForURL(event_name, process, listener_url); + event_router_->AddEventListenerForURL(event_name, process, listener_url); } else { NOTREACHED() << "Tried to add an event listener without a valid " << "extension ID nor listener URL"; @@ -161,14 +158,13 @@ void ExtensionMessageFilter::OnExtensionRemoveListener( if (!process) return; - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; if (crx_file::id_util::IdIsValid(extension_id)) { - router->RemoveEventListener(event_name, process, extension_id); + event_router_->RemoveEventListener(event_name, process, extension_id); } else if (listener_url.is_valid()) { - router->RemoveEventListenerForURL(event_name, process, listener_url); + event_router_->RemoveEventListenerForURL(event_name, process, listener_url); } else { NOTREACHED() << "Tried to remove an event listener without a valid " << "extension ID nor listener URL"; @@ -177,20 +173,18 @@ void ExtensionMessageFilter::OnExtensionRemoveListener( void ExtensionMessageFilter::OnExtensionAddLazyListener( const std::string& extension_id, const std::string& event_name) { - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; - router->AddLazyEventListener(event_name, extension_id); + event_router_->AddLazyEventListener(event_name, extension_id); } void ExtensionMessageFilter::OnExtensionRemoveLazyListener( const std::string& extension_id, const std::string& event_name) { - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; - router->RemoveLazyEventListener(event_name, extension_id); + event_router_->RemoveLazyEventListener(event_name, extension_id); } void ExtensionMessageFilter::OnExtensionAddFilteredListener( @@ -202,12 +196,11 @@ void ExtensionMessageFilter::OnExtensionAddFilteredListener( if (!process) return; - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; - router->AddFilteredEventListener( - event_name, process, extension_id, filter, lazy); + event_router_->AddFilteredEventListener(event_name, process, extension_id, + filter, lazy); } void ExtensionMessageFilter::OnExtensionRemoveFilteredListener( @@ -219,12 +212,11 @@ void ExtensionMessageFilter::OnExtensionRemoveFilteredListener( if (!process) return; - EventRouter* router = extension_system_->event_router(); - if (!router) + if (!event_router_) return; - router->RemoveFilteredEventListener( - event_name, process, extension_id, filter, lazy); + event_router_->RemoveFilteredEventListener(event_name, process, extension_id, + filter, lazy); } void ExtensionMessageFilter::OnExtensionShouldSuspendAck( diff --git a/extensions/browser/extension_message_filter.h b/extensions/browser/extension_message_filter.h index b54596e..e0c0e0c 100644 --- a/extensions/browser/extension_message_filter.h +++ b/extensions/browser/extension_message_filter.h @@ -26,7 +26,7 @@ class Size; namespace extensions { -class ExtensionSystem; +class EventRouter; class ProcessManager; // This class filters out incoming extension-specific IPC messages from the @@ -84,7 +84,7 @@ class ExtensionMessageFilter : public content::BrowserMessageFilter { scoped_ptr<KeyedServiceShutdownNotifier::Subscription> shutdown_notifier_; // Owned by the browser context; should only be accessed on the UI thread. - ExtensionSystem* extension_system_; + EventRouter* event_router_; ProcessManager* process_manager_; DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter); diff --git a/extensions/browser/extension_pref_value_map_factory.cc b/extensions/browser/extension_pref_value_map_factory.cc index 6ce78e8..10fdf09 100644 --- a/extensions/browser/extension_pref_value_map_factory.cc +++ b/extensions/browser/extension_pref_value_map_factory.cc @@ -6,6 +6,7 @@ #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "extensions/browser/extension_pref_value_map.h" +#include "extensions/browser/extensions_browser_client.h" ExtensionPrefValueMapFactory::ExtensionPrefValueMapFactory() : BrowserContextKeyedServiceFactory( @@ -32,3 +33,10 @@ KeyedService* ExtensionPrefValueMapFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { return new ExtensionPrefValueMap(); } + +content::BrowserContext* ExtensionPrefValueMapFactory::GetBrowserContextToUse( + content::BrowserContext* context) const { + // Redirected in incognito. + return extensions::ExtensionsBrowserClient::Get()->GetOriginalContext( + context); +} diff --git a/extensions/browser/extension_pref_value_map_factory.h b/extensions/browser/extension_pref_value_map_factory.h index c2630f0..cbe7d5a 100644 --- a/extensions/browser/extension_pref_value_map_factory.h +++ b/extensions/browser/extension_pref_value_map_factory.h @@ -26,6 +26,8 @@ class ExtensionPrefValueMapFactory : public BrowserContextKeyedServiceFactory { KeyedService* BuildServiceInstanceFor( content::BrowserContext* context) const override; + content::BrowserContext* GetBrowserContextToUse( + content::BrowserContext* context) const override; }; #endif // EXTENSIONS_BROWSER_EXTENSION_PREF_VALUE_MAP_FACTORY_H_ diff --git a/extensions/browser/extension_system.h b/extensions/browser/extension_system.h index 600ac3a..099a99f 100644 --- a/extensions/browser/extension_system.h +++ b/extensions/browser/extension_system.h @@ -30,7 +30,6 @@ class BrowserContext; namespace extensions { class ContentVerifier; -class EventRouter; class Extension; class ExtensionSet; class InfoMap; @@ -82,9 +81,6 @@ class ExtensionSystem : public KeyedService { // Returns the IO-thread-accessible extension data. virtual InfoMap* info_map() = 0; - // The EventRouter is created at startup. - virtual EventRouter* event_router() = 0; - // Returns the QuotaService that limits calls to certain extension functions. // Lives on the UI thread. Created at startup. virtual QuotaService* quota_service() = 0; diff --git a/extensions/browser/guest_view/app_view/app_view_guest.cc b/extensions/browser/guest_view/app_view/app_view_guest.cc index 705274d..9c157d0 100644 --- a/extensions/browser/guest_view/app_view/app_view_guest.cc +++ b/extensions/browser/guest_view/app_view/app_view_guest.cc @@ -14,7 +14,6 @@ #include "extensions/browser/event_router.h" #include "extensions/browser/extension_host.h" #include "extensions/browser/extension_registry.h" -#include "extensions/browser/extension_system.h" #include "extensions/browser/guest_view/app_view/app_view_constants.h" #include "extensions/browser/lazy_background_task_queue.h" #include "extensions/browser/process_manager.h" @@ -273,10 +272,10 @@ void AppViewGuest::LaunchAppAndFireEvent( scoped_ptr<base::DictionaryValue> data, const WebContentsCreatedCallback& callback, ExtensionHost* extension_host) { - ExtensionSystem* system = ExtensionSystem::Get(browser_context()); - bool has_event_listener = system->event_router()->ExtensionHasEventListener( - extension_host->extension()->id(), - app_runtime::OnEmbedRequested::kEventName); + bool has_event_listener = EventRouter::Get(browser_context()) + ->ExtensionHasEventListener( + extension_host->extension()->id(), + app_runtime::OnEmbedRequested::kEventName); if (!has_event_listener) { callback.Run(nullptr); return; diff --git a/extensions/browser/mock_extension_system.cc b/extensions/browser/mock_extension_system.cc index 8371c95..845ab9e 100644 --- a/extensions/browser/mock_extension_system.cc +++ b/extensions/browser/mock_extension_system.cc @@ -9,7 +9,7 @@ namespace extensions { MockExtensionSystem::MockExtensionSystem(content::BrowserContext* context) - : browser_context_(context), event_router_(nullptr) { + : browser_context_(context) { } MockExtensionSystem::~MockExtensionSystem() { @@ -46,10 +46,6 @@ InfoMap* MockExtensionSystem::info_map() { return nullptr; } -EventRouter* MockExtensionSystem::event_router() { - return event_router_; -} - QuotaService* MockExtensionSystem::quota_service() { return nullptr; } diff --git a/extensions/browser/mock_extension_system.h b/extensions/browser/mock_extension_system.h index c06b7bc..05ca13f4 100644 --- a/extensions/browser/mock_extension_system.h +++ b/extensions/browser/mock_extension_system.h @@ -25,8 +25,6 @@ class MockExtensionSystem : public ExtensionSystem { content::BrowserContext* browser_context() { return browser_context_; } - void set_event_router(EventRouter* router) { event_router_ = router; } - // ExtensionSystem overrides: void InitForRegularProfile(bool extensions_enabled) override; ExtensionService* extension_service() override; @@ -36,7 +34,6 @@ class MockExtensionSystem : public ExtensionSystem { StateStore* state_store() override; StateStore* rules_store() override; InfoMap* info_map() override; - EventRouter* event_router() override; QuotaService* quota_service() override; const OneShotEvent& ready() const override; ContentVerifier* content_verifier() override; @@ -47,9 +44,6 @@ class MockExtensionSystem : public ExtensionSystem { content::BrowserContext* browser_context_; OneShotEvent ready_; - // Not owned, defaults to null. - EventRouter* event_router_; - DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); }; diff --git a/extensions/extensions.gypi b/extensions/extensions.gypi index d661a26..7457d7b 100644 --- a/extensions/extensions.gypi +++ b/extensions/extensions.gypi @@ -565,6 +565,8 @@ 'browser/event_page_tracker.h', 'browser/event_router.cc', 'browser/event_router.h', + 'browser/event_router_factory.cc', + 'browser/event_router_factory.h', 'browser/extension_error.cc', 'browser/extension_error.h', 'browser/extension_function.cc', diff --git a/extensions/shell/browser/shell_extension_system.cc b/extensions/shell/browser/shell_extension_system.cc index e5cabb7..e5f5a52 100644 --- a/extensions/shell/browser/shell_extension_system.cc +++ b/extensions/shell/browser/shell_extension_system.cc @@ -14,7 +14,6 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" #include "extensions/browser/api/app_runtime/app_runtime_api.h" -#include "extensions/browser/event_router.h" #include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/info_map.h" @@ -97,8 +96,6 @@ void ShellExtensionSystem::Shutdown() { void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) { runtime_data_.reset( new RuntimeData(ExtensionRegistry::Get(browser_context_))); - event_router_.reset( - new EventRouter(browser_context_, ExtensionPrefs::Get(browser_context_))); quota_service_.reset(new QuotaService); } @@ -132,10 +129,6 @@ InfoMap* ShellExtensionSystem::info_map() { return info_map_.get(); } -EventRouter* ShellExtensionSystem::event_router() { - return event_router_.get(); -} - QuotaService* ShellExtensionSystem::quota_service() { return quota_service_.get(); } diff --git a/extensions/shell/browser/shell_extension_system.h b/extensions/shell/browser/shell_extension_system.h index d4db30c..2cbdd5f 100644 --- a/extensions/shell/browser/shell_extension_system.h +++ b/extensions/shell/browser/shell_extension_system.h @@ -23,8 +23,6 @@ class BrowserContext; namespace extensions { -class DeclarativeUserScriptManager; -class EventRouter; class InfoMap; class ProcessManager; class RendererStartupHelper; @@ -59,7 +57,6 @@ class ShellExtensionSystem : public ExtensionSystem { StateStore* state_store() override; StateStore* rules_store() override; InfoMap* info_map() override; - EventRouter* event_router() override; QuotaService* quota_service() override; void RegisterExtensionWithRequestContexts( const Extension* extension) override; @@ -78,7 +75,6 @@ class ShellExtensionSystem : public ExtensionSystem { scoped_refptr<InfoMap> info_map_; scoped_ptr<RuntimeData> runtime_data_; - scoped_ptr<EventRouter> event_router_; scoped_ptr<QuotaService> quota_service_; // Signaled when the extension system has completed its startup tasks. |