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

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

Issue 1889973002: Refactoring starting a resource load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 ASSERT(m_state != ConnectionStateReleased); 86 ASSERT(m_state != ConnectionStateReleased);
87 m_state = ConnectionStateReleased; 87 m_state = ConnectionStateReleased;
88 if (m_loader) { 88 if (m_loader) {
89 m_loader->cancel(); 89 m_loader->cancel();
90 m_loader.clear(); 90 m_loader.clear();
91 } 91 }
92 m_fetcher.clear(); 92 m_fetcher.clear();
93 } 93 }
94 94
95 void ResourceLoader::start(ResourceRequest& request) 95 void ResourceLoader::start(ResourceRequest& request, WebTaskRunner* loadingTaskR unner, bool defersLoading)
96 { 96 {
97 ASSERT(!m_loader); 97 ASSERT(!m_loader);
98
99 m_fetcher->willStartLoadingResource(m_resource.get(), this, request);
100 RELEASE_ASSERT(m_state == ConnectionStateNew); 98 RELEASE_ASSERT(m_state == ConnectionStateNew);
101 m_state = ConnectionStateStarted; 99 m_state = ConnectionStateStarted;
102 100
101 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer sLoading) {
Yoav Weiss 2016/04/20 08:52:08 Does that constitute a behavior change? I may be r
Nate Chapin 2016/05/18 23:56:04 No behavior change. I moved this from requestSynch
102 cancel();
103 return;
104 }
105
103 m_loader = adoptPtr(Platform::current()->createURLLoader()); 106 m_loader = adoptPtr(Platform::current()->createURLLoader());
104 m_loader->setDefersLoading(m_fetcher->defersLoading()); 107 m_loader->setDefersLoading(defersLoading);
105 ASSERT(m_loader); 108 ASSERT(m_loader);
106 m_loader->setLoadingTaskRunner(m_fetcher->loadingTaskRunner()); 109 m_loader->setLoadingTaskRunner(loadingTaskRunner);
107 110
108 if (m_resource->options().synchronousPolicy == RequestSynchronously) 111 if (m_resource->options().synchronousPolicy == RequestSynchronously)
109 requestSynchronously(request); 112 requestSynchronously(request);
110 else 113 else
111 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); 114 m_loader->loadAsynchronously(WrappedResourceRequest(request), this);
112 } 115 }
113 116
114 void ResourceLoader::setDefersLoading(bool defers) 117 void ResourceLoader::setDefersLoading(bool defers)
115 { 118 {
116 ASSERT(m_loader); 119 ASSERT(m_loader);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 372
370 void ResourceLoader::requestSynchronously(ResourceRequest& request) 373 void ResourceLoader::requestSynchronously(ResourceRequest& request)
371 { 374 {
372 // downloadToFile is not supported for synchronous requests. 375 // downloadToFile is not supported for synchronous requests.
373 ASSERT(!request.downloadToFile()); 376 ASSERT(!request.downloadToFile());
374 ASSERT(m_loader); 377 ASSERT(m_loader);
375 378
376 // Synchronous requests should always be max priority, lest they hang the re nderer. 379 // Synchronous requests should always be max priority, lest they hang the re nderer.
377 request.setPriority(ResourceLoadPriorityHighest); 380 request.setPriority(ResourceLoadPriorityHighest);
378 381
379 if (m_fetcher->defersLoading()) {
380 cancel();
381 return;
382 }
383
384 WrappedResourceRequest requestIn(request); 382 WrappedResourceRequest requestIn(request);
385 WebURLResponse responseOut; 383 WebURLResponse responseOut;
386 responseOut.initialize(); 384 responseOut.initialize();
387 WebURLError errorOut; 385 WebURLError errorOut;
388 WebData dataOut; 386 WebData dataOut;
389 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); 387 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut);
390 if (errorOut.reason) { 388 if (errorOut.reason) {
391 if (m_state == ConnectionStateReleased) { 389 if (m_state == ConnectionStateReleased) {
392 // A message dispatched while synchronously fetching the resource 390 // A message dispatched while synchronously fetching the resource
393 // can bring about the cancellation of this load. 391 // can bring about the cancellation of this load.
(...skipping 14 matching lines...) Expand all
408 // empty buffer is a noop in most cases, but is destructive in the case of 406 // empty buffer is a noop in most cases, but is destructive in the case of
409 // a 304, where it will overwrite the cached data we should be reusing. 407 // a 304, where it will overwrite the cached data we should be reusing.
410 if (dataOut.size()) { 408 if (dataOut.size()) {
411 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength); 409 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size (), encodedDataLength);
412 m_resource->setResourceBuffer(dataOut); 410 m_resource->setResourceBuffer(dataOut);
413 } 411 }
414 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 412 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
415 } 413 }
416 414
417 } // namespace blink 415 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698