Chromium Code Reviews| Index: mojo/public/cpp/bindings/interface_ptr_set.h |
| diff --git a/mojo/public/cpp/bindings/interface_ptr_set.h b/mojo/public/cpp/bindings/interface_ptr_set.h |
| index c5d402d7cfaf51571c418c3460c2ee7d71fc24f6..000d2a6521acd6af162ad23f877fd9fffb8cc115 100644 |
| --- a/mojo/public/cpp/bindings/interface_ptr_set.h |
| +++ b/mojo/public/cpp/bindings/interface_ptr_set.h |
| @@ -10,20 +10,21 @@ |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| #include "mojo/public/cpp/bindings/interface_ptr.h" |
| namespace mojo { |
| -template <typename Interface> |
| -class InterfacePtrSet { |
| +template <typename Interface, template <typename> class Ptr> |
| +class PtrSet { |
|
yzshen1
2016/04/08 20:52:56
Please put this in mojo::internal namespace.
msw
2016/04/08 21:12:14
Done.
|
| public: |
| - InterfacePtrSet() {} |
| - ~InterfacePtrSet() { CloseAll(); } |
| + PtrSet() {} |
| + ~PtrSet() { CloseAll(); } |
| - void AddInterfacePtr(InterfacePtr<Interface> ptr) { |
| + void AddPtr(Ptr<Interface> ptr) { |
| auto weak_interface_ptr = new Element(std::move(ptr)); |
| ptrs_.push_back(weak_interface_ptr->GetWeakPtr()); |
| - ClearNullInterfacePtrs(); |
| + ClearNullPtrs(); |
| } |
| template <typename FunctionType> |
| @@ -32,7 +33,7 @@ class InterfacePtrSet { |
| if (it) |
| function(it->get()); |
| } |
| - ClearNullInterfacePtrs(); |
| + ClearNullPtrs(); |
| } |
| void CloseAll() { |
| @@ -46,7 +47,7 @@ class InterfacePtrSet { |
| private: |
| class Element { |
| public: |
| - explicit Element(InterfacePtr<Interface> ptr) |
| + explicit Element(Ptr<Interface> ptr) |
| : ptr_(std::move(ptr)), weak_ptr_factory_(this) { |
| ptr_.set_connection_error_handler([this]() { delete this; }); |
| } |
| @@ -61,13 +62,13 @@ class InterfacePtrSet { |
| } |
| private: |
| - InterfacePtr<Interface> ptr_; |
| + Ptr<Interface> ptr_; |
| base::WeakPtrFactory<Element> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(Element); |
| }; |
| - void ClearNullInterfacePtrs() { |
| + void ClearNullPtrs() { |
| ptrs_.erase(std::remove_if(ptrs_.begin(), ptrs_.end(), |
| [](const base::WeakPtr<Element>& p) { |
| return p.get() == nullptr; |
| @@ -78,6 +79,12 @@ class InterfacePtrSet { |
| std::vector<base::WeakPtr<Element>> ptrs_; |
| }; |
| +template <typename Interface> |
| +using InterfacePtrSet = PtrSet<Interface, InterfacePtr>; |
| + |
| +template <typename Interface> |
| +using AssociatedInterfacePtrSet = PtrSet<Interface, AssociatedInterfacePtr>; |
| + |
| } // namespace mojo |
| #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_SET_H_ |