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

Unified Diff: third_party/WebKit/Source/platform/heap/SelfKeepAlive.h

Issue 1999363002: Split out Members, Persistents and SelfKeepAlive in separate headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sof-gc-type
Patch Set: rebased Created 4 years, 7 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
Index: third_party/WebKit/Source/platform/heap/SelfKeepAlive.h
diff --git a/third_party/WebKit/Source/platform/heap/SelfKeepAlive.h b/third_party/WebKit/Source/platform/heap/SelfKeepAlive.h
new file mode 100644
index 0000000000000000000000000000000000000000..76c50b5a226af8527528191e66003be6b3fe4f7a
--- /dev/null
+++ b/third_party/WebKit/Source/platform/heap/SelfKeepAlive.h
@@ -0,0 +1,83 @@
+// 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 SelfKeepAlive_h
+#define SelfKeepAlive_h
+
+#include "platform/heap/Persistent.h"
+#include "wtf/Allocator.h"
+#include "wtf/Assertions.h"
+
+namespace blink {
+
+// SelfKeepAlive<Object> is the idiom to use for objects that have to keep
+// themselves temporarily alive and cannot rely on there being some
+// external reference in that interval:
+//
+// class Opener {
+// public:
+// ...
+// void open()
+// {
+// // Retain a self-reference while in an open()ed state:
+// m_keepAlive = this;
+// ....
+// }
+//
+// void close()
+// {
+// // Clear self-reference that ensured we were kept alive while opened.
+// m_keepAlive.clear();
+// ....
+// }
+//
+// private:
+// ...
+// SelfKeepAlive m_keepAlive;
+// };
+//
+// The responsibility to call clear() in a timely fashion resides with the implementation
+// of the object.
+//
+//
+template<typename Self>
+class SelfKeepAlive final {
+ DISALLOW_NEW();
+public:
+ SelfKeepAlive()
+ {
+ }
+
+ explicit SelfKeepAlive(Self* self)
+ {
+ assign(self);
+ }
+
+ SelfKeepAlive& operator=(Self* self)
+ {
+ assign(self);
+ return *this;
+ }
+
+ void clear()
+ {
+ m_keepAlive.clear();
+ }
+
+ explicit operator bool() const { return m_keepAlive; }
+
+private:
+ void assign(Self* self)
+ {
+ ASSERT(!m_keepAlive || m_keepAlive.get() == self);
+ m_keepAlive = self;
+ }
+
+ GC_PLUGIN_IGNORE("420515")
+ Persistent<Self> m_keepAlive;
+};
+
+} // namespace blink
+
+#endif // SelfKeepAlive_h
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Persistent.h ('k') | third_party/WebKit/Source/platform/heap/blink_heap.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698