OLD | NEW |
---|---|
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 "base/auto_reset.h" | |
8 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | |
9 | |
7 namespace mojo { | 10 namespace mojo { |
8 namespace internal { | 11 namespace internal { |
9 | 12 |
10 SimpleBindingState::SimpleBindingState() = default; | 13 SimpleBindingState::SimpleBindingState() = default; |
11 | 14 |
12 SimpleBindingState::~SimpleBindingState() = default; | 15 SimpleBindingState::~SimpleBindingState() = default; |
13 | 16 |
14 void SimpleBindingState::AddFilter(std::unique_ptr<MessageReceiver> filter) { | 17 void SimpleBindingState::AddFilter(std::unique_ptr<MessageReceiver> filter) { |
15 DCHECK(router_); | 18 DCHECK(router_); |
16 router_->AddFilter(std::move(filter)); | 19 router_->AddFilter(std::move(filter)); |
(...skipping 14 matching lines...) Expand all Loading... | |
31 } | 34 } |
32 | 35 |
33 void SimpleBindingState::Close() { | 36 void SimpleBindingState::Close() { |
34 if (!router_) | 37 if (!router_) |
35 return; | 38 return; |
36 | 39 |
37 router_->CloseMessagePipe(); | 40 router_->CloseMessagePipe(); |
38 DestroyRouter(); | 41 DestroyRouter(); |
39 } | 42 } |
40 | 43 |
44 void SimpleBindingState::FlushForTesting() { | |
45 if (!router_ || router_->encountered_error()) | |
46 return; | |
47 | |
48 ControlMessageProxy control_message_proxy(router_); | |
49 base::AutoReset<ControlMessageProxy*> control_message_proxy_resetter( | |
50 &control_message_proxy_, &control_message_proxy); | |
51 control_message_proxy.FlushForTesting(); | |
52 } | |
53 | |
41 void SimpleBindingState::EnableTestingMode() { | 54 void SimpleBindingState::EnableTestingMode() { |
42 DCHECK(is_bound()); | 55 DCHECK(is_bound()); |
43 router_->EnableTestingMode(); | 56 router_->EnableTestingMode(); |
44 } | 57 } |
45 | 58 |
46 void SimpleBindingState::BindInternal( | 59 void SimpleBindingState::BindInternal( |
47 ScopedMessagePipeHandle handle, | 60 ScopedMessagePipeHandle handle, |
48 scoped_refptr<base::SingleThreadTaskRunner> runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> runner, |
49 const char* interface_name, | 62 const char* interface_name, |
50 std::unique_ptr<MessageReceiver> request_validator, | 63 std::unique_ptr<MessageReceiver> request_validator, |
(...skipping 11 matching lines...) Expand all Loading... | |
62 } | 75 } |
63 | 76 |
64 void SimpleBindingState::DestroyRouter() { | 77 void SimpleBindingState::DestroyRouter() { |
65 router_->set_connection_error_handler(base::Closure()); | 78 router_->set_connection_error_handler(base::Closure()); |
66 delete router_; | 79 delete router_; |
67 router_ = nullptr; | 80 router_ = nullptr; |
68 connection_error_handler_.Reset(); | 81 connection_error_handler_.Reset(); |
69 } | 82 } |
70 | 83 |
71 void SimpleBindingState::RunConnectionErrorHandler() { | 84 void SimpleBindingState::RunConnectionErrorHandler() { |
85 if (control_message_proxy_) | |
86 control_message_proxy_->OnConnectionError(); | |
72 if (!connection_error_handler_.is_null()) | 87 if (!connection_error_handler_.is_null()) |
73 connection_error_handler_.Run(); | 88 connection_error_handler_.Run(); |
74 } | 89 } |
75 | 90 |
76 // ----------------------------------------------------------------------------- | 91 // ----------------------------------------------------------------------------- |
77 | 92 |
78 MultiplexedBindingState::MultiplexedBindingState() = default; | 93 MultiplexedBindingState::MultiplexedBindingState() = default; |
79 | 94 |
80 MultiplexedBindingState::~MultiplexedBindingState() = default; | 95 MultiplexedBindingState::~MultiplexedBindingState() = default; |
81 | 96 |
(...skipping 18 matching lines...) Expand all Loading... | |
100 void MultiplexedBindingState::Close() { | 115 void MultiplexedBindingState::Close() { |
101 if (!router_) | 116 if (!router_) |
102 return; | 117 return; |
103 | 118 |
104 endpoint_client_.reset(); | 119 endpoint_client_.reset(); |
105 router_->CloseMessagePipe(); | 120 router_->CloseMessagePipe(); |
106 router_ = nullptr; | 121 router_ = nullptr; |
107 connection_error_handler_.Reset(); | 122 connection_error_handler_.Reset(); |
108 } | 123 } |
109 | 124 |
125 void MultiplexedBindingState::FlushForTesting() { | |
126 if (!endpoint_client_ || endpoint_client_->encountered_error()) | |
127 return; | |
128 | |
129 ControlMessageProxy control_message_proxy(endpoint_client_.get()); | |
yzshen1
2016/08/26 21:07:07
Previously we only handled interface control messa
Sam McNally
2016/08/29 06:39:23
Done.
| |
130 base::AutoReset<ControlMessageProxy*> control_message_proxy_resetter( | |
131 &control_message_proxy_, &control_message_proxy); | |
132 control_message_proxy.FlushForTesting(); | |
133 } | |
134 | |
110 void MultiplexedBindingState::EnableTestingMode() { | 135 void MultiplexedBindingState::EnableTestingMode() { |
111 DCHECK(is_bound()); | 136 DCHECK(is_bound()); |
112 router_->EnableTestingMode(); | 137 router_->EnableTestingMode(); |
113 } | 138 } |
114 | 139 |
115 void MultiplexedBindingState::BindInternal( | 140 void MultiplexedBindingState::BindInternal( |
116 ScopedMessagePipeHandle handle, | 141 ScopedMessagePipeHandle handle, |
117 scoped_refptr<base::SingleThreadTaskRunner> runner, | 142 scoped_refptr<base::SingleThreadTaskRunner> runner, |
118 const char* interface_name, | 143 const char* interface_name, |
119 std::unique_ptr<MessageReceiver> request_validator, | 144 std::unique_ptr<MessageReceiver> request_validator, |
120 bool has_sync_methods, | 145 bool has_sync_methods, |
121 MessageReceiverWithResponderStatus* stub) { | 146 MessageReceiverWithResponderStatus* stub) { |
122 DCHECK(!router_); | 147 DCHECK(!router_); |
123 | 148 |
124 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); | 149 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); |
125 router_->SetMasterInterfaceName(interface_name); | 150 router_->SetMasterInterfaceName(interface_name); |
126 | 151 |
127 endpoint_client_.reset(new InterfaceEndpointClient( | 152 endpoint_client_.reset(new InterfaceEndpointClient( |
128 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, | 153 router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, |
129 std::move(request_validator), has_sync_methods, std::move(runner))); | 154 std::move(request_validator), has_sync_methods, std::move(runner))); |
130 | 155 |
131 endpoint_client_->set_connection_error_handler( | 156 endpoint_client_->set_connection_error_handler( |
132 base::Bind(&MultiplexedBindingState::RunConnectionErrorHandler, | 157 base::Bind(&MultiplexedBindingState::RunConnectionErrorHandler, |
133 base::Unretained(this))); | 158 base::Unretained(this))); |
134 } | 159 } |
135 | 160 |
136 void MultiplexedBindingState::RunConnectionErrorHandler() { | 161 void MultiplexedBindingState::RunConnectionErrorHandler() { |
162 if (control_message_proxy_) | |
163 control_message_proxy_->OnConnectionError(); | |
137 if (!connection_error_handler_.is_null()) | 164 if (!connection_error_handler_.is_null()) |
138 connection_error_handler_.Run(); | 165 connection_error_handler_.Run(); |
139 } | 166 } |
140 | 167 |
141 } // namesapce internal | 168 } // namesapce internal |
142 } // namespace mojo | 169 } // namespace mojo |
OLD | NEW |