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

Unified Diff: mojo/common/weak_interface_ptr_set.h

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 9 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 | « mojo/common/weak_binding_set.h ('k') | mojo/converters/base/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/weak_interface_ptr_set.h
diff --git a/mojo/common/weak_interface_ptr_set.h b/mojo/common/weak_interface_ptr_set.h
deleted file mode 100644
index f93c0259574a7b7cadcd51023c41b902f31fc54a..0000000000000000000000000000000000000000
--- a/mojo/common/weak_interface_ptr_set.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_COMMON_WEAK_INTERFACE_PTR_SET_H_
-#define MOJO_COMMON_WEAK_INTERFACE_PTR_SET_H_
-
-#include <vector>
-
-#include "base/logging.h"
-#include "base/memory/weak_ptr.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
-
-namespace mojo {
-
-namespace internal {
-
-// TODO(vtl): This name of this class is a little odd -- it's not a "weak
-// pointer", but a wrapper around InterfacePtr that owns itself and can vend
-// weak pointers to itself. Probably, with connection error callbacks instead of
-// ErrorHandlers, this class is unneeded, and WeakInterfacePtrSet can simply
-// own/remove interface pointers as connection errors occur.
-// https://github.com/domokit/mojo/issues/311
-template <typename Interface>
-class WeakInterfacePtr {
- public:
- explicit WeakInterfacePtr(InterfacePtr<Interface> ptr)
- : ptr_(ptr.Pass()), weak_ptr_factory_(this) {
- ptr_.set_connection_error_handler([this]() { delete this; });
- }
- ~WeakInterfacePtr() {}
-
- void Close() { ptr_.reset(); }
-
- Interface* get() { return ptr_.get(); }
-
- base::WeakPtr<WeakInterfacePtr> GetWeakPtr() {
- return weak_ptr_factory_.GetWeakPtr();
- }
-
- private:
- InterfacePtr<Interface> ptr_;
- base::WeakPtrFactory<WeakInterfacePtr> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(WeakInterfacePtr);
-};
-
-} // namespace internal
-
-// A WeakInterfacePtrSet contains a collection of InterfacePtrs
-// that are automatically removed from the collection and destroyed
-// when their associated MessagePipe experiences a connection error.
-// When the set is destroyed all of the MessagePipes will be closed.
-// TODO(rudominer) Rename this class since the ownership of the elements
-// is not "weak" from the point of view of the client.
-template <typename Interface>
-class WeakInterfacePtrSet {
- public:
- WeakInterfacePtrSet() {}
- ~WeakInterfacePtrSet() { CloseAll(); }
-
- // |ptr| must be bound to a message pipe.
- void AddInterfacePtr(InterfacePtr<Interface> ptr) {
- DCHECK(ptr.is_bound());
- auto weak_interface_ptr =
- new internal::WeakInterfacePtr<Interface>(ptr.Pass());
- ptrs_.push_back(weak_interface_ptr->GetWeakPtr());
- ClearNullInterfacePtrs();
- }
-
- // Applies |function| to each of the InterfacePtrs in the set.
- template <typename FunctionType>
- void ForAllPtrs(FunctionType function) {
- for (const auto& it : ptrs_) {
- if (it)
- function(it->get());
- }
- ClearNullInterfacePtrs();
- }
-
- // Closes the MessagePipe associated with each of the InterfacePtrs in
- // this set and clears the set.
- void CloseAll() {
- for (const auto& it : ptrs_) {
- if (it)
- it->Close();
- }
- ptrs_.clear();
- }
-
- // TODO(rudominer) After reworking this class and eliminating the method
- // ClearNullInterfacePtrs, this method should become const.
- size_t size() {
- ClearNullInterfacePtrs();
- return ptrs_.size();
- }
-
- private:
- using WPWIPI = base::WeakPtr<internal::WeakInterfacePtr<Interface>>;
-
- void ClearNullInterfacePtrs() {
- ptrs_.erase(std::remove_if(ptrs_.begin(), ptrs_.end(), [](const WPWIPI& p) {
- return p.get() == nullptr;
- }), ptrs_.end());
- }
-
- std::vector<WPWIPI> ptrs_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_COMMON_WEAK_INTERFACE_PTR_SET_H_
« no previous file with comments | « mojo/common/weak_binding_set.h ('k') | mojo/converters/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698