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

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 2506553002: Scheduler: Deprecate CancellableTaskFactory in favor of WebTaskRunner::postCancellableTask (Closed)
Patch Set: add comments Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
7 rights reserved. 7 rights reserved.
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 19 matching lines...) Expand all
30 #include "core/fetch/FetchRequest.h" 30 #include "core/fetch/FetchRequest.h"
31 #include "core/fetch/IntegrityMetadata.h" 31 #include "core/fetch/IntegrityMetadata.h"
32 #include "core/fetch/MemoryCache.h" 32 #include "core/fetch/MemoryCache.h"
33 #include "core/fetch/ResourceClient.h" 33 #include "core/fetch/ResourceClient.h"
34 #include "core/fetch/ResourceClientWalker.h" 34 #include "core/fetch/ResourceClientWalker.h"
35 #include "core/fetch/ResourceLoader.h" 35 #include "core/fetch/ResourceLoader.h"
36 #include "platform/Histogram.h" 36 #include "platform/Histogram.h"
37 #include "platform/InstanceCounters.h" 37 #include "platform/InstanceCounters.h"
38 #include "platform/RuntimeEnabledFeatures.h" 38 #include "platform/RuntimeEnabledFeatures.h"
39 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
40 #include "platform/WebTaskRunner.h"
40 #include "platform/network/HTTPParsers.h" 41 #include "platform/network/HTTPParsers.h"
41 #include "platform/tracing/TraceEvent.h" 42 #include "platform/tracing/TraceEvent.h"
42 #include "platform/weborigin/KURL.h" 43 #include "platform/weborigin/KURL.h"
43 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
44 #include "public/platform/WebCachePolicy.h" 45 #include "public/platform/WebCachePolicy.h"
45 #include "public/platform/WebScheduler.h" 46 #include "public/platform/WebScheduler.h"
46 #include "public/platform/WebSecurityOrigin.h" 47 #include "public/platform/WebSecurityOrigin.h"
47 #include "wtf/CurrentTime.h" 48 #include "wtf/CurrentTime.h"
48 #include "wtf/MathExtras.h" 49 #include "wtf/MathExtras.h"
49 #include "wtf/StdLibExtras.h" 50 #include "wtf/StdLibExtras.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 public: 247 public:
247 static ResourceCallback& callbackHandler(); 248 static ResourceCallback& callbackHandler();
248 void schedule(Resource*); 249 void schedule(Resource*);
249 void cancel(Resource*); 250 void cancel(Resource*);
250 bool isScheduled(Resource*) const; 251 bool isScheduled(Resource*) const;
251 252
252 private: 253 private:
253 ResourceCallback(); 254 ResourceCallback();
254 255
255 void runTask(); 256 void runTask();
256 std::unique_ptr<CancellableTaskFactory> m_callbackTaskFactory; 257 TaskHandle m_taskHandle;
257 HashSet<Persistent<Resource>> m_resourcesWithPendingClients; 258 HashSet<Persistent<Resource>> m_resourcesWithPendingClients;
258 }; 259 };
259 260
260 Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler() { 261 Resource::ResourceCallback& Resource::ResourceCallback::callbackHandler() {
261 DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, ()); 262 DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, ());
262 return callbackHandler; 263 return callbackHandler;
263 } 264 }
264 265
265 Resource::ResourceCallback::ResourceCallback() 266 Resource::ResourceCallback::ResourceCallback() {}
266 : m_callbackTaskFactory(
267 CancellableTaskFactory::create(this, &ResourceCallback::runTask)) {}
268 267
269 void Resource::ResourceCallback::schedule(Resource* resource) { 268 void Resource::ResourceCallback::schedule(Resource* resource) {
270 if (!m_callbackTaskFactory->isPending()) { 269 if (!m_taskHandle.isActive()) {
271 Platform::current() 270 // unretained(this) is safe because a posted task is canceled when
272 ->currentThread() 271 // |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
273 ->scheduler() 272 m_taskHandle =
274 ->loadingTaskRunner() 273 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
275 ->postTask(BLINK_FROM_HERE, m_callbackTaskFactory->cancelAndCreate()); 274 ->currentThread()
275 ->scheduler()
276 ->loadingTaskRunner()
277 ->postCancellableTask(
278 BLINK_FROM_HERE,
279 WTF::bind(&ResourceCallback::runTask, WTF::unretained(this)));
276 } 280 }
277 m_resourcesWithPendingClients.add(resource); 281 m_resourcesWithPendingClients.add(resource);
278 } 282 }
279 283
280 void Resource::ResourceCallback::cancel(Resource* resource) { 284 void Resource::ResourceCallback::cancel(Resource* resource) {
281 m_resourcesWithPendingClients.remove(resource); 285 m_resourcesWithPendingClients.remove(resource);
282 if (m_callbackTaskFactory->isPending() && 286 if (m_taskHandle.isActive() && m_resourcesWithPendingClients.isEmpty())
283 m_resourcesWithPendingClients.isEmpty()) 287 m_taskHandle.cancel();
284 m_callbackTaskFactory->cancel();
285 } 288 }
286 289
287 bool Resource::ResourceCallback::isScheduled(Resource* resource) const { 290 bool Resource::ResourceCallback::isScheduled(Resource* resource) const {
288 return m_resourcesWithPendingClients.contains(resource); 291 return m_resourcesWithPendingClients.contains(resource);
289 } 292 }
290 293
291 void Resource::ResourceCallback::runTask() { 294 void Resource::ResourceCallback::runTask() {
292 HeapVector<Member<Resource>> resources; 295 HeapVector<Member<Resource>> resources;
293 for (const Member<Resource>& resource : m_resourcesWithPendingClients) 296 for (const Member<Resource>& resource : m_resourcesWithPendingClients)
294 resources.append(resource.get()); 297 resources.append(resource.get());
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 case Resource::TextTrack: 1111 case Resource::TextTrack:
1109 case Resource::Media: 1112 case Resource::Media:
1110 case Resource::Manifest: 1113 case Resource::Manifest:
1111 return false; 1114 return false;
1112 } 1115 }
1113 NOTREACHED(); 1116 NOTREACHED();
1114 return false; 1117 return false;
1115 } 1118 }
1116 1119
1117 } // namespace blink 1120 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/html/HTMLMediaElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698