| 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_IMPL_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/error_handler.h" | 8 #include "mojo/public/cpp/bindings/error_handler.h" |
| 9 #include "mojo/public/cpp/bindings/interface_ptr.h" | 9 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 10 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
| 11 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 10 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 11 | 13 |
| 12 namespace mojo { | 14 namespace mojo { |
| 13 namespace internal { | 15 namespace internal { |
| 14 | 16 |
| 15 template <typename Interface> | 17 template <typename Interface> |
| 16 class InterfaceImplState : public ErrorHandler { | 18 class InterfaceImplState : public ErrorHandler { |
| 17 public: | 19 public: |
| 18 typedef typename Interface::Client Client; | 20 typedef typename Interface::Client Client; |
| 19 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 40 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
| 39 MessagePipe pipe; | 41 MessagePipe pipe; |
| 40 ptr->Bind(pipe.handle0.Pass(), waiter); | 42 ptr->Bind(pipe.handle0.Pass(), waiter); |
| 41 Bind(pipe.handle1.Pass(), waiter); | 43 Bind(pipe.handle1.Pass(), waiter); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void Bind(ScopedMessagePipeHandle handle, | 46 void Bind(ScopedMessagePipeHandle handle, |
| 45 MojoAsyncWaiter* waiter) { | 47 MojoAsyncWaiter* waiter) { |
| 46 assert(!router_); | 48 assert(!router_); |
| 47 | 49 |
| 48 router_ = new Router(handle.Pass(), waiter); | 50 FilterChain filters; |
| 51 filters.Append(new MessageHeaderValidator) |
| 52 .Append(new typename Interface::RequestValidator_) |
| 53 .Append(new typename Interface::Client::ResponseValidator_); |
| 54 |
| 55 router_ = new Router(handle.Pass(), filters.Pass(), waiter); |
| 49 router_->set_incoming_receiver(&stub_); | 56 router_->set_incoming_receiver(&stub_); |
| 50 router_->set_error_handler(this); | 57 router_->set_error_handler(this); |
| 51 | 58 |
| 52 proxy_ = new typename Client::Proxy_(router_); | 59 proxy_ = new typename Client::Proxy_(router_); |
| 53 | 60 |
| 54 stub_.sink()->SetClient(proxy_); | 61 stub_.sink()->SetClient(proxy_); |
| 55 } | 62 } |
| 56 | 63 |
| 57 Router* router() { return router_; } | 64 Router* router() { return router_; } |
| 58 | 65 |
| 59 void set_client(Client* client) { client_ = client; } | 66 void set_client(Client* client) { client_ = client; } |
| 60 Client* client() { return client_; } | 67 Client* client() { return client_; } |
| 61 | 68 |
| 62 private: | 69 private: |
| 63 virtual void OnConnectionError() MOJO_OVERRIDE { | 70 virtual void OnConnectionError() MOJO_OVERRIDE { |
| 64 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> | 71 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> |
| 65 OnConnectionError(); | 72 OnConnectionError(); |
| 66 } | 73 } |
| 67 | 74 |
| 68 internal::Router* router_; | 75 Router* router_; |
| 69 Client* client_; | 76 Client* client_; |
| 70 typename Client::Proxy_* proxy_; | 77 typename Client::Proxy_* proxy_; |
| 71 typename Interface::Stub_ stub_; | 78 typename Interface::Stub_ stub_; |
| 72 | 79 |
| 73 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); | 80 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 } // namespace internal | 83 } // namespace internal |
| 77 } // namespace mojo | 84 } // namespace mojo |
| 78 | 85 |
| 79 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 86 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
| OLD | NEW |