Index: Source/wtf/UnretainedPtr.h |
diff --git a/Source/wtf/UnretainedPtr.h b/Source/wtf/UnretainedPtr.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e8c7410fa70da8fbda563a787a8ebe8a219c5d7 |
--- /dev/null |
+++ b/Source/wtf/UnretainedPtr.h |
@@ -0,0 +1,43 @@ |
+// 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 WTF_UnretainedPtr_h |
+#define WTF_UnretainedPtr_h |
+ |
+// UnretainedPtr should be used when a pointer of a GarbageCollected object |
+// is passed to a thread (via postTask) that is not attached to Blink GC. |
+// |
+// postTask(new Task(WTF::bind(&function, UnretainedPtr<GarbageCollectedObject>(this)))); |
+// |
+// Without UnretainedPtr specified, the target thread keeps |this| pointer alive |
+// by creating a CrossThreadPersistent handle for the pointer. With |
+// UnretainedPtr specified, the target thread doesn't keep |this| pointer alive. |
+// |
+// If the target thread is not attached to Blink GC, the thread is not allowed |
+// to create a CrossThreadPersistent handle, so you need to specify |
+// UnretainedPtr. In this case, you need to write code so that |this| pointer |
+// is kept alive until the target thread finishes processing the task. |
+ |
+namespace WTF { |
+ |
+template<typename T> |
+class UnretainedPtr { |
+ WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(UnretainedPtr); |
+ WTF_DISALLOW_ZERO_ASSIGNMENT(UnretainedPtr); |
+public: |
+ UnretainedPtr(std::nullptr_t) : m_ptr(0) { } |
+ UnretainedPtr(T* ptr) : m_ptr(ptr) { } |
+ operator T*() const { return m_ptr; } |
+ template<typename U> |
+ operator RawPtr<U>() const { return m_ptr; } |
+ |
+private: |
+ T* m_ptr; |
+}; |
+ |
+} // namespace WTF |
+ |
+using WTF::UnretainedPtr; |
+ |
+#endif |