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

Unified Diff: mojo/common/weak_interface_ptr_set.h

Issue 1237653005: Rename WeakInterfacePtrSet to InterfacePtrSet. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Responding to code review take 2. Created 5 years, 5 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/interface_ptr_set_unittest.cc ('k') | mojo/common/weak_interface_ptr_set_unittest.cc » ('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 b668a461993ff19880b2a305bd57ad427fe1cca1..0000000000000000000000000000000000000000
--- a/mojo/common/weak_interface_ptr_set.h
+++ /dev/null
@@ -1,75 +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 {
-
-// 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());
- ptrs_.emplace_back(ptr.Pass());
- InterfacePtr<Interface>& intrfc_ptr = ptrs_.back();
- Interface* pointer = intrfc_ptr.get();
- // Set the connection error handler for the newly added InterfacePtr to be a
- // function that will erase it from the vector.
- intrfc_ptr.set_connection_error_handler([pointer, this]() {
- // Since InterfacePtr itself is a movable type, the thing that uniquely
- // identifies the InterfacePtr we wish to erase is its Interface*.
- auto it = std::find_if(ptrs_.begin(), ptrs_.end(),
- [pointer](const InterfacePtr<Interface>& p) {
- return (p.get() == pointer);
- });
- DCHECK(it != ptrs_.end());
- ptrs_.erase(it);
- });
- }
-
- // 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());
- }
- }
-
- // Closes the MessagePipe associated with each of the InterfacePtrs in
- // this set and clears the set.
- void CloseAll() {
- for (auto& it : ptrs_) {
- if (it)
- it.reset();
- }
- ptrs_.clear();
- }
-
- size_t size() const { return ptrs_.size(); }
-
- private:
- std::vector<InterfacePtr<Interface>> ptrs_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_COMMON_WEAK_INTERFACE_PTR_SET_H_
« no previous file with comments | « mojo/common/interface_ptr_set_unittest.cc ('k') | mojo/common/weak_interface_ptr_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698