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

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

Issue 2214383002: Move registration of Java mojo interfaces to the new InterfaceRegistrar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java-content-interface-registry
Patch Set: fix vr_shell build Created 4 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 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_PROVIDER_H_ 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_
6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_ 6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_
7 7
8 #include "base/bind.h"
8 #include "services/shell/public/interfaces/interface_provider.mojom.h" 9 #include "services/shell/public/interfaces/interface_provider.mojom.h"
9 10
10 namespace shell { 11 namespace shell {
11 12
12 // Encapsulates a mojom::InterfaceProviderPtr implemented in a remote 13 // Encapsulates a mojom::InterfaceProviderPtr implemented in a remote
13 // application. Provides two main features: 14 // application. Provides two main features:
14 // - a typesafe GetInterface() method for binding InterfacePtrs. 15 // - a typesafe GetInterface() method for binding InterfacePtrs.
15 // - a testing API that allows local callbacks to be registered that bind 16 // - a testing API that allows local callbacks to be registered that bind
16 // requests for remote interfaces. 17 // requests for remote interfaces.
17 // An instance of this class is used by the GetInterface() methods on 18 // An instance of this class is used by the GetInterface() methods on
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 GetInterface(Interface::Name_, std::move(pipe.handle1)); 74 GetInterface(Interface::Name_, std::move(pipe.handle1));
74 } 75 }
75 template <typename Interface> 76 template <typename Interface>
76 void GetInterface(mojo::InterfaceRequest<Interface> request) { 77 void GetInterface(mojo::InterfaceRequest<Interface> request) {
77 GetInterface(Interface::Name_, std::move(request.PassMessagePipe())); 78 GetInterface(Interface::Name_, std::move(request.PassMessagePipe()));
78 } 79 }
79 void GetInterface(const std::string& name, 80 void GetInterface(const std::string& name,
80 mojo::ScopedMessagePipeHandle request_handle); 81 mojo::ScopedMessagePipeHandle request_handle);
81 82
83 // Returns a callback to GetInterface<Interface>(). This can be passed to
84 // InterfaceRegistry::AddInterface() to forward requests.
85 template <typename Interface>
86 base::Callback<void(mojo::InterfaceRequest<Interface>)>
87 CreateInterfaceFactory() {
88 // InterfaceProvider::GetInterface() is overloaded, so static_cast to select
89 // the overload that takes an mojo::InterfaceRequest<Interface>.
90 return base::Bind(static_cast<void (InterfaceProvider::*)(
91 mojo::InterfaceRequest<Interface>)>(
92 &InterfaceProvider::GetInterface<Interface>),
93 GetWeakPtr());
94 }
95
82 private: 96 private:
83 void SetBinderForName( 97 void SetBinderForName(
84 const std::string& name, 98 const std::string& name,
85 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder) { 99 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder) {
86 binders_[name] = binder; 100 binders_[name] = binder;
87 } 101 }
88 void ClearBinders(); 102 void ClearBinders();
89 103
90 using BinderMap = std::map< 104 using BinderMap = std::map<
91 std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)>>; 105 std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)>>;
92 BinderMap binders_; 106 BinderMap binders_;
93 107
94 mojom::InterfaceProviderPtr interface_provider_; 108 mojom::InterfaceProviderPtr interface_provider_;
95 mojom::InterfaceProviderRequest pending_request_; 109 mojom::InterfaceProviderRequest pending_request_;
96 110
97 // A callback to receive all GetInterface() requests in lieu of the 111 // A callback to receive all GetInterface() requests in lieu of the
98 // InterfaceProvider pipe. 112 // InterfaceProvider pipe.
99 ForwardCallback forward_callback_; 113 ForwardCallback forward_callback_;
100 114
101 base::WeakPtrFactory<InterfaceProvider> weak_factory_; 115 base::WeakPtrFactory<InterfaceProvider> weak_factory_;
102 116
103 DISALLOW_COPY_AND_ASSIGN(InterfaceProvider); 117 DISALLOW_COPY_AND_ASSIGN(InterfaceProvider);
104 }; 118 };
105 119
106 } // namespace shell 120 } // namespace shell
107 121
108 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_ 122 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698