| 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 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) { | 31 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) { |
| 32 auto binding = new WeakBinding<Interface>(impl, request.Pass()); | 32 auto binding = new WeakBinding<Interface>(impl, request.Pass()); |
| 33 binding->set_connection_error_handler([this]() { OnConnectionError(); }); | 33 binding->set_connection_error_handler([this]() { OnConnectionError(); }); |
| 34 bindings_.push_back(binding->GetWeakPtr()); | 34 bindings_.push_back(binding->GetWeakPtr()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void CloseAllBindings() { | 37 void CloseAllBindings() { |
| 38 for (const auto& it : bindings_) { | 38 for (const auto& it : bindings_) { |
| 39 if (it) | 39 if (it) { |
| 40 it->Close(); | 40 it->Close(); |
| 41 delete it.get(); |
| 42 } |
| 41 } | 43 } |
| 42 bindings_.clear(); | 44 bindings_.clear(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 bool empty() const { return bindings_.empty(); } | 47 bool empty() const { return bindings_.empty(); } |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 void OnConnectionError() { | 50 void OnConnectionError() { |
| 49 // Clear any deleted bindings. | 51 // Clear any deleted bindings. |
| 50 bindings_.erase( | 52 bindings_.erase( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 Binding<Interface> binding_; | 96 Binding<Interface> binding_; |
| 95 Closure error_handler_; | 97 Closure error_handler_; |
| 96 base::WeakPtrFactory<WeakBinding> weak_ptr_factory_; | 98 base::WeakPtrFactory<WeakBinding> weak_ptr_factory_; |
| 97 | 99 |
| 98 DISALLOW_COPY_AND_ASSIGN(WeakBinding); | 100 DISALLOW_COPY_AND_ASSIGN(WeakBinding); |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 } // namespace mojo | 103 } // namespace mojo |
| 102 | 104 |
| 103 #endif // MOJO_COMMON_WEAK_BINDING_SET_H_ | 105 #endif // MOJO_COMMON_WEAK_BINDING_SET_H_ |
| OLD | NEW |