Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: extensions/browser/service_registration_manager.h

Issue 652313002: Enable the mojo-based serial API in the renderer behind a flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-js-natives-registration
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/service_registration_manager.h
diff --git a/extensions/browser/service_registration_manager.h b/extensions/browser/service_registration_manager.h
index cec84a0b9dc7b0cbbbe9514d95ccea19fe3e68af..e577de72d3507d1c02a94a5a3bbf23c5372769d6 100644
--- a/extensions/browser/service_registration_manager.h
+++ b/extensions/browser/service_registration_manager.h
@@ -5,6 +5,7 @@
#ifndef EXTENSIONS_BROWSER_SERVICE_REGISTRATION_MANAGER_H_
#define EXTENSIONS_BROWSER_SERVICE_REGISTRATION_MANAGER_H_
+#include <map>
#include <string>
#include <utility>
#include <vector>
@@ -27,6 +28,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_);
}
+ virtual std::string GetName() const override { return Interface::Name_; }
+
private:
const base::Callback<void(mojo::InterfaceRequest<Interface>)> factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
@@ -77,6 +82,24 @@ class ServiceRegistrationManager {
new internal::ServiceFactory<Interface>(factory))));
}
+ // Overrides an existing service factory with |factory| for testing. This
+ // does not alter the permission checks used to determine whether a service
+ // is available.
+ template <typename Interface>
+ void OverrideServiceFactoryForTest(
raymes 2014/10/15 21:07:09 It seems a bit nicer to me to avoid having this te
Sam McNally 2014/10/20 07:21:07 Done.
+ const base::Callback<void(mojo::InterfaceRequest<Interface>)>& factory) {
+ bool inserted =
+ test_factories_.insert(std::make_pair(
+ Interface::Name_,
+ linked_ptr<internal::ServiceFactoryBase>(
+ new internal::ServiceFactory<Interface>(
+ factory)))).second;
+ DCHECK(inserted);
+ }
+
+ // Clears any overrides created using OverrideServiceFactoryForTest().
+ void ClearOverridesForTest();
+
// Adds the service factories appropriate for |render_frame_host| to its
// ServiceRegistry.
void AddToRenderFrame(content::RenderFrameHost* render_frame_host);
@@ -86,6 +109,9 @@ class ServiceRegistrationManager {
std::vector<std::pair<std::string, linked_ptr<internal::ServiceFactoryBase>>>
factories_;
+ std::map<std::string, linked_ptr<internal::ServiceFactoryBase>>
+ test_factories_;
+
DISALLOW_COPY_AND_ASSIGN(ServiceRegistrationManager);
};

Powered by Google App Engine
This is Rietveld 408576698