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

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: Put PtrSet in mojo::internal. 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..69fc8249cd40c3f6dc756792ea92a8b49ca2b6c4 100644
--- a/mojo/public/cpp/bindings/interface_ptr_set.h
+++ b/mojo/public/cpp/bindings/interface_ptr_set.h
@@ -10,20 +10,22 @@
#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 {
+namespace internal {
-template <typename Interface>
-class InterfacePtrSet {
+template <typename Interface, template <typename> class Ptr>
+class PtrSet {
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 +34,7 @@ class InterfacePtrSet {
if (it)
function(it->get());
}
- ClearNullInterfacePtrs();
+ ClearNullPtrs();
}
void CloseAll() {
@@ -46,7 +48,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 +63,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 +80,15 @@ class InterfacePtrSet {
std::vector<base::WeakPtr<Element>> ptrs_;
};
+} // namespace internal
+
+template <typename Interface>
+using InterfacePtrSet = internal::PtrSet<Interface, InterfacePtr>;
+
+template <typename Interface>
+using AssociatedInterfacePtrSet =
+ internal::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