summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:20:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:28:57 +0000
commitd17ea114e5ef69ad5d5d7413280a13e6428098aa (patch)
tree2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h
parent8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff)
downloadqtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h')
-rw-r--r--chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h b/chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h
new file mode 100644
index 00000000000..5e60054db89
--- /dev/null
+++ b/chromium/third_party/blink/renderer/platform/heap/self_keep_alive.h
@@ -0,0 +1,74 @@
+// 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_SELF_KEEP_ALIVE_H_
+#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_SELF_KEEP_ALIVE_H_
+
+#include "third_party/blink/renderer/platform/heap/persistent.h"
+#include "third_party/blink/renderer/platform/wtf/allocator.h"
+#include "third_party/blink/renderer/platform/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() = default;
+
+ explicit SelfKeepAlive(Self* self) { Assign(self); }
+
+ SelfKeepAlive& operator=(Self* self) {
+ Assign(self);
+ return *this;
+ }
+
+ void Clear() { keep_alive_.Clear(); }
+
+ explicit operator bool() const { return keep_alive_; }
+
+ private:
+ void Assign(Self* self) {
+ DCHECK(!keep_alive_ || keep_alive_.Get() == self);
+ keep_alive_ = self;
+ }
+
+ GC_PLUGIN_IGNORE("420515")
+ Persistent<Self> keep_alive_;
+};
+
+} // namespace blink
+
+#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_SELF_KEEP_ALIVE_H_