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

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: 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 m_taskHandle =
272 ->currentThread() 271 Platform::current()
273 ->scheduler() 272 ->currentThread()
274 ->loadingTaskRunner() 273 ->scheduler()
275 ->postTask(BLINK_FROM_HERE, m_callbackTaskFactory->cancelAndCreate()); 274 ->loadingTaskRunner()
275 ->postCancellableTask(
276 BLINK_FROM_HERE,
277 WTF::bind(&ResourceCallback::runTask, WTF::unretained(this)));
yhirano 2016/11/15 05:40:07 Please write a comment explaining why this unretai
nhiroki 2016/11/15 06:16:42 Done.
276 } 278 }
277 m_resourcesWithPendingClients.add(resource); 279 m_resourcesWithPendingClients.add(resource);
278 } 280 }
279 281
280 void Resource::ResourceCallback::cancel(Resource* resource) { 282 void Resource::ResourceCallback::cancel(Resource* resource) {
281 m_resourcesWithPendingClients.remove(resource); 283 m_resourcesWithPendingClients.remove(resource);
282 if (m_callbackTaskFactory->isPending() && 284 if (m_taskHandle.isActive() && m_resourcesWithPendingClients.isEmpty())
283 m_resourcesWithPendingClients.isEmpty()) 285 m_taskHandle.cancel();
284 m_callbackTaskFactory->cancel();
285 } 286 }
286 287
287 bool Resource::ResourceCallback::isScheduled(Resource* resource) const { 288 bool Resource::ResourceCallback::isScheduled(Resource* resource) const {
288 return m_resourcesWithPendingClients.contains(resource); 289 return m_resourcesWithPendingClients.contains(resource);
289 } 290 }
290 291
291 void Resource::ResourceCallback::runTask() { 292 void Resource::ResourceCallback::runTask() {
292 HeapVector<Member<Resource>> resources; 293 HeapVector<Member<Resource>> resources;
293 for (const Member<Resource>& resource : m_resourcesWithPendingClients) 294 for (const Member<Resource>& resource : m_resourcesWithPendingClients)
294 resources.append(resource.get()); 295 resources.append(resource.get());
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 case Resource::TextTrack: 1109 case Resource::TextTrack:
1109 case Resource::Media: 1110 case Resource::Media:
1110 case Resource::Manifest: 1111 case Resource::Manifest:
1111 return false; 1112 return false;
1112 } 1113 }
1113 NOTREACHED(); 1114 NOTREACHED();
1114 return false; 1115 return false;
1115 } 1116 }
1116 1117
1117 } // namespace blink 1118 } // 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