| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> // For |std::swap()|. | 10 #include <algorithm> // For |std::swap()|. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 DCHECK(endpoint_client_); | 143 DCHECK(endpoint_client_); |
| 144 endpoint_client_->set_connection_error_with_reason_handler(error_handler); | 144 endpoint_client_->set_connection_error_with_reason_handler(error_handler); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Returns true if bound and awaiting a response to a message. | 147 // Returns true if bound and awaiting a response to a message. |
| 148 bool has_pending_callbacks() const { | 148 bool has_pending_callbacks() const { |
| 149 return endpoint_client_ && endpoint_client_->has_pending_responders(); | 149 return endpoint_client_ && endpoint_client_->has_pending_responders(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 size_t pending_callback_count() const { |
| 153 return endpoint_client_ ? endpoint_client_->pending_responder_count() : 0; |
| 154 } |
| 155 |
| 152 AssociatedGroup* associated_group() { | 156 AssociatedGroup* associated_group() { |
| 153 ConfigureProxyIfNecessary(); | 157 ConfigureProxyIfNecessary(); |
| 154 return endpoint_client_->associated_group(); | 158 return endpoint_client_->associated_group(); |
| 155 } | 159 } |
| 156 | 160 |
| 157 void EnableTestingMode() { | 161 void EnableTestingMode() { |
| 158 ConfigureProxyIfNecessary(); | 162 ConfigureProxyIfNecessary(); |
| 159 router_->EnableTestingMode(); | 163 router_->EnableTestingMode(); |
| 160 } | 164 } |
| 161 | 165 |
| 162 void ForwardMessage(Message message) { | 166 void ForwardMessage(Message message) { |
| 163 ConfigureProxyIfNecessary(); | 167 ConfigureProxyIfNecessary(); |
| 164 endpoint_client_->Accept(&message); | 168 endpoint_client_->Accept(&message); |
| 165 } | 169 } |
| 166 | 170 |
| 167 void ForwardMessageWithResponder(Message message, | 171 void ForwardMessageWithResponder(Message message, |
| 168 std::unique_ptr<MessageReceiver> responder) { | 172 std::unique_ptr<MessageReceiver> responder) { |
| 169 ConfigureProxyIfNecessary(); | 173 ConfigureProxyIfNecessary(); |
| 170 endpoint_client_->AcceptWithResponder(&message, responder.release()); | 174 endpoint_client_->AcceptWithResponder(&message, responder.release()); |
| 171 } | 175 } |
| 172 | 176 |
| 177 void set_process_async_during_sync(bool value) { |
| 178 DCHECK(!router_); |
| 179 process_async_during_sync_ = value; |
| 180 } |
| 181 |
| 173 private: | 182 private: |
| 174 using Proxy = typename Interface::Proxy_; | 183 using Proxy = typename Interface::Proxy_; |
| 175 | 184 |
| 176 void ConfigureProxyIfNecessary() { | 185 void ConfigureProxyIfNecessary() { |
| 177 // The proxy has been configured. | 186 // The proxy has been configured. |
| 178 if (proxy_) { | 187 if (proxy_) { |
| 179 DCHECK(router_); | 188 DCHECK(router_); |
| 180 DCHECK(endpoint_client_); | 189 DCHECK(endpoint_client_); |
| 181 return; | 190 return; |
| 182 } | 191 } |
| 183 // The object hasn't been bound. | 192 // The object hasn't been bound. |
| 184 if (!handle_.is_valid()) | 193 if (!handle_.is_valid()) |
| 185 return; | 194 return; |
| 186 | 195 |
| 187 MultiplexRouter::Config config = | 196 MultiplexRouter::Config config = |
| 188 Interface::PassesAssociatedKinds_ | 197 Interface::PassesAssociatedKinds_ |
| 189 ? MultiplexRouter::MULTI_INTERFACE | 198 ? MultiplexRouter::MULTI_INTERFACE |
| 190 : (Interface::HasSyncMethods_ | 199 : (Interface::HasSyncMethods_ |
| 191 ? MultiplexRouter::SINGLE_INTERFACE_WITH_SYNC_METHODS | 200 ? MultiplexRouter::SINGLE_INTERFACE_WITH_SYNC_METHODS |
| 192 : MultiplexRouter::SINGLE_INTERFACE); | 201 : MultiplexRouter::SINGLE_INTERFACE); |
| 193 router_ = new MultiplexRouter(std::move(handle_), config, true, runner_); | 202 router_ = new MultiplexRouter( |
| 203 std::move(handle_), config, true, runner_, |
| 204 process_async_during_sync_ |
| 205 ? MultiplexRouter::ALLOW_DIRECT_CLIENT_CALLS |
| 206 : MultiplexRouter::ALLOW_DIRECT_CLIENT_CALLS_FOR_SYNC_MESSAGES); |
| 194 router_->SetMasterInterfaceName(Interface::Name_); | 207 router_->SetMasterInterfaceName(Interface::Name_); |
| 195 endpoint_client_.reset(new InterfaceEndpointClient( | 208 endpoint_client_.reset(new InterfaceEndpointClient( |
| 196 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, | 209 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, |
| 197 base::WrapUnique(new typename Interface::ResponseValidator_()), false, | 210 base::WrapUnique(new typename Interface::ResponseValidator_()), false, |
| 198 std::move(runner_), | 211 std::move(runner_), |
| 199 // The version is only queried from the client so the value passed here | 212 // The version is only queried from the client so the value passed here |
| 200 // will not be used. | 213 // will not be used. |
| 201 0u)); | 214 0u)); |
| 202 proxy_.reset(new Proxy(endpoint_client_.get())); | 215 proxy_.reset(new Proxy(endpoint_client_.get())); |
| 203 if (Interface::PassesAssociatedKinds_) | 216 if (Interface::PassesAssociatedKinds_) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 std::unique_ptr<Proxy> proxy_; | 229 std::unique_ptr<Proxy> proxy_; |
| 217 | 230 |
| 218 // |router_| (as well as other members above) is not initialized until | 231 // |router_| (as well as other members above) is not initialized until |
| 219 // read/write with the message pipe handle is needed. |handle_| is valid | 232 // read/write with the message pipe handle is needed. |handle_| is valid |
| 220 // between the Bind() call and the initialization of |router_|. | 233 // between the Bind() call and the initialization of |router_|. |
| 221 ScopedMessagePipeHandle handle_; | 234 ScopedMessagePipeHandle handle_; |
| 222 scoped_refptr<base::SingleThreadTaskRunner> runner_; | 235 scoped_refptr<base::SingleThreadTaskRunner> runner_; |
| 223 | 236 |
| 224 uint32_t version_; | 237 uint32_t version_; |
| 225 | 238 |
| 239 bool process_async_during_sync_ = false; |
| 240 |
| 226 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 241 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
| 227 }; | 242 }; |
| 228 | 243 |
| 229 } // namespace internal | 244 } // namespace internal |
| 230 } // namespace mojo | 245 } // namespace mojo |
| 231 | 246 |
| 232 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ | 247 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ |
| OLD | NEW |