Chromium Code Reviews| Index: third_party/WebKit/Source/core/fetch/Resource.cpp |
| diff --git a/third_party/WebKit/Source/core/fetch/Resource.cpp b/third_party/WebKit/Source/core/fetch/Resource.cpp |
| index 723beaef078e02bae7e48b631f91cd3c31c8ab38..af3623159fbe9d8091f512431d568271e1dc7a7f 100644 |
| --- a/third_party/WebKit/Source/core/fetch/Resource.cpp |
| +++ b/third_party/WebKit/Source/core/fetch/Resource.cpp |
| @@ -37,6 +37,7 @@ |
| #include "platform/InstanceCounters.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| #include "platform/SharedBuffer.h" |
| +#include "platform/WebTaskRunner.h" |
| #include "platform/network/HTTPParsers.h" |
| #include "platform/tracing/TraceEvent.h" |
| #include "platform/weborigin/KURL.h" |
| @@ -253,7 +254,7 @@ class Resource::ResourceCallback final { |
| ResourceCallback(); |
| void runTask(); |
| - std::unique_ptr<CancellableTaskFactory> m_callbackTaskFactory; |
| + TaskHandle m_taskHandle; |
| HashSet<Persistent<Resource>> m_resourcesWithPendingClients; |
| }; |
| @@ -262,26 +263,28 @@ Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler() { |
| return callbackHandler; |
| } |
| -Resource::ResourceCallback::ResourceCallback() |
| - : m_callbackTaskFactory( |
| - CancellableTaskFactory::create(this, &ResourceCallback::runTask)) {} |
| +Resource::ResourceCallback::ResourceCallback() {} |
| void Resource::ResourceCallback::schedule(Resource* resource) { |
| - if (!m_callbackTaskFactory->isPending()) { |
| - Platform::current() |
| - ->currentThread() |
| - ->scheduler() |
| - ->loadingTaskRunner() |
| - ->postTask(BLINK_FROM_HERE, m_callbackTaskFactory->cancelAndCreate()); |
| + if (!m_taskHandle.isActive()) { |
| + // unretained(this) is safe because a posted task is canceled when |
| + // |m_taskHandle| is destroyed on the dtor of this ResourceCallback. |
|
haraken
2016/11/16 04:22:55
tzik@: We prefer using wrapWeakPersistent(), right
tzik
2016/11/16 04:45:33
Since ResourceCallback is not GCed object, we need
haraken
2016/11/16 05:02:55
Makes sense.
BTW, what happens if we post a cance
nhiroki
2016/11/16 05:54:01
I guess the task just runs and then releases the r
|
| + m_taskHandle = |
| + Platform::current() |
|
haraken
2016/11/15 16:15:28
Can we use TaskRunnerHelper or ParentFrameTaskRunn
nhiroki
2016/11/15 22:31:49
I'd prefer to work on it in a separate CL because
|
| + ->currentThread() |
| + ->scheduler() |
| + ->loadingTaskRunner() |
| + ->postCancellableTask( |
| + BLINK_FROM_HERE, |
| + WTF::bind(&ResourceCallback::runTask, WTF::unretained(this))); |
| } |
| m_resourcesWithPendingClients.add(resource); |
| } |
| void Resource::ResourceCallback::cancel(Resource* resource) { |
| m_resourcesWithPendingClients.remove(resource); |
| - if (m_callbackTaskFactory->isPending() && |
| - m_resourcesWithPendingClients.isEmpty()) |
| - m_callbackTaskFactory->cancel(); |
| + if (m_taskHandle.isActive() && m_resourcesWithPendingClients.isEmpty()) |
| + m_taskHandle.cancel(); |
| } |
| bool Resource::ResourceCallback::isScheduled(Resource* resource) const { |