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

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

Issue 1735583002: Rename WeakBindingSet/WeakInterfacePtrSet to BindingSet/InterfacePtrSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/public/cpp/bindings/weak_binding_set.h ('k') | mojo/services/package_manager/package_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/weak_interface_ptr_set.h
diff --git a/mojo/public/cpp/bindings/weak_interface_ptr_set.h b/mojo/public/cpp/bindings/weak_interface_ptr_set.h
deleted file mode 100644
index f92a5edee91990718923a94f03836255dd10b9fd..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/weak_interface_ptr_set.h
+++ /dev/null
@@ -1,88 +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_PUBLIC_CPP_BINDINGS_WEAK_INTERFACE_PTR_SET_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_WEAK_INTERFACE_PTR_SET_H_
-
-#include <utility>
-#include <vector>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
-
-namespace mojo {
-
-template <typename Interface>
-class WeakInterfacePtr;
-
-template <typename Interface>
-class WeakInterfacePtrSet {
- public:
- WeakInterfacePtrSet() {}
- ~WeakInterfacePtrSet() { CloseAll(); }
-
- void AddInterfacePtr(InterfacePtr<Interface> ptr) {
- auto weak_interface_ptr = new WeakInterfacePtr<Interface>(std::move(ptr));
- ptrs_.push_back(weak_interface_ptr->GetWeakPtr());
- ClearNullInterfacePtrs();
- }
-
- template <typename FunctionType>
- void ForAllPtrs(FunctionType function) {
- for (const auto& it : ptrs_) {
- if (it)
- function(it->get());
- }
- ClearNullInterfacePtrs();
- }
-
- void CloseAll() {
- for (const auto& it : ptrs_) {
- if (it)
- it->Close();
- }
- ptrs_.clear();
- }
-
- private:
- using WPWIPI = base::WeakPtr<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_;
-};
-
-template <typename Interface>
-class WeakInterfacePtr {
- public:
- explicit WeakInterfacePtr(InterfacePtr<Interface> ptr)
- : ptr_(std::move(ptr)), 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 mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_WEAK_INTERFACE_PTR_SET_H_
« no previous file with comments | « mojo/public/cpp/bindings/weak_binding_set.h ('k') | mojo/services/package_manager/package_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698