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

Unified Diff: mojo/edk/util/weak_ptr_internal.h

Issue 1646113002: Bring in a reduced/simplified version of Chromium's base::WeakPtr to //mojo/edk/util. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review Created 4 years, 11 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/edk/util/weak_ptr.h ('k') | mojo/edk/util/weak_ptr_internal.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/util/weak_ptr_internal.h
diff --git a/mojo/edk/util/weak_ptr_internal.h b/mojo/edk/util/weak_ptr_internal.h
new file mode 100644
index 0000000000000000000000000000000000000000..ed90d76606150c26daa2ae97ba8fc570599cbaa2
--- /dev/null
+++ b/mojo/edk/util/weak_ptr_internal.h
@@ -0,0 +1,44 @@
+// Copyright 2016 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_UTIL_WEAK_PTR_INTERNAL_H_
+#define MOJO_UTIL_WEAK_PTR_INTERNAL_H_
+
+#include <assert.h>
+
+#include "mojo/edk/util/ref_counted.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace util {
+namespace internal {
+
+// |WeakPtr<T>|s have a reference to a |WeakPtrFlag| to determine whether they
+// are valid (non-null) or not. We do not store a |T*| in this object since
+// there may also be |WeakPtr<U>|s to the same object, where |U| is a superclass
+// of |T|.
+//
+// This class in not thread-safe, though references may be released on any
+// thread (allowing weak pointers to be destroyed/reset/reassigned on any
+// thread).
+class WeakPtrFlag : public RefCountedThreadSafe<WeakPtrFlag> {
+ public:
+ WeakPtrFlag();
+ ~WeakPtrFlag();
+
+ bool is_valid() const { return is_valid_; }
+
+ void Invalidate();
+
+ private:
+ bool is_valid_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(WeakPtrFlag);
+};
+
+} // namespace internal
+} // namespace util
+} // namespace mojo
+
+#endif // MOJO_UTIL_WEAK_PTR_INTERNAL_H_
« no previous file with comments | « mojo/edk/util/weak_ptr.h ('k') | mojo/edk/util/weak_ptr_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698