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_COMMON_WEAK_BINDING_SET_H_ | 5 #ifndef MOJO_COMMON_WEAK_BINDING_SET_H_ |
6 #define MOJO_COMMON_WEAK_BINDING_SET_H_ | 6 #define MOJO_COMMON_WEAK_BINDING_SET_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 template <typename Interface> | 21 template <typename Interface> |
22 class WeakBindingSet { | 22 class WeakBindingSet { |
23 public: | 23 public: |
24 WeakBindingSet() {} | 24 WeakBindingSet() {} |
25 ~WeakBindingSet() { CloseAllBindings(); } | 25 ~WeakBindingSet() { CloseAllBindings(); } |
26 | 26 |
27 void set_connection_error_handler(const Closure& error_handler) { | 27 void set_connection_error_handler(const Closure& error_handler) { |
28 error_handler_ = error_handler; | 28 error_handler_ = error_handler; |
29 } | 29 } |
30 | 30 |
31 // NOTE: Deprecated. Please use the method above. | |
32 // TODO(yzshen): Remove this method once all callsites are converted. | |
33 void set_error_handler(ErrorHandler* error_handler) { | |
34 if (error_handler) { | |
35 set_connection_error_handler( | |
36 [error_handler]() { error_handler->OnConnectionError(); }); | |
37 } else { | |
38 set_connection_error_handler(Closure()); | |
39 } | |
40 } | |
41 | |
42 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) { | 31 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) { |
43 auto binding = new WeakBinding<Interface>(impl, request.Pass()); | 32 auto binding = new WeakBinding<Interface>(impl, request.Pass()); |
44 binding->set_connection_error_handler([this]() { OnConnectionError(); }); | 33 binding->set_connection_error_handler([this]() { OnConnectionError(); }); |
45 bindings_.push_back(binding->GetWeakPtr()); | 34 bindings_.push_back(binding->GetWeakPtr()); |
46 } | 35 } |
47 | 36 |
48 void CloseAllBindings() { | 37 void CloseAllBindings() { |
49 for (const auto& it : bindings_) { | 38 for (const auto& it : bindings_) { |
50 if (it) | 39 if (it) |
51 it->Close(); | 40 it->Close(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 Binding<Interface> binding_; | 94 Binding<Interface> binding_; |
106 Closure error_handler_; | 95 Closure error_handler_; |
107 base::WeakPtrFactory<WeakBinding> weak_ptr_factory_; | 96 base::WeakPtrFactory<WeakBinding> weak_ptr_factory_; |
108 | 97 |
109 DISALLOW_COPY_AND_ASSIGN(WeakBinding); | 98 DISALLOW_COPY_AND_ASSIGN(WeakBinding); |
110 }; | 99 }; |
111 | 100 |
112 } // namespace mojo | 101 } // namespace mojo |
113 | 102 |
114 #endif // MOJO_COMMON_WEAK_BINDING_SET_H_ | 103 #endif // MOJO_COMMON_WEAK_BINDING_SET_H_ |
OLD | NEW |