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

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

Issue 695943002: Reland "Prepare blink to unify definitions of load completion" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderHost.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 void ResourceLoader::trace(Visitor* visitor) 95 void ResourceLoader::trace(Visitor* visitor)
96 { 96 {
97 visitor->trace(m_host); 97 visitor->trace(m_host);
98 visitor->trace(m_resource); 98 visitor->trace(m_resource);
99 } 99 }
100 100
101 void ResourceLoader::releaseResources() 101 void ResourceLoader::releaseResources()
102 { 102 {
103 ASSERT(m_state != Terminated); 103 ASSERT(m_state != Terminated);
104 ASSERT(m_notifiedLoadComplete); 104 ASSERT(m_notifiedLoadComplete);
105 m_requestCountTracker.clear(); 105 ASSERT(!m_requestCountTracker);
106 m_host->didLoadResource(m_resource); 106 m_host->didLoadResource();
107 if (m_state == Terminated) 107 if (m_state == Terminated)
108 return; 108 return;
109 m_resource->clearLoader(); 109 m_resource->clearLoader();
110 m_resource->deleteIfPossible(); 110 m_resource->deleteIfPossible();
111 m_resource = nullptr; 111 m_resource = nullptr;
112 m_host->willTerminateResourceLoader(this); 112 m_host->willTerminateResourceLoader(this);
113 113
114 ASSERT(m_state != Terminated); 114 ASSERT(m_state != Terminated);
115 115
116 // It's possible that when we release the loader, it will be 116 // It's possible that when we release the loader, it will be
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength) 227 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64_t encodedD ataLength)
228 { 228 {
229 // If load has been cancelled after finishing (which could happen with a 229 // If load has been cancelled after finishing (which could happen with a
230 // JavaScript that changes the window location), do nothing. 230 // JavaScript that changes the window location), do nothing.
231 if (m_state == Terminated) 231 if (m_state == Terminated)
232 return; 232 return;
233 233
234 if (m_notifiedLoadComplete) 234 if (m_notifiedLoadComplete)
235 return; 235 return;
236 m_notifiedLoadComplete = true; 236 didComplete();
237 m_host->didFinishLoading(m_resource, finishTime, encodedDataLength); 237 m_host->didFinishLoading(m_resource, finishTime, encodedDataLength);
238 } 238 }
239 239
240 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue) 240 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in traPriorityValue)
241 { 241 {
242 if (m_loader) { 242 if (m_loader) {
243 m_host->didChangeLoadingPriority(m_resource, loadPriority, intraPriority Value); 243 m_host->didChangeLoadingPriority(m_resource, loadPriority, intraPriority Value);
244 ASSERT(m_state != Terminated); 244 ASSERT(m_state != Terminated);
245 m_loader->didChangePriority(static_cast<blink::WebURLRequest::Priority>( loadPriority), intraPriorityValue); 245 m_loader->didChangePriority(static_cast<blink::WebURLRequest::Priority>( loadPriority), intraPriorityValue);
246 } 246 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 m_state = Finishing; 279 m_state = Finishing;
280 m_resource->setResourceError(nonNullError); 280 m_resource->setResourceError(nonNullError);
281 281
282 if (m_loader) { 282 if (m_loader) {
283 m_connectionState = ConnectionStateCanceled; 283 m_connectionState = ConnectionStateCanceled;
284 m_loader->cancel(); 284 m_loader->cancel();
285 m_loader.clear(); 285 m_loader.clear();
286 } 286 }
287 287
288 if (!m_notifiedLoadComplete) { 288 if (!m_notifiedLoadComplete) {
289 m_notifiedLoadComplete = true; 289 didComplete();
290 m_host->didFailLoading(m_resource, nonNullError); 290 m_host->didFailLoading(m_resource, nonNullError);
291 } 291 }
292 292
293 if (m_state == Finishing) 293 if (m_state == Finishing)
294 m_resource->error(Resource::LoadError); 294 m_resource->error(Resource::LoadError);
295 if (m_state != Terminated) 295 if (m_state != Terminated)
296 releaseResources(); 296 releaseResources();
297 } 297 }
298 298
299 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedNewRequest, const blink::WebURLResponse& passedRedirectResponse) 299 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedNewRequest, const blink::WebURLResponse& passedRedirectResponse)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 didFinishLoadingOnePart(0, blink::WebURLLoaderClient::kUnknownEncodedDat aLength); 416 didFinishLoadingOnePart(0, blink::WebURLLoaderClient::kUnknownEncodedDat aLength);
417 } 417 }
418 if (m_state == Terminated) 418 if (m_state == Terminated)
419 return; 419 return;
420 420
421 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors()) 421 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor eHTTPStatusCodeErrors())
422 return; 422 return;
423 m_state = Finishing; 423 m_state = Finishing;
424 424
425 if (!m_notifiedLoadComplete) { 425 if (!m_notifiedLoadComplete) {
426 m_notifiedLoadComplete = true; 426 didComplete();
427 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque st.url())); 427 m_host->didFailLoading(m_resource, ResourceError::cancelledError(m_reque st.url()));
428 } 428 }
429 429
430 ASSERT(m_state != Terminated); 430 ASSERT(m_state != Terminated);
431 m_resource->error(Resource::LoadError); 431 m_resource->error(Resource::LoadError);
432 cancel(); 432 cancel();
433 } 433 }
434 434
435 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int length, int encodedDataLength) 435 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int length, int encodedDataLength)
436 { 436 {
(...skipping 26 matching lines...) Expand all
463 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); 463 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData);
464 m_connectionState = ConnectionStateFinishedLoading; 464 m_connectionState = ConnectionStateFinishedLoading;
465 if (m_state != Initialized) 465 if (m_state != Initialized)
466 return; 466 return;
467 ASSERT(m_state != Terminated); 467 ASSERT(m_state != Terminated);
468 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data()); 468 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data());
469 469
470 RefPtrWillBeRawPtr<ResourceLoader> protect(this); 470 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
471 ResourcePtr<Resource> protectResource(m_resource); 471 ResourcePtr<Resource> protectResource(m_resource);
472 m_state = Finishing; 472 m_state = Finishing;
473 m_resource->setLoadFinishTime(finishTime);
473 didFinishLoadingOnePart(finishTime, encodedDataLength); 474 didFinishLoadingOnePart(finishTime, encodedDataLength);
474 if (m_state == Terminated) 475 if (m_state == Terminated)
475 return; 476 return;
476 m_resource->finish(finishTime); 477 m_resource->finish();
477 478
478 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release 479 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release
479 // the resources a second time, they have been released by cancel. 480 // the resources a second time, they have been released by cancel.
480 if (m_state == Terminated) 481 if (m_state == Terminated)
481 return; 482 return;
482 releaseResources(); 483 releaseResources();
483 } 484 }
484 485
485 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or) 486 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or)
486 { 487 {
487 m_connectionState = ConnectionStateFailed; 488 m_connectionState = ConnectionStateFailed;
488 ASSERT(m_state != Terminated); 489 ASSERT(m_state != Terminated);
489 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data()); 490 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data());
490 491
491 RefPtrWillBeRawPtr<ResourceLoader> protect(this); 492 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
492 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); 493 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get());
493 ResourcePtr<Resource> protectResource(m_resource); 494 ResourcePtr<Resource> protectResource(m_resource);
494 m_state = Finishing; 495 m_state = Finishing;
495 m_resource->setResourceError(error); 496 m_resource->setResourceError(error);
496 497
497 if (!m_notifiedLoadComplete) { 498 if (!m_notifiedLoadComplete) {
498 m_notifiedLoadComplete = true; 499 didComplete();
499 m_host->didFailLoading(m_resource, error); 500 m_host->didFailLoading(m_resource, error);
500 } 501 }
501 if (m_state == Terminated) 502 if (m_state == Terminated)
502 return; 503 return;
503 504
504 m_resource->error(Resource::LoadError); 505 m_resource->error(Resource::LoadError);
505 506
506 if (m_state == Terminated) 507 if (m_state == Terminated)
507 return; 508 return;
508 509
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 didReceiveResponse(0, responseOut); 543 didReceiveResponse(0, responseOut);
543 if (m_state == Terminated) 544 if (m_state == Terminated)
544 return; 545 return;
545 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo(); 546 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo();
546 int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedData Length : blink::WebURLLoaderClient::kUnknownEncodedDataLength; 547 int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedData Length : blink::WebURLLoaderClient::kUnknownEncodedDataLength;
547 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDa taLength); 548 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDa taLength);
548 m_resource->setResourceBuffer(dataOut); 549 m_resource->setResourceBuffer(dataOut);
549 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 550 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
550 } 551 }
551 552
553 void ResourceLoader::didComplete()
554 {
555 m_notifiedLoadComplete = true;
556 m_requestCountTracker.clear();
557 }
558
552 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const 559 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const
553 { 560 {
554 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 561 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
555 return request; 562 return request;
556 } 563 }
557 564
558 } 565 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698