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/message_header_validator.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validator_chain.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 explicit InterfaceImplState(WithErrorHandler<Interface>* instance) | 20 explicit InterfaceImplState(WithErrorHandler<Interface>* instance) |
19 : router_(NULL), | 21 : router_(NULL), |
(...skipping 15 matching lines...) Expand all Loading... |
35 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 37 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
36 MessagePipe pipe; | 38 MessagePipe pipe; |
37 ptr->Bind(pipe.handle0.Pass(), waiter); | 39 ptr->Bind(pipe.handle0.Pass(), waiter); |
38 Bind(pipe.handle1.Pass(), waiter); | 40 Bind(pipe.handle1.Pass(), waiter); |
39 } | 41 } |
40 | 42 |
41 void Bind(ScopedMessagePipeHandle handle, | 43 void Bind(ScopedMessagePipeHandle handle, |
42 MojoAsyncWaiter* waiter) { | 44 MojoAsyncWaiter* waiter) { |
43 assert(!router_); | 45 assert(!router_); |
44 | 46 |
45 router_ = new Router(handle.Pass(), waiter); | 47 internal::ValidatorChain validators; |
| 48 validators.Append(new internal::MessageHeaderValidator) |
| 49 .Append(new typename Interface::RequestValidator_) |
| 50 .Append(new typename Interface::Client_::ResponseValidator_); |
| 51 |
| 52 router_ = new Router(handle.Pass(), validators.Pass(), waiter); |
46 router_->set_incoming_receiver(&stub_); | 53 router_->set_incoming_receiver(&stub_); |
47 router_->set_error_handler(this); | 54 router_->set_error_handler(this); |
48 | 55 |
49 proxy_ = new typename Interface::Client_::Proxy_(router_); | 56 proxy_ = new typename Interface::Client_::Proxy_(router_); |
50 | 57 |
51 stub_.sink()->SetClient(proxy_); | 58 stub_.sink()->SetClient(proxy_); |
52 } | 59 } |
53 | 60 |
54 Router* router() { return router_; } | 61 Router* router() { return router_; } |
55 | 62 |
56 private: | 63 private: |
57 virtual void OnConnectionError() MOJO_OVERRIDE { | 64 virtual void OnConnectionError() MOJO_OVERRIDE { |
58 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> | 65 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> |
59 OnConnectionError(); | 66 OnConnectionError(); |
60 } | 67 } |
61 | 68 |
62 internal::Router* router_; | 69 internal::Router* router_; |
63 typename Interface::Client_::Proxy_* proxy_; | 70 typename Interface::Client_::Proxy_* proxy_; |
64 typename Interface::Stub_ stub_; | 71 typename Interface::Stub_ stub_; |
65 | 72 |
66 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); | 73 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); |
67 }; | 74 }; |
68 | 75 |
69 } // namespace internal | 76 } // namespace internal |
70 } // namespace mojo | 77 } // namespace mojo |
71 | 78 |
72 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 79 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
OLD | NEW |