diff options
author | sammc <sammc@chromium.org> | 2014-10-28 04:51:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-28 11:51:47 +0000 |
commit | fb8875c804337e452e7f799bc3960b912100e5a9 (patch) | |
tree | 193fcf3358fb5ccc7885ce4f0a60c7cde190aa7b /extensions/browser/mojo | |
parent | 929d45a9ff9a74eb05453a10b84ba1a27392c1e6 (diff) | |
download | chromium_src-fb8875c804337e452e7f799bc3960b912100e5a9.zip chromium_src-fb8875c804337e452e7f799bc3960b912100e5a9.tar.gz chromium_src-fb8875c804337e452e7f799bc3960b912100e5a9.tar.bz2 |
Enable the mojo-based serial API in the renderer behind a flag.
This enables the serial custom bindings that forward to the mojo serial
service behind the --enable-mojo-serial-service flag. This adds service
factory overrides to ServiceRegistrationManager for testing and updates
the serial api browsertest to test both serial implementations.
BUG=389016
Review URL: https://codereview.chromium.org/652313002
Cr-Commit-Position: refs/heads/master@{#301594}
Diffstat (limited to 'extensions/browser/mojo')
-rw-r--r-- | extensions/browser/mojo/service_registration_manager.cc | 22 | ||||
-rw-r--r-- | extensions/browser/mojo/service_registration_manager.h | 17 |
2 files changed, 36 insertions, 3 deletions
diff --git a/extensions/browser/mojo/service_registration_manager.cc b/extensions/browser/mojo/service_registration_manager.cc index 97f3698..ee3e55a 100644 --- a/extensions/browser/mojo/service_registration_manager.cc +++ b/extensions/browser/mojo/service_registration_manager.cc @@ -23,6 +23,8 @@ namespace { base::LazyInstance<ServiceRegistrationManager> g_lazy_instance = LAZY_INSTANCE_INITIALIZER; +ServiceRegistrationManager* g_test_instance = nullptr; + } // namespace ServiceRegistrationManager::ServiceRegistrationManager() { @@ -44,6 +46,8 @@ ServiceRegistrationManager::~ServiceRegistrationManager() { } ServiceRegistrationManager* ServiceRegistrationManager::GetSharedInstance() { + if (g_test_instance) + return g_test_instance; return g_lazy_instance.Pointer(); } @@ -72,9 +76,23 @@ void ServiceRegistrationManager::AddServicesToRenderFrame( for (const auto& factory : factories_) { auto availability = ExtensionAPI::GetSharedInstance()->IsAvailable( factory.first, extension, context_type, extension_url); - if (availability.is_available()) - factory.second->Register(render_frame_host->GetServiceRegistry()); + if (availability.is_available()) { + AddServiceToServiceRegistry(render_frame_host->GetServiceRegistry(), + factory.second.get()); + } } } +void ServiceRegistrationManager::AddServiceToServiceRegistry( + content::ServiceRegistry* service_registry, + internal::ServiceFactoryBase* factory) { + factory->Register(service_registry); +} + +// static +void ServiceRegistrationManager::SetServiceRegistrationManagerForTest( + ServiceRegistrationManager* service_registration_manager) { + g_test_instance = service_registration_manager; +} + } // namespace extensions diff --git a/extensions/browser/mojo/service_registration_manager.h b/extensions/browser/mojo/service_registration_manager.h index c7d14c6..5fed206 100644 --- a/extensions/browser/mojo/service_registration_manager.h +++ b/extensions/browser/mojo/service_registration_manager.h @@ -19,6 +19,7 @@ class RenderFrameHost; } namespace extensions { + namespace internal { // A base class for forwarding calls to ServiceRegistry::AddService(). @@ -28,6 +29,8 @@ class ServiceFactoryBase { // Add this service factory to |service_registry|. virtual void Register(content::ServiceRegistry* service_registry) const = 0; + + virtual std::string GetName() const = 0; }; template <typename Interface> @@ -42,6 +45,8 @@ class ServiceFactory : public ServiceFactoryBase { service_registry->AddService(factory_); } + std::string GetName() const override { return Interface::Name_; } + private: const base::Callback<void(mojo::InterfaceRequest<Interface>)> factory_; DISALLOW_COPY_AND_ASSIGN(ServiceFactory); @@ -57,7 +62,7 @@ class ServiceFactory : public ServiceFactoryBase { class ServiceRegistrationManager { public: ServiceRegistrationManager(); - ~ServiceRegistrationManager(); + virtual ~ServiceRegistrationManager(); static ServiceRegistrationManager* GetSharedInstance(); @@ -84,7 +89,17 @@ class ServiceRegistrationManager { // ServiceRegistry. void AddServicesToRenderFrame(content::RenderFrameHost* render_frame_host); + protected: + virtual void AddServiceToServiceRegistry( + content::ServiceRegistry* service_registry, + internal::ServiceFactoryBase* service_factory); + private: + friend class TestServiceRegistrationManager; + + static void SetServiceRegistrationManagerForTest( + ServiceRegistrationManager* service_registration_manager); + // All factories and their corresponding API permissions. std::vector<std::pair<std::string, linked_ptr<internal::ServiceFactoryBase>>> factories_; |