| 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_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <assert.h> | |
| 9 | |
| 10 #include <algorithm> // For |std::swap()|. | 8 #include <algorithm> // For |std::swap()|. |
| 11 | 9 |
| 12 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 10 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
| 13 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 11 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 14 #include "mojo/public/cpp/bindings/lib/router.h" | 12 #include "mojo/public/cpp/bindings/lib/router.h" |
| 13 #include "mojo/public/cpp/environment/logging.h" |
| 15 | 14 |
| 16 struct MojoAsyncWaiter; | 15 struct MojoAsyncWaiter; |
| 17 | 16 |
| 18 namespace mojo { | 17 namespace mojo { |
| 19 namespace internal { | 18 namespace internal { |
| 20 | 19 |
| 21 template <typename Interface> | 20 template <typename Interface> |
| 22 class InterfacePtrState { | 21 class InterfacePtrState { |
| 23 public: | 22 public: |
| 24 InterfacePtrState() : proxy_(NULL), router_(NULL), waiter_(NULL) {} | 23 InterfacePtrState() : proxy_(NULL), router_(NULL), waiter_(NULL) {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 } | 38 } |
| 40 | 39 |
| 41 void Swap(InterfacePtrState* other) { | 40 void Swap(InterfacePtrState* other) { |
| 42 std::swap(other->proxy_, proxy_); | 41 std::swap(other->proxy_, proxy_); |
| 43 std::swap(other->router_, router_); | 42 std::swap(other->router_, router_); |
| 44 handle_.swap(other->handle_); | 43 handle_.swap(other->handle_); |
| 45 std::swap(other->waiter_, waiter_); | 44 std::swap(other->waiter_, waiter_); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { | 47 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { |
| 49 assert(!proxy_); | 48 MOJO_DCHECK(!proxy_); |
| 50 assert(!router_); | 49 MOJO_DCHECK(!router_); |
| 51 assert(!handle_.is_valid()); | 50 MOJO_DCHECK(!handle_.is_valid()); |
| 52 assert(!waiter_); | 51 MOJO_DCHECK(!waiter_); |
| 53 | 52 |
| 54 handle_ = handle.Pass(); | 53 handle_ = handle.Pass(); |
| 55 waiter_ = waiter; | 54 waiter_ = waiter; |
| 56 } | 55 } |
| 57 | 56 |
| 58 bool WaitForIncomingMethodCall() { | 57 bool WaitForIncomingMethodCall() { |
| 59 ConfigureProxyIfNecessary(); | 58 ConfigureProxyIfNecessary(); |
| 60 | 59 |
| 61 assert(router_); | 60 MOJO_DCHECK(router_); |
| 62 return router_->WaitForIncomingMessage(); | 61 return router_->WaitForIncomingMessage(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 ScopedMessagePipeHandle PassMessagePipe() { | 64 ScopedMessagePipeHandle PassMessagePipe() { |
| 66 if (router_) | 65 if (router_) |
| 67 return router_->PassMessagePipe(); | 66 return router_->PassMessagePipe(); |
| 68 | 67 |
| 69 waiter_ = NULL; | 68 waiter_ = NULL; |
| 70 return handle_.Pass(); | 69 return handle_.Pass(); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void set_client(typename Interface::Client* client) { | 72 void set_client(typename Interface::Client* client) { |
| 74 ConfigureProxyIfNecessary(); | 73 ConfigureProxyIfNecessary(); |
| 75 | 74 |
| 76 assert(proxy_); | 75 MOJO_DCHECK(proxy_); |
| 77 proxy_->stub.set_sink(client); | 76 proxy_->stub.set_sink(client); |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool encountered_error() const { | 79 bool encountered_error() const { |
| 81 return router_ ? router_->encountered_error() : false; | 80 return router_ ? router_->encountered_error() : false; |
| 82 } | 81 } |
| 83 | 82 |
| 84 void set_error_handler(ErrorHandler* error_handler) { | 83 void set_error_handler(ErrorHandler* error_handler) { |
| 85 ConfigureProxyIfNecessary(); | 84 ConfigureProxyIfNecessary(); |
| 86 | 85 |
| 87 assert(router_); | 86 MOJO_DCHECK(router_); |
| 88 router_->set_error_handler(error_handler); | 87 router_->set_error_handler(error_handler); |
| 89 } | 88 } |
| 90 | 89 |
| 91 Router* router_for_testing() { | 90 Router* router_for_testing() { |
| 92 ConfigureProxyIfNecessary(); | 91 ConfigureProxyIfNecessary(); |
| 93 return router_; | 92 return router_; |
| 94 } | 93 } |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 class ProxyWithStub : public Interface::Proxy_ { | 96 class ProxyWithStub : public Interface::Proxy_ { |
| 98 public: | 97 public: |
| 99 explicit ProxyWithStub(MessageReceiverWithResponder* receiver) | 98 explicit ProxyWithStub(MessageReceiverWithResponder* receiver) |
| 100 : Interface::Proxy_(receiver) { | 99 : Interface::Proxy_(receiver) { |
| 101 } | 100 } |
| 102 typename Interface::Client::Stub_ stub; | 101 typename Interface::Client::Stub_ stub; |
| 103 private: | 102 private: |
| 104 MOJO_DISALLOW_COPY_AND_ASSIGN(ProxyWithStub); | 103 MOJO_DISALLOW_COPY_AND_ASSIGN(ProxyWithStub); |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 void ConfigureProxyIfNecessary() { | 106 void ConfigureProxyIfNecessary() { |
| 108 // The proxy has been configured. | 107 // The proxy has been configured. |
| 109 if (proxy_) { | 108 if (proxy_) { |
| 110 assert(router_); | 109 MOJO_DCHECK(router_); |
| 111 return; | 110 return; |
| 112 } | 111 } |
| 113 // The object hasn't been bound. | 112 // The object hasn't been bound. |
| 114 if (!waiter_) { | 113 if (!waiter_) { |
| 115 assert(!handle_.is_valid()); | 114 MOJO_DCHECK(!handle_.is_valid()); |
| 116 return; | 115 return; |
| 117 } | 116 } |
| 118 | 117 |
| 119 FilterChain filters; | 118 FilterChain filters; |
| 120 filters.Append<MessageHeaderValidator>(); | 119 filters.Append<MessageHeaderValidator>(); |
| 121 filters.Append<typename Interface::Client::RequestValidator_>(); | 120 filters.Append<typename Interface::Client::RequestValidator_>(); |
| 122 filters.Append<typename Interface::ResponseValidator_>(); | 121 filters.Append<typename Interface::ResponseValidator_>(); |
| 123 | 122 |
| 124 router_ = new Router(handle_.Pass(), filters.Pass(), waiter_); | 123 router_ = new Router(handle_.Pass(), filters.Pass(), waiter_); |
| 125 waiter_ = NULL; | 124 waiter_ = NULL; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 ScopedMessagePipeHandle handle_; | 138 ScopedMessagePipeHandle handle_; |
| 140 const MojoAsyncWaiter* waiter_; | 139 const MojoAsyncWaiter* waiter_; |
| 141 | 140 |
| 142 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 141 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
| 143 }; | 142 }; |
| 144 | 143 |
| 145 } // namespace internal | 144 } // namespace internal |
| 146 } // namespace mojo | 145 } // namespace mojo |
| 147 | 146 |
| 148 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ | 147 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
| OLD | NEW |