| 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_STRONG_BINDING_SET_H_ | 5 #ifndef MOJO_COMMON_STRONG_BINDING_SET_H_ |
| 6 #define MOJO_COMMON_STRONG_BINDING_SET_H_ | 6 #define MOJO_COMMON_STRONG_BINDING_SET_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 std::find_if(bindings_.begin(), bindings_.end(), | 37 std::find_if(bindings_.begin(), bindings_.end(), |
| 38 [binding](const std::unique_ptr<Binding<Interface>>& b) { | 38 [binding](const std::unique_ptr<Binding<Interface>>& b) { |
| 39 return (b.get() == binding); | 39 return (b.get() == binding); |
| 40 }); | 40 }); |
| 41 DCHECK(it != bindings_.end()); | 41 DCHECK(it != bindings_.end()); |
| 42 delete binding->impl(); | 42 delete binding->impl(); |
| 43 bindings_.erase(it); | 43 bindings_.erase(it); |
| 44 }); | 44 }); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Removes all bindings for the specified interface implementation. |
| 48 // The implementation object is not destroyed. |
| 49 void RemoveBindings(Interface* impl) { |
| 50 bindings_.erase( |
| 51 std::remove_if(bindings_.begin(), bindings_.end(), |
| 52 [impl](const std::unique_ptr<Binding<Interface>>& b) { |
| 53 return (b->impl() == impl); |
| 54 })); |
| 55 } |
| 56 |
| 47 // Closes all bindings and deletes their associated interfaces. | 57 // Closes all bindings and deletes their associated interfaces. |
| 48 void CloseAllBindings() { | 58 void CloseAllBindings() { |
| 49 for (auto it = bindings_.begin(); it != bindings_.end(); ++it) { | 59 for (auto it = bindings_.begin(); it != bindings_.end(); ++it) { |
| 50 delete (*it)->impl(); | 60 delete (*it)->impl(); |
| 51 } | 61 } |
| 52 bindings_.clear(); | 62 bindings_.clear(); |
| 53 } | 63 } |
| 54 | 64 |
| 55 size_t size() const { return bindings_.size(); } | 65 size_t size() const { return bindings_.size(); } |
| 56 | 66 |
| 57 private: | 67 private: |
| 58 std::vector<std::unique_ptr<Binding<Interface>>> bindings_; | 68 std::vector<std::unique_ptr<Binding<Interface>>> bindings_; |
| 59 | 69 |
| 60 DISALLOW_COPY_AND_ASSIGN(StrongBindingSet); | 70 DISALLOW_COPY_AND_ASSIGN(StrongBindingSet); |
| 61 }; | 71 }; |
| 62 | 72 |
| 63 } // namespace mojo | 73 } // namespace mojo |
| 64 | 74 |
| 65 #endif // MOJO_COMMON_STRONG_BINDING_SET_H_ | 75 #endif // MOJO_COMMON_STRONG_BINDING_SET_H_ |
| OLD | NEW |