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_STRONG_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
11 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
12 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
14 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
15 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 16 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
16 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 17 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
17 #include "mojo/public/cpp/bindings/lib/router.h" | 18 #include "mojo/public/cpp/bindings/lib/router.h" |
18 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
19 | 20 |
20 namespace mojo { | 21 namespace mojo { |
(...skipping 20 matching lines...) Expand all Loading... |
41 // void Create(..., InterfaceRequest<Foo> request) override { | 42 // void Create(..., InterfaceRequest<Foo> request) override { |
42 // new StronglyBound(std::move(request)); // The binding now owns the | 43 // new StronglyBound(std::move(request)); // The binding now owns the |
43 // // instance of StronglyBound. | 44 // // instance of StronglyBound. |
44 // } | 45 // } |
45 // }; | 46 // }; |
46 // | 47 // |
47 // This class is thread hostile once it is bound to a message pipe. Until it is | 48 // This class is thread hostile once it is bound to a message pipe. Until it is |
48 // bound, it may be bound or destroyed on any thread. | 49 // bound, it may be bound or destroyed on any thread. |
49 template <typename Interface> | 50 template <typename Interface> |
50 class StrongBinding { | 51 class StrongBinding { |
51 MOVE_ONLY_TYPE_FOR_CPP_03(StrongBinding); | |
52 | |
53 public: | 52 public: |
54 explicit StrongBinding(Interface* impl) : binding_(impl) {} | 53 explicit StrongBinding(Interface* impl) : binding_(impl) {} |
55 | 54 |
56 StrongBinding(Interface* impl, ScopedMessagePipeHandle handle) | 55 StrongBinding(Interface* impl, ScopedMessagePipeHandle handle) |
57 : StrongBinding(impl) { | 56 : StrongBinding(impl) { |
58 Bind(std::move(handle)); | 57 Bind(std::move(handle)); |
59 } | 58 } |
60 | 59 |
61 StrongBinding(Interface* impl, InterfacePtr<Interface>* ptr) | 60 StrongBinding(Interface* impl, InterfacePtr<Interface>* ptr) |
62 : StrongBinding(impl) { | 61 : StrongBinding(impl) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 internal::Router* internal_router() { return binding_.internal_router(); } | 105 internal::Router* internal_router() { return binding_.internal_router(); } |
107 | 106 |
108 void OnConnectionError() { | 107 void OnConnectionError() { |
109 connection_error_handler_.Run(); | 108 connection_error_handler_.Run(); |
110 delete binding_.impl(); | 109 delete binding_.impl(); |
111 } | 110 } |
112 | 111 |
113 private: | 112 private: |
114 Closure connection_error_handler_; | 113 Closure connection_error_handler_; |
115 Binding<Interface> binding_; | 114 Binding<Interface> binding_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(StrongBinding); |
116 }; | 117 }; |
117 | 118 |
118 } // namespace mojo | 119 } // namespace mojo |
119 | 120 |
120 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 121 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
OLD | NEW |