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

Side by Side Diff: services/shell/public/cpp/interface_registry.h

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ 6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
12 #include "services/shell/public/cpp/lib/callback_binder.h" 13 #include "services/shell/public/cpp/lib/callback_binder.h"
13 #include "services/shell/public/cpp/lib/interface_factory_binder.h" 14 #include "services/shell/public/cpp/lib/interface_factory_binder.h"
14 #include "services/shell/public/interfaces/interface_provider.mojom.h" 15 #include "services/shell/public/interfaces/interface_provider.mojom.h"
15 16
16 namespace shell { 17 namespace shell {
17 class InterfaceBinder; 18 class InterfaceBinder;
18 19
19 // An implementation of mojom::InterfaceProvider that allows the user to 20 // An implementation of mojom::InterfaceProvider that allows the user to
(...skipping 13 matching lines...) Expand all
33 // 34 //
34 // The InterfaceFactory must outlive the InterfaceRegistry. 35 // The InterfaceFactory must outlive the InterfaceRegistry.
35 // 36 //
36 // Additionally you may specify a default InterfaceBinder to handle requests for 37 // Additionally you may specify a default InterfaceBinder to handle requests for
37 // interfaces unhandled by any registered InterfaceFactory. Just as with 38 // interfaces unhandled by any registered InterfaceFactory. Just as with
38 // InterfaceFactory, the default InterfaceBinder supplied must outlive 39 // InterfaceFactory, the default InterfaceBinder supplied must outlive
39 // InterfaceRegistry. 40 // InterfaceRegistry.
40 // 41 //
41 class InterfaceRegistry : public mojom::InterfaceProvider { 42 class InterfaceRegistry : public mojom::InterfaceProvider {
42 public: 43 public:
44 using Binder = base::Callback<void(const mojo::String&,
45 mojo::ScopedMessagePipeHandle)>;
46
43 class TestApi { 47 class TestApi {
44 public: 48 public:
45 explicit TestApi(InterfaceRegistry* registry) : registry_(registry) {} 49 explicit TestApi(InterfaceRegistry* registry) : registry_(registry) {}
46 ~TestApi() {} 50 ~TestApi() {}
47 51
48 void SetInterfaceBinderForName(InterfaceBinder* binder, 52 void SetInterfaceBinderForName(InterfaceBinder* binder,
49 const std::string& interface_name) { 53 const std::string& interface_name) {
50 registry_->SetInterfaceBinderForName( 54 registry_->SetInterfaceBinderForName(
51 base::WrapUnique(binder), interface_name); 55 base::WrapUnique(binder), interface_name);
52 } 56 }
53 57
54 private: 58 private:
55 InterfaceRegistry* registry_; 59 InterfaceRegistry* registry_;
56 DISALLOW_COPY_AND_ASSIGN(TestApi); 60 DISALLOW_COPY_AND_ASSIGN(TestApi);
57 }; 61 };
58 62
59 // Construct with a Connection (which may be null), and create an 63 // Construct with a Connection (which may be null), and create an
60 // InterfaceProvider pipe, the client end of which may be obtained by calling 64 // InterfaceProvider pipe, the client end of which may be obtained by calling
61 // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's 65 // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's
62 // rules filtering which interfaces are allowed to be exposed to clients are 66 // rules filtering which interfaces are allowed to be exposed to clients are
63 // imposed on this registry. If null, they are not. 67 // imposed on this registry. If null, they are not.
64 explicit InterfaceRegistry(Connection* connection); 68 explicit InterfaceRegistry(Connection* connection);
65 ~InterfaceRegistry() override; 69 ~InterfaceRegistry() override;
66 70
71 // Sets a default handler for incoming interface requests which are allowed by
72 // capability filters but have no registered handler in this registry.
73 void set_default_binder(const Binder& binder) { default_binder_ = binder; }
74
67 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); 75 void Bind(mojom::InterfaceProviderRequest local_interfaces_request);
68 76
69 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); 77 base::WeakPtr<InterfaceRegistry> GetWeakPtr();
70 78
71 // Allows |Interface| to be exposed via this registry. Requests to bind will 79 // Allows |Interface| to be exposed via this registry. Requests to bind will
72 // be handled by |factory|. Returns true if the interface was exposed, false 80 // be handled by |factory|. Returns true if the interface was exposed, false
73 // if Connection policy prevented exposure. 81 // if Connection policy prevented exposure.
74 template <typename Interface> 82 template <typename Interface>
75 bool AddInterface(InterfaceFactory<Interface>* factory) { 83 bool AddInterface(InterfaceFactory<Interface>* factory) {
76 return SetInterfaceBinderForName( 84 return SetInterfaceBinderForName(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, 133 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder,
126 const std::string& name); 134 const std::string& name);
127 135
128 mojom::InterfaceProviderRequest pending_request_; 136 mojom::InterfaceProviderRequest pending_request_;
129 137
130 mojo::Binding<mojom::InterfaceProvider> binding_; 138 mojo::Binding<mojom::InterfaceProvider> binding_;
131 Connection* connection_; 139 Connection* connection_;
132 140
133 NameToInterfaceBinderMap name_to_binder_; 141 NameToInterfaceBinderMap name_to_binder_;
134 142
143 Binder default_binder_;
144
135 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; 145 base::WeakPtrFactory<InterfaceRegistry> weak_factory_;
136 146
137 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); 147 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry);
138 }; 148 };
139 149
140 } // namespace shell 150 } // namespace shell
141 151
142 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ 152 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698