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

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

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 3 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 #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"
8
7 namespace mojo { 9 namespace mojo {
8 namespace internal { 10 namespace internal {
9 11
10 SimpleBindingState::SimpleBindingState() = default; 12 SimpleBindingState::SimpleBindingState() = default;
11 13
12 SimpleBindingState::~SimpleBindingState() = default; 14 SimpleBindingState::~SimpleBindingState() = default;
13 15
14 void SimpleBindingState::AddFilter(std::unique_ptr<MessageReceiver> filter) { 16 void SimpleBindingState::AddFilter(std::unique_ptr<MessageReceiver> filter) {
15 DCHECK(router_); 17 DCHECK(router_);
16 router_->AddFilter(std::move(filter)); 18 router_->AddFilter(std::move(filter));
(...skipping 14 matching lines...) Expand all
31 } 33 }
32 34
33 void SimpleBindingState::Close() { 35 void SimpleBindingState::Close() {
34 if (!router_) 36 if (!router_)
35 return; 37 return;
36 38
37 router_->CloseMessagePipe(); 39 router_->CloseMessagePipe();
38 DestroyRouter(); 40 DestroyRouter();
39 } 41 }
40 42
43 void SimpleBindingState::FlushForTesting() {
44 if (!router_ || router_->encountered_error())
45 return;
46
47 router_->control_message_proxy()->FlushForTesting();
48 }
49
41 void SimpleBindingState::EnableTestingMode() { 50 void SimpleBindingState::EnableTestingMode() {
42 DCHECK(is_bound()); 51 DCHECK(is_bound());
43 router_->EnableTestingMode(); 52 router_->EnableTestingMode();
44 } 53 }
45 54
46 void SimpleBindingState::BindInternal( 55 void SimpleBindingState::BindInternal(
47 ScopedMessagePipeHandle handle, 56 ScopedMessagePipeHandle handle,
48 scoped_refptr<base::SingleThreadTaskRunner> runner, 57 scoped_refptr<base::SingleThreadTaskRunner> runner,
49 const char* interface_name, 58 const char* interface_name,
50 std::unique_ptr<MessageReceiver> request_validator, 59 std::unique_ptr<MessageReceiver> request_validator,
51 bool has_sync_methods, 60 bool has_sync_methods,
52 MessageReceiverWithResponderStatus* stub) { 61 MessageReceiverWithResponderStatus* stub,
62 uint32_t interface_version) {
53 FilterChain filters; 63 FilterChain filters;
54 filters.Append<MessageHeaderValidator>(interface_name); 64 filters.Append<MessageHeaderValidator>(interface_name);
55 filters.Append(std::move(request_validator)); 65 filters.Append(std::move(request_validator));
56 66
57 router_ = new internal::Router(std::move(handle), std::move(filters), 67 router_ = new internal::Router(std::move(handle), std::move(filters),
58 has_sync_methods, std::move(runner)); 68 has_sync_methods, std::move(runner),
69 interface_version);
59 router_->set_incoming_receiver(stub); 70 router_->set_incoming_receiver(stub);
60 router_->set_connection_error_handler(base::Bind( 71 router_->set_connection_error_handler(base::Bind(
61 &SimpleBindingState::RunConnectionErrorHandler, base::Unretained(this))); 72 &SimpleBindingState::RunConnectionErrorHandler, base::Unretained(this)));
62 } 73 }
63 74
64 void SimpleBindingState::DestroyRouter() { 75 void SimpleBindingState::DestroyRouter() {
65 router_->set_connection_error_handler(base::Closure()); 76 router_->set_connection_error_handler(base::Closure());
66 delete router_; 77 delete router_;
67 router_ = nullptr; 78 router_ = nullptr;
68 connection_error_handler_.Reset(); 79 connection_error_handler_.Reset();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void MultiplexedBindingState::Close() { 117 void MultiplexedBindingState::Close() {
107 if (!router_) 118 if (!router_)
108 return; 119 return;
109 120
110 endpoint_client_.reset(); 121 endpoint_client_.reset();
111 router_->CloseMessagePipe(); 122 router_->CloseMessagePipe();
112 router_ = nullptr; 123 router_ = nullptr;
113 connection_error_handler_.Reset(); 124 connection_error_handler_.Reset();
114 } 125 }
115 126
127 void MultiplexedBindingState::FlushForTesting() {
128 if (!endpoint_client_ || endpoint_client_->encountered_error())
129 return;
130
131 endpoint_client_->control_message_proxy()->FlushForTesting();
132 }
133
116 void MultiplexedBindingState::EnableTestingMode() { 134 void MultiplexedBindingState::EnableTestingMode() {
117 DCHECK(is_bound()); 135 DCHECK(is_bound());
118 router_->EnableTestingMode(); 136 router_->EnableTestingMode();
119 } 137 }
120 138
121 void MultiplexedBindingState::BindInternal( 139 void MultiplexedBindingState::BindInternal(
122 ScopedMessagePipeHandle handle, 140 ScopedMessagePipeHandle handle,
123 scoped_refptr<base::SingleThreadTaskRunner> runner, 141 scoped_refptr<base::SingleThreadTaskRunner> runner,
124 const char* interface_name, 142 const char* interface_name,
125 std::unique_ptr<MessageReceiver> request_validator, 143 std::unique_ptr<MessageReceiver> request_validator,
126 bool has_sync_methods, 144 bool has_sync_methods,
127 MessageReceiverWithResponderStatus* stub) { 145 MessageReceiverWithResponderStatus* stub,
146 uint32_t interface_version) {
128 DCHECK(!router_); 147 DCHECK(!router_);
129 148
130 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); 149 router_ = new internal::MultiplexRouter(false, std::move(handle), runner);
131 router_->SetMasterInterfaceName(interface_name); 150 router_->SetMasterInterfaceName(interface_name);
132 151
133 endpoint_client_.reset(new InterfaceEndpointClient( 152 endpoint_client_.reset(new InterfaceEndpointClient(
134 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, 153 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub,
135 std::move(request_validator), has_sync_methods, std::move(runner))); 154 std::move(request_validator), has_sync_methods, std::move(runner),
155 interface_version));
136 156
137 endpoint_client_->set_connection_error_handler( 157 endpoint_client_->set_connection_error_handler(
138 base::Bind(&MultiplexedBindingState::RunConnectionErrorHandler, 158 base::Bind(&MultiplexedBindingState::RunConnectionErrorHandler,
139 base::Unretained(this))); 159 base::Unretained(this)));
140 } 160 }
141 161
142 void MultiplexedBindingState::RunConnectionErrorHandler() { 162 void MultiplexedBindingState::RunConnectionErrorHandler() {
143 if (!connection_error_handler_.is_null()) 163 if (!connection_error_handler_.is_null())
144 connection_error_handler_.Run(); 164 connection_error_handler_.Run();
145 } 165 }
146 166
147 } // namesapce internal 167 } // namesapce internal
148 } // namespace mojo 168 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698