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

Side by Side Diff: services/shell/public/cpp/interface_provider.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: rebase 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
« no previous file with comments | « services/shell/public/cpp/connector.h ('k') | services/shell/public/cpp/interface_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "services/shell/public/interfaces/interface_provider.mojom.h" 8 #include "services/shell/public/interfaces/interface_provider.mojom.h"
9 9
10 namespace shell { 10 namespace shell {
11 11
12 // Encapsulates a mojom::InterfaceProviderPtr implemented in a remote 12 // Encapsulates a mojom::InterfaceProviderPtr implemented in a remote
13 // application. Provides two main features: 13 // application. Provides two main features:
14 // - a typesafe GetInterface() method for binding InterfacePtrs. 14 // - a typesafe GetInterface() method for binding InterfacePtrs.
15 // - a testing API that allows local callbacks to be registered that bind 15 // - a testing API that allows local callbacks to be registered that bind
16 // requests for remote interfaces. 16 // requests for remote interfaces.
17 // An instance of this class is used by the GetInterface() methods on 17 // An instance of this class is used by the GetInterface() methods on
18 // Connection. 18 // Connection.
19 class InterfaceProvider { 19 class InterfaceProvider {
20 public: 20 public:
21 using ForwardCallback = base::Callback<void(const mojo::String&,
22 mojo::ScopedMessagePipeHandle)>;
21 class TestApi { 23 class TestApi {
22 public: 24 public:
23 explicit TestApi(InterfaceProvider* provider) : provider_(provider) {} 25 explicit TestApi(InterfaceProvider* provider) : provider_(provider) {}
24 ~TestApi() {} 26 ~TestApi() {}
25 27
26 void SetBinderForName( 28 void SetBinderForName(
27 const std::string& name, 29 const std::string& name,
28 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder) { 30 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder) {
29 provider_->SetBinderForName(name, binder); 31 provider_->SetBinderForName(name, binder);
30 } 32 }
31 33
32 void ClearBinders() { 34 void ClearBinders() {
33 provider_->ClearBinders(); 35 provider_->ClearBinders();
34 } 36 }
35 37
36 private: 38 private:
37 InterfaceProvider* provider_; 39 InterfaceProvider* provider_;
38 DISALLOW_COPY_AND_ASSIGN(TestApi); 40 DISALLOW_COPY_AND_ASSIGN(TestApi);
39 }; 41 };
40 42
41 InterfaceProvider(); 43 InterfaceProvider();
42 ~InterfaceProvider(); 44 ~InterfaceProvider();
43 45
46 // Binds this InterfaceProvider to an actual mojom::InterfaceProvider pipe.
47 // It is an error to call this on a forwarding InterfaceProvider, i.e. this
48 // call is exclusive to Forward().
44 void Bind(mojom::InterfaceProviderPtr interface_provider); 49 void Bind(mojom::InterfaceProviderPtr interface_provider);
45 50
51 // Sets this InterfaceProvider to forward all GetInterface() requests to
52 // |callback|. It is an error to call this on a bound InterfaceProvider, i.e.
53 // this call is exclusive to Bind(). In addition, and unlike Bind(), this MUST
54 // be called before any calls to GetInterface() are made.
55 void Forward(const ForwardCallback& callback);
56
46 // Returns a raw pointer to the remote InterfaceProvider. 57 // Returns a raw pointer to the remote InterfaceProvider.
47 mojom::InterfaceProvider* get() { return interface_provider_.get(); } 58 mojom::InterfaceProvider* get() { return interface_provider_.get(); }
48 59
49 // Sets a closure to be run when the remote InterfaceProvider pipe is closed. 60 // Sets a closure to be run when the remote InterfaceProvider pipe is closed.
50 void SetConnectionLostClosure(const base::Closure& connection_lost_closure); 61 void SetConnectionLostClosure(const base::Closure& connection_lost_closure);
51 62
52 base::WeakPtr<InterfaceProvider> GetWeakPtr(); 63 base::WeakPtr<InterfaceProvider> GetWeakPtr();
53 64
54 // Binds |ptr| to an implementation of Interface in the remote application. 65 // Binds |ptr| to an implementation of Interface in the remote application.
55 // |ptr| can immediately be used to start sending requests to the remote 66 // |ptr| can immediately be used to start sending requests to the remote
(...skipping 20 matching lines...) Expand all
76 } 87 }
77 void ClearBinders(); 88 void ClearBinders();
78 89
79 using BinderMap = std::map< 90 using BinderMap = std::map<
80 std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)>>; 91 std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)>>;
81 BinderMap binders_; 92 BinderMap binders_;
82 93
83 mojom::InterfaceProviderPtr interface_provider_; 94 mojom::InterfaceProviderPtr interface_provider_;
84 mojom::InterfaceProviderRequest pending_request_; 95 mojom::InterfaceProviderRequest pending_request_;
85 96
97 // A callback to receive all GetInterface() requests in lieu of the
98 // InterfaceProvider pipe.
99 ForwardCallback forward_callback_;
100
86 base::WeakPtrFactory<InterfaceProvider> weak_factory_; 101 base::WeakPtrFactory<InterfaceProvider> weak_factory_;
87 102
88 DISALLOW_COPY_AND_ASSIGN(InterfaceProvider); 103 DISALLOW_COPY_AND_ASSIGN(InterfaceProvider);
89 }; 104 };
90 105
91 } // namespace shell 106 } // namespace shell
92 107
93 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_ 108 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_PROVIDER_H_
OLDNEW
« no previous file with comments | « services/shell/public/cpp/connector.h ('k') | services/shell/public/cpp/interface_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698