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

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.cc

Issue 2532053004: Mojo C++ bindings: remove the single-threaded Router. (Closed)
Patch Set: . Created 4 years 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 #include "mojo/public/cpp/bindings/lib/binding_state.h" 5 #include "mojo/public/cpp/bindings/lib/binding_state.h"
6 6
7 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 7 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
8 8
9 namespace mojo { 9 namespace mojo {
10 namespace internal { 10 namespace internal {
11 11
12 SimpleBindingState::SimpleBindingState() = default; 12 BindingStateBase::BindingStateBase() = default;
13 13
14 SimpleBindingState::~SimpleBindingState() = default; 14 BindingStateBase::~BindingStateBase() = default;
15 15
16 void SimpleBindingState::AddFilter(std::unique_ptr<MessageReceiver> filter) { 16 void BindingStateBase::AddFilter(std::unique_ptr<MessageReceiver> filter) {
17 DCHECK(router_); 17 DCHECK(endpoint_client_);
18 router_->AddFilter(std::move(filter)); 18 endpoint_client_->AddFilter(std::move(filter));
19 } 19 }
20 20
21 void SimpleBindingState::PauseIncomingMethodCallProcessing() { 21 bool BindingStateBase::HasAssociatedInterfaces() const {
22 return router_ ? router_->HasAssociatedEndpoints() : false;
23 }
24
25 void BindingStateBase::PauseIncomingMethodCallProcessing() {
22 DCHECK(router_); 26 DCHECK(router_);
23 router_->PauseIncomingMethodCallProcessing(); 27 router_->PauseIncomingMethodCallProcessing();
24 } 28 }
25 void SimpleBindingState::ResumeIncomingMethodCallProcessing() { 29 void BindingStateBase::ResumeIncomingMethodCallProcessing() {
26 DCHECK(router_); 30 DCHECK(router_);
27 router_->ResumeIncomingMethodCallProcessing(); 31 router_->ResumeIncomingMethodCallProcessing();
28 } 32 }
29 33
30 bool SimpleBindingState::WaitForIncomingMethodCall(MojoDeadline deadline) { 34 bool BindingStateBase::WaitForIncomingMethodCall(MojoDeadline deadline) {
31 DCHECK(router_); 35 DCHECK(router_);
32 return router_->WaitForIncomingMessage(deadline); 36 return router_->WaitForIncomingMessage(deadline);
33 } 37 }
34 38
35 void SimpleBindingState::Close() { 39 void BindingStateBase::Close() {
36 if (!router_) 40 if (!router_)
37 return; 41 return;
38 42
39 router_->CloseMessagePipe();
40 DestroyRouter();
41 }
42
43 void SimpleBindingState::CloseWithReason(uint32_t custom_reason,
44 const std::string& description) {
45 if (router_)
46 router_->control_message_proxy()->SendDisconnectReason(custom_reason,
47 description);
48 Close();
49 }
50
51 void SimpleBindingState::FlushForTesting() {
52 router_->control_message_proxy()->FlushForTesting();
53 }
54
55 void SimpleBindingState::EnableTestingMode() {
56 DCHECK(is_bound());
57 router_->EnableTestingMode();
58 }
59
60 void SimpleBindingState::BindInternal(
61 ScopedMessagePipeHandle handle,
62 scoped_refptr<base::SingleThreadTaskRunner> runner,
63 const char* interface_name,
64 std::unique_ptr<MessageReceiver> request_validator,
65 bool has_sync_methods,
66 MessageReceiverWithResponderStatus* stub,
67 uint32_t interface_version) {
68 FilterChain filters;
69 filters.Append<MessageHeaderValidator>(interface_name);
70 filters.Append(std::move(request_validator));
71
72 router_ = new internal::Router(std::move(handle), std::move(filters),
73 has_sync_methods, std::move(runner),
74 interface_version);
75 router_->set_incoming_receiver(stub);
76 }
77
78 void SimpleBindingState::DestroyRouter() {
79 delete router_;
80 router_ = nullptr;
81 }
82
83 // -----------------------------------------------------------------------------
84
85 MultiplexedBindingState::MultiplexedBindingState() = default;
86
87 MultiplexedBindingState::~MultiplexedBindingState() = default;
88
89 void MultiplexedBindingState::AddFilter(
90 std::unique_ptr<MessageReceiver> filter) {
91 DCHECK(endpoint_client_);
92 endpoint_client_->AddFilter(std::move(filter));
93 }
94
95 bool MultiplexedBindingState::HasAssociatedInterfaces() const {
96 return router_ ? router_->HasAssociatedEndpoints() : false;
97 }
98
99 void MultiplexedBindingState::PauseIncomingMethodCallProcessing() {
100 DCHECK(router_);
101 router_->PauseIncomingMethodCallProcessing();
102 }
103 void MultiplexedBindingState::ResumeIncomingMethodCallProcessing() {
104 DCHECK(router_);
105 router_->ResumeIncomingMethodCallProcessing();
106 }
107
108 bool MultiplexedBindingState::WaitForIncomingMethodCall(MojoDeadline deadline) {
109 DCHECK(router_);
110 return router_->WaitForIncomingMessage(deadline);
111 }
112
113 void MultiplexedBindingState::Close() {
114 if (!router_)
115 return;
116
117 endpoint_client_.reset(); 43 endpoint_client_.reset();
118 router_->CloseMessagePipe(); 44 router_->CloseMessagePipe();
119 router_ = nullptr; 45 router_ = nullptr;
120 } 46 }
121 47
122 void MultiplexedBindingState::CloseWithReason(uint32_t custom_reason, 48 void BindingStateBase::CloseWithReason(uint32_t custom_reason,
123 const std::string& description) { 49 const std::string& description) {
124 if (endpoint_client_) 50 if (endpoint_client_)
125 endpoint_client_->control_message_proxy()->SendDisconnectReason( 51 endpoint_client_->control_message_proxy()->SendDisconnectReason(
126 custom_reason, description); 52 custom_reason, description);
127 Close(); 53 Close();
128 } 54 }
129 55
130 void MultiplexedBindingState::FlushForTesting() { 56 void BindingStateBase::FlushForTesting() {
131 endpoint_client_->control_message_proxy()->FlushForTesting(); 57 endpoint_client_->control_message_proxy()->FlushForTesting();
132 } 58 }
133 59
134 void MultiplexedBindingState::EnableTestingMode() { 60 void BindingStateBase::EnableTestingMode() {
135 DCHECK(is_bound()); 61 DCHECK(is_bound());
136 router_->EnableTestingMode(); 62 router_->EnableTestingMode();
137 } 63 }
138 64
139 void MultiplexedBindingState::BindInternal( 65 void BindingStateBase::BindInternal(
140 ScopedMessagePipeHandle handle, 66 ScopedMessagePipeHandle handle,
141 scoped_refptr<base::SingleThreadTaskRunner> runner, 67 scoped_refptr<base::SingleThreadTaskRunner> runner,
142 const char* interface_name, 68 const char* interface_name,
143 std::unique_ptr<MessageReceiver> request_validator, 69 std::unique_ptr<MessageReceiver> request_validator,
144 bool passes_associated_kinds, 70 bool passes_associated_kinds,
145 bool has_sync_methods, 71 bool has_sync_methods,
146 MessageReceiverWithResponderStatus* stub, 72 MessageReceiverWithResponderStatus* stub,
147 uint32_t interface_version) { 73 uint32_t interface_version) {
148 DCHECK(!router_); 74 DCHECK(!router_);
149 75
150 MultiplexRouter::Config config = 76 MultiplexRouter::Config config =
151 passes_associated_kinds 77 passes_associated_kinds
152 ? MultiplexRouter::MULTI_INTERFACE 78 ? MultiplexRouter::MULTI_INTERFACE
153 : (has_sync_methods 79 : (has_sync_methods
154 ? MultiplexRouter::SINGLE_INTERFACE_WITH_SYNC_METHODS 80 ? MultiplexRouter::SINGLE_INTERFACE_WITH_SYNC_METHODS
155 : MultiplexRouter::SINGLE_INTERFACE); 81 : MultiplexRouter::SINGLE_INTERFACE);
156 router_ = new MultiplexRouter(std::move(handle), config, false, runner); 82 router_ = new MultiplexRouter(std::move(handle), config, false, runner);
157 router_->SetMasterInterfaceName(interface_name); 83 router_->SetMasterInterfaceName(interface_name);
158 84
159 endpoint_client_.reset(new InterfaceEndpointClient( 85 endpoint_client_.reset(new InterfaceEndpointClient(
160 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, 86 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub,
161 std::move(request_validator), has_sync_methods, std::move(runner), 87 std::move(request_validator), has_sync_methods, std::move(runner),
162 interface_version)); 88 interface_version));
163 } 89 }
164 90
165 } // namesapce internal 91 } // namesapce internal
166 } // namespace mojo 92 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.h ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698