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> | 8 #include <assert.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
11 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 11 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
12 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 12 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
13 #include "mojo/public/cpp/bindings/lib/router.h" | 13 #include "mojo/public/cpp/bindings/lib/router.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 template <typename Interface> | 19 template <typename Interface> |
19 class InterfacePtrState { | 20 class InterfacePtrState { |
20 public: | 21 public: |
21 InterfacePtrState() : proxy_(NULL), router_(NULL) {} | 22 InterfacePtrState() : proxy_(NULL), router_(NULL) {} |
22 | 23 |
23 ~InterfacePtrState() { | 24 ~InterfacePtrState() { |
24 // Destruction order matters here. We delete |proxy_| first, even though | 25 // Destruction order matters here. We delete |proxy_| first, even though |
25 // |router_| may have a reference to it, so that |~Interface| may have a | 26 // |router_| may have a reference to it, so that |~Interface| may have a |
26 // shot at generating new outbound messages (ie, invoking client methods). | 27 // shot at generating new outbound messages (ie, invoking client methods). |
27 delete proxy_; | 28 delete proxy_; |
28 delete router_; | 29 delete router_; |
29 } | 30 } |
30 | 31 |
31 Interface* instance() const { return proxy_; } | 32 Interface* instance() const { return proxy_; } |
32 | 33 |
33 Router* router() const { return router_; } | 34 Router* router() const { return router_; } |
34 | 35 |
35 void Swap(InterfacePtrState* other) { | 36 void Swap(InterfacePtrState* other) { |
36 std::swap(other->proxy_, proxy_); | 37 std::swap(other->proxy_, proxy_); |
37 std::swap(other->router_, router_); | 38 std::swap(other->router_, router_); |
38 } | 39 } |
39 | 40 |
40 void ConfigureProxy(ScopedMessagePipeHandle handle, | 41 void ConfigureProxy( |
41 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 42 ScopedMessagePipeHandle handle, |
| 43 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
42 assert(!proxy_); | 44 assert(!proxy_); |
43 assert(!router_); | 45 assert(!router_); |
44 | 46 |
45 FilterChain filters; | 47 FilterChain filters; |
46 filters.Append<MessageHeaderValidator>(); | 48 filters.Append<MessageHeaderValidator>(); |
47 filters.Append<typename Interface::Client::RequestValidator_>(); | 49 filters.Append<typename Interface::Client::RequestValidator_>(); |
48 filters.Append<typename Interface::ResponseValidator_>(); | 50 filters.Append<typename Interface::ResponseValidator_>(); |
49 | 51 |
50 router_ = new Router(handle.Pass(), filters.Pass(), waiter); | 52 router_ = new Router(handle.Pass(), filters.Pass(), waiter); |
51 ProxyWithStub* proxy = new ProxyWithStub(router_); | 53 ProxyWithStub* proxy = new ProxyWithStub(router_); |
(...skipping 21 matching lines...) Expand all Loading... |
73 ProxyWithStub* proxy_; | 75 ProxyWithStub* proxy_; |
74 Router* router_; | 76 Router* router_; |
75 | 77 |
76 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 78 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
77 }; | 79 }; |
78 | 80 |
79 } // namespace internal | 81 } // namespace internal |
80 } // namespace mojo | 82 } // namespace mojo |
81 | 83 |
82 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ | 84 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
OLD | NEW |