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

Side by Side Diff: extensions/browser/mojo/service_registration_manager.h

Issue 652793002: Add service registration for apps APIs implemented as mojo services. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXTENSIONS_BROWSER_MOJO_SERVICE_REGISTRATION_MANAGER_H_
6 #define EXTENSIONS_BROWSER_MOJO_SERVICE_REGISTRATION_MANAGER_H_
7
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/linked_ptr.h"
14 #include "content/public/common/service_registry.h"
15 #include "mojo/public/cpp/bindings/interface_request.h"
16
17 namespace content {
18 class RenderFrameHost;
19 }
20
21 namespace extensions {
22 namespace internal {
23
24 // A base class for forwarding calls to ServiceRegistry::AddService().
25 class ServiceFactoryBase {
26 public:
27 virtual ~ServiceFactoryBase() {}
28
29 // Add this service factory to |service_registry|.
30 virtual void Register(content::ServiceRegistry* service_registry) const = 0;
31 };
32
33 template <typename Interface>
34 class ServiceFactory : public ServiceFactoryBase {
35 public:
36 explicit ServiceFactory(
37 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& factory)
Ken Rockot(use gerrit already) 2014/10/24 16:36:14 I agree with Raymes on the confusing nature of thi
38 : factory_(factory) {}
39 ~ServiceFactory() override {}
40
41 void Register(content::ServiceRegistry* service_registry) const override {
42 service_registry->AddService(factory_);
43 }
44
45 private:
46 const base::Callback<void(mojo::InterfaceRequest<Interface>)> factory_;
47 DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
48 };
49
50 } // namespace internal
51
52 // A meta service registry. This allows registration of service factories and
53 // their associated extensions API permission name. Whenever a RenderFrameHost
54 // is created, each service that the render frame should have access to (based
55 // on its SiteInstance), is added to the ServiceRegistry for that
56 // RenderFrameHost.
57 class ServiceRegistrationManager {
58 public:
59 ServiceRegistrationManager();
60 ~ServiceRegistrationManager();
61
62 static ServiceRegistrationManager* GetSharedInstance();
63
64 // Registers a ServiceFactory to be provided to extensions with the
65 // |permission_name| API permission.
66 //
67 // TODO(sammc): Add support for service factories that take the Extension*
68 // (or extension ID) and BrowserContext to allow fine-grained service and
69 // permission customization.
70 template <typename Interface>
71 void AddServiceFactory(
72 const std::string& permission_name,
Ken Rockot(use gerrit already) 2014/10/24 16:36:14 nit: Maybe we could have a ServiceFilter type (whi
Sam McNally 2014/10/26 23:17:31 The TODO is about currying the Extension and/or Br
73 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& factory) {
74 factories_.push_back(
75 std::make_pair(permission_name,
76 linked_ptr<internal::ServiceFactoryBase>(
77 new internal::ServiceFactory<Interface>(factory))));
78 }
79
80 // Adds the service factories appropriate for |render_frame_host| to its
81 // ServiceRegistry.
82 void AddServicesToRenderFrame(content::RenderFrameHost* render_frame_host);
83
84 private:
85 // All factories and their corresponding API permissions.
86 std::vector<std::pair<std::string, linked_ptr<internal::ServiceFactoryBase>>>
87 factories_;
88
89 DISALLOW_COPY_AND_ASSIGN(ServiceRegistrationManager);
90 };
91
92 } // namespace extensions
93
94 #endif // EXTENSIONS_BROWSER_MOJO_SERVICE_REGISTRATION_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_web_contents_observer.cc ('k') | extensions/browser/mojo/service_registration_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698