Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: mojo/public/cpp/bindings/interface_ptr_set.h

Issue 1872903003: Generalize InterfacePtrSet for [Associated]InterfacePtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mash/session/session.cc ('k') | mojo/services/tracing/tracing_app.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « mash/session/session.cc ('k') | mojo/services/tracing/tracing_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698