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

Side by Side Diff: Source/platform/scheduler/CancellableTaskFactory.h

Issue 1171463006: Make Timer and CancellableTaskFactory embeddeable in lazily swept objects. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CancellableTaskFactory_h 5 #ifndef CancellableTaskFactory_h
6 #define CancellableTaskFactory_h 6 #define CancellableTaskFactory_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "public/platform/WebScheduler.h" 9 #include "public/platform/WebScheduler.h"
10 #include "wtf/AddressSanitizer.h"
10 #include "wtf/Functional.h" 11 #include "wtf/Functional.h"
11 #include "wtf/Noncopyable.h" 12 #include "wtf/Noncopyable.h"
12 #include "wtf/OwnPtr.h" 13 #include "wtf/OwnPtr.h"
13 #include "wtf/PassOwnPtr.h" 14 #include "wtf/PassOwnPtr.h"
14 #include "wtf/RefCounted.h" 15 #include "wtf/RefCounted.h"
15 #include "wtf/WeakPtr.h" 16 #include "wtf/WeakPtr.h"
16 17
17 namespace blink { 18 namespace blink {
18 class TraceLocation; 19 class TraceLocation;
19 20
20 class PLATFORM_EXPORT CancellableTaskFactory { 21 class PLATFORM_EXPORT CancellableTaskFactory {
21 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory); 22 WTF_MAKE_NONCOPYABLE(CancellableTaskFactory);
22 23
23 public: 24 public:
24 explicit CancellableTaskFactory(PassOwnPtr<Closure> closure) 25 explicit CancellableTaskFactory(PassOwnPtr<Closure> closure)
25 : m_closure(closure) 26 : m_closure(closure)
27 #if defined(ADDRESS_SANITIZER)
28 , m_unpoisonBeforeUpdate(false)
29 #endif
26 , m_weakPtrFactory(this) 30 , m_weakPtrFactory(this)
27 { 31 {
28 } 32 }
29 33
30 bool isPending() const 34 bool isPending() const
31 { 35 {
32 return m_weakPtrFactory.hasWeakPtrs(); 36 return m_weakPtrFactory.hasWeakPtrs();
33 } 37 }
34 38
35 void cancel(); 39 void cancel();
36 40
37 // Returns a task that can be disabled by calling cancel(). The user takes 41 // Returns a task that can be disabled by calling cancel(). The user takes
38 // ownership of the task. Creating a new task cancels any previous ones. 42 // ownership of the task. Creating a new task cancels any previous ones.
39 WebThread::Task* cancelAndCreate(); 43 WebThread::Task* cancelAndCreate();
40 44
45 #if defined(ADDRESS_SANITIZER)
46 // The CancellableTaskFactory part object might be within a poisoned heap
47 // object, hence CancellableTask::run() will access poisoned memory
48 // when reaching into the factory object to update its state.
49 // We will allow such access iff the task factory is marked as requiring
50 // unpoisoning first.
51 void setUnpoisonBeforeUpdate() { m_unpoisonBeforeUpdate = true; }
52 #endif
53
41 private: 54 private:
42 class CancellableTask : public WebThread::Task { 55 class CancellableTask : public WebThread::Task {
43 WTF_MAKE_NONCOPYABLE(CancellableTask); 56 WTF_MAKE_NONCOPYABLE(CancellableTask);
44 57
45 public: 58 public:
46 explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr) 59 explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr)
47 : m_weakPtr(weakPtr) { } 60 : m_weakPtr(weakPtr) { }
48 61
49 virtual ~CancellableTask() { } 62 virtual ~CancellableTask() { }
50 63
51 void run() override; 64 void run() override;
52 65
53 private: 66 private:
54 WeakPtr<CancellableTaskFactory> m_weakPtr; 67 WeakPtr<CancellableTaskFactory> m_weakPtr;
55 }; 68 };
56 69
57 OwnPtr<Closure> m_closure; 70 OwnPtr<Closure> m_closure;
71 #if defined(ADDRESS_SANITIZER)
72 bool m_unpoisonBeforeUpdate;
73 #endif
58 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory; 74 WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory;
59 }; 75 };
60 76
61 } // namespace blink 77 } // namespace blink
62 78
63 #endif // CancellableTaskFactory_h 79 #endif // CancellableTaskFactory_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698