Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 290 |
| 291 for (const auto& resource : resources) | 291 for (const auto& resource : resources) |
| 292 resource->finishPendingClients(); | 292 resource->finishPendingClients(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 Resource::Resource(const ResourceRequest& request, Type type, const ResourceLoad erOptions& options) | 295 Resource::Resource(const ResourceRequest& request, Type type, const ResourceLoad erOptions& options) |
| 296 : m_resourceRequest(request) | 296 : m_resourceRequest(request) |
| 297 , m_options(options) | 297 , m_options(options) |
| 298 , m_responseTimestamp(currentTime()) | 298 , m_responseTimestamp(currentTime()) |
| 299 , m_cancelTimer(this, &Resource::cancelTimerFired) | 299 , m_cancelTimer(this, &Resource::cancelTimerFired) |
| 300 , m_isRevalidating(false) | |
| 300 , m_loadFinishTime(0) | 301 , m_loadFinishTime(0) |
| 301 , m_identifier(0) | 302 , m_identifier(0) |
| 302 , m_encodedSize(0) | 303 , m_encodedSize(0) |
| 303 , m_decodedSize(0) | 304 , m_decodedSize(0) |
| 304 , m_overheadSize(calculateOverheadSize()) | 305 , m_overheadSize(calculateOverheadSize()) |
| 305 , m_preloadCount(0) | 306 , m_preloadCount(0) |
| 306 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()) | 307 , m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()) |
| 307 , m_preloadResult(PreloadNotReferenced) | 308 , m_preloadResult(PreloadNotReferenced) |
| 308 , m_type(type) | 309 , m_type(type) |
| 309 , m_status(NotStarted) | 310 , m_status(NotStarted) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 340 { | 341 { |
| 341 // TOOD(japhet): Temporary, out of place hack to stop a top crasher. | 342 // TOOD(japhet): Temporary, out of place hack to stop a top crasher. |
| 342 // Make this more organic. | 343 // Make this more organic. |
| 343 if (!fetcher->loadingTaskRunner()) | 344 if (!fetcher->loadingTaskRunner()) |
| 344 return; | 345 return; |
| 345 | 346 |
| 346 RELEASE_ASSERT(!m_loader); | 347 RELEASE_ASSERT(!m_loader); |
| 347 ASSERT(stillNeedsLoad()); | 348 ASSERT(stillNeedsLoad()); |
| 348 m_status = Pending; | 349 m_status = Pending; |
| 349 | 350 |
| 350 ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); | 351 KURL url = m_resourceRequest.url(); |
| 351 KURL url = request.url(); | 352 m_resourceRequest.setAllowStoredCredentials(m_options.allowCredentials == Al lowStoredCredentials); |
| 352 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); | |
| 353 | 353 |
| 354 m_fetcherSecurityOrigin = fetcher->context().getSecurityOrigin(); | 354 m_fetcherSecurityOrigin = fetcher->context().getSecurityOrigin(); |
| 355 m_loader = ResourceLoader::create(fetcher, this); | 355 m_loader = ResourceLoader::create(fetcher, this); |
| 356 m_loader->start(request); | 356 m_loader->start(m_resourceRequest); |
| 357 // If the request reference is null (i.e., a synchronous revalidation will | 357 m_resourceRequest.setURL(url); |
| 358 // null the request), don't make the request non-null by setting the url. | |
| 359 if (!request.isNull()) | |
| 360 request.setURL(url); | |
| 361 } | 358 } |
| 362 | 359 |
| 363 void Resource::checkNotify() | 360 void Resource::checkNotify() |
| 364 { | 361 { |
| 365 if (isLoading()) | 362 if (isLoading()) |
| 366 return; | 363 return; |
| 367 | 364 |
| 368 ResourceClientWalker<ResourceClient> w(m_clients); | 365 ResourceClientWalker<ResourceClient> w(m_clients); |
| 369 while (ResourceClient* c = w.next()) | 366 while (ResourceClient* c = w.next()) |
| 370 c->notifyFinished(this); | 367 c->notifyFinished(this); |
| 371 } | 368 } |
| 372 | 369 |
| 373 void Resource::appendData(const char* data, size_t length) | 370 void Resource::appendData(const char* data, size_t length) |
| 374 { | 371 { |
| 375 TRACE_EVENT0("blink", "Resource::appendData"); | 372 TRACE_EVENT0("blink", "Resource::appendData"); |
| 376 ASSERT(m_revalidatingRequest.isNull()); | 373 DCHECK(!m_isRevalidating); |
| 377 ASSERT(!errorOccurred()); | 374 ASSERT(!errorOccurred()); |
| 378 if (m_options.dataBufferingPolicy == DoNotBufferData) | 375 if (m_options.dataBufferingPolicy == DoNotBufferData) |
| 379 return; | 376 return; |
| 380 if (m_data) | 377 if (m_data) |
| 381 m_data->append(data, length); | 378 m_data->append(data, length); |
| 382 else | 379 else |
| 383 m_data = SharedBuffer::createPurgeable(data, length); | 380 m_data = SharedBuffer::createPurgeable(data, length); |
| 384 setEncodedSize(m_data->size()); | 381 setEncodedSize(m_data->size()); |
| 385 } | 382 } |
| 386 | 383 |
| 387 void Resource::setResourceBuffer(PassRefPtr<SharedBuffer> resourceBuffer) | 384 void Resource::setResourceBuffer(PassRefPtr<SharedBuffer> resourceBuffer) |
| 388 { | 385 { |
| 389 ASSERT(m_revalidatingRequest.isNull()); | 386 DCHECK(!m_isRevalidating); |
| 390 ASSERT(!errorOccurred()); | 387 ASSERT(!errorOccurred()); |
| 391 ASSERT(m_options.dataBufferingPolicy == BufferData); | 388 ASSERT(m_options.dataBufferingPolicy == BufferData); |
| 392 m_data = resourceBuffer; | 389 m_data = resourceBuffer; |
| 393 setEncodedSize(m_data->size()); | 390 setEncodedSize(m_data->size()); |
| 394 } | 391 } |
| 395 | 392 |
| 396 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy) | 393 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy) |
| 397 { | 394 { |
| 398 m_options.dataBufferingPolicy = dataBufferingPolicy; | 395 m_options.dataBufferingPolicy = dataBufferingPolicy; |
| 399 m_data.clear(); | 396 m_data.clear(); |
| 400 setEncodedSize(0); | 397 setEncodedSize(0); |
| 401 } | 398 } |
| 402 | 399 |
| 403 void Resource::markClientsAndObserversFinished() | 400 void Resource::markClientsAndObserversFinished() |
| 404 { | 401 { |
| 405 while (!m_clients.isEmpty()) { | 402 while (!m_clients.isEmpty()) { |
| 406 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); | 403 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); |
| 407 for (int i = it->value; i; i--) { | 404 for (int i = it->value; i; i--) { |
| 408 m_finishedClients.add(it->key); | 405 m_finishedClients.add(it->key); |
| 409 m_clients.remove(it); | 406 m_clients.remove(it); |
| 410 } | 407 } |
| 411 } | 408 } |
| 412 } | 409 } |
| 413 | 410 |
| 414 void Resource::error(const ResourceError& error) | 411 void Resource::error(const ResourceError& error) |
| 415 { | 412 { |
| 416 ASSERT(!error.isNull()); | 413 ASSERT(!error.isNull()); |
| 417 m_error = error; | 414 m_error = error; |
| 418 if (!m_revalidatingRequest.isNull()) | 415 m_isRevalidating = false; |
| 419 m_revalidatingRequest = ResourceRequest(); | |
| 420 | 416 |
| 421 if (m_error.isCancellation() || !isPreloaded()) | 417 if (m_error.isCancellation() || !isPreloaded()) |
| 422 memoryCache()->remove(this); | 418 memoryCache()->remove(this); |
| 423 | 419 |
| 424 setStatus(LoadError); | 420 setStatus(LoadError); |
| 425 ASSERT(errorOccurred()); | 421 ASSERT(errorOccurred()); |
| 426 m_data.clear(); | 422 m_data.clear(); |
| 427 m_loader = nullptr; | 423 m_loader = nullptr; |
| 428 checkNotify(); | 424 checkNotify(); |
| 429 markClientsAndObserversFinished(); | 425 markClientsAndObserversFinished(); |
| 430 } | 426 } |
| 431 | 427 |
| 432 void Resource::finish(double loadFinishTime) | 428 void Resource::finish(double loadFinishTime) |
| 433 { | 429 { |
| 434 ASSERT(m_revalidatingRequest.isNull()); | 430 DCHECK(!m_isRevalidating); |
| 435 m_loadFinishTime = loadFinishTime; | 431 m_loadFinishTime = loadFinishTime; |
| 436 if (!errorOccurred()) | 432 if (!errorOccurred()) |
| 437 m_status = Cached; | 433 m_status = Cached; |
| 438 m_loader = nullptr; | 434 m_loader = nullptr; |
| 439 checkNotify(); | 435 checkNotify(); |
| 440 markClientsAndObserversFinished(); | 436 markClientsAndObserversFinished(); |
| 441 } | 437 } |
| 442 | 438 |
| 443 AtomicString Resource::httpContentType() const | 439 AtomicString Resource::httpContentType() const |
| 444 { | 440 { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 return currentAge(response, responseTimestamp) <= freshnessLifetime(response , responseTimestamp); | 540 return currentAge(response, responseTimestamp) <= freshnessLifetime(response , responseTimestamp); |
| 545 } | 541 } |
| 546 | 542 |
| 547 const ResourceRequest& Resource::lastResourceRequest() const | 543 const ResourceRequest& Resource::lastResourceRequest() const |
| 548 { | 544 { |
| 549 if (!m_redirectChain.size()) | 545 if (!m_redirectChain.size()) |
| 550 return m_resourceRequest; | 546 return m_resourceRequest; |
| 551 return m_redirectChain.last().m_request; | 547 return m_redirectChain.last().m_request; |
| 552 } | 548 } |
| 553 | 549 |
| 554 void Resource::setRevalidatingRequest(const ResourceRequest& request) | 550 void Resource::setRevalidatingRequest(const ResourceRequest& request) |
|
yhirano
2016/05/23 11:40:38
DCHECK(!request.isNull())?
Nate Chapin
2016/05/26 21:43:02
Done.
| |
| 555 { | 551 { |
| 556 m_revalidatingRequest = request; | 552 m_isRevalidating = true; |
| 553 m_resourceRequest = request; | |
| 557 m_status = NotStarted; | 554 m_status = NotStarted; |
| 558 } | 555 } |
| 559 | 556 |
| 560 void Resource::willFollowRedirect(ResourceRequest& newRequest, const ResourceRes ponse& redirectResponse) | 557 void Resource::willFollowRedirect(ResourceRequest& newRequest, const ResourceRes ponse& redirectResponse) |
| 561 { | 558 { |
| 562 newRequest.setAllowStoredCredentials(m_options.allowCredentials == AllowStor edCredentials); | 559 newRequest.setAllowStoredCredentials(m_options.allowCredentials == AllowStor edCredentials); |
| 563 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); | 560 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); |
| 564 } | 561 } |
| 565 | 562 |
| 566 void Resource::setResponse(const ResourceResponse& response) | 563 void Resource::setResponse(const ResourceResponse& response) |
| 567 { | 564 { |
| 568 m_response = response; | 565 m_response = response; |
| 569 if (m_response.wasFetchedViaServiceWorker()) | 566 if (m_response.wasFetchedViaServiceWorker()) |
| 570 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create(this , m_fetcherSecurityOrigin.get()); | 567 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create(this , m_fetcherSecurityOrigin.get()); |
| 571 } | 568 } |
| 572 | 569 |
| 573 bool Resource::unlock() | 570 bool Resource::unlock() |
| 574 { | 571 { |
| 575 if (!m_data) | 572 if (!m_data) |
| 576 return false; | 573 return false; |
| 577 | 574 |
| 578 if (!m_data->isLocked()) | 575 if (!m_data->isLocked()) |
| 579 return true; | 576 return true; |
| 580 | 577 |
| 581 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !m_revalida tingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock()) | 578 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !isLoaded() || !isSafeToUnlock()) |
|
Nate Chapin
2016/05/19 22:18:39
Switched this to !isLoaded(), which I think is wha
| |
| 582 return false; | 579 return false; |
| 583 | 580 |
| 584 m_data->unlock(); | 581 m_data->unlock(); |
| 585 return true; | 582 return true; |
| 586 } | 583 } |
| 587 | 584 |
| 588 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web DataConsumerHandle>) | 585 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web DataConsumerHandle>) |
| 589 { | 586 { |
| 590 m_responseTimestamp = currentTime(); | 587 m_responseTimestamp = currentTime(); |
| 591 | 588 |
| 592 if (!m_revalidatingRequest.isNull()) { | 589 if (m_isRevalidating) { |
| 590 m_isRevalidating = false; | |
| 593 if (response.httpStatusCode() == 304) { | 591 if (response.httpStatusCode() == 304) { |
| 594 revalidationSucceeded(response); | 592 revalidationSucceeded(response); |
| 595 return; | 593 return; |
| 596 } | 594 } |
| 597 revalidationFailed(); | 595 revalidationFailed(); |
| 598 } | 596 } |
| 599 setResponse(response); | 597 setResponse(response); |
| 600 String encoding = response.textEncodingName(); | 598 String encoding = response.textEncodingName(); |
| 601 if (!encoding.isNull()) | 599 if (!encoding.isNull()) |
| 602 setEncoding(encoding); | 600 setEncoding(encoding); |
| 603 } | 601 } |
| 604 | 602 |
| 605 void Resource::setSerializedCachedMetadata(const char* data, size_t size) | 603 void Resource::setSerializedCachedMetadata(const char* data, size_t size) |
| 606 { | 604 { |
| 607 ASSERT(m_revalidatingRequest.isNull()); | 605 DCHECK(!m_isRevalidating); |
| 608 ASSERT(!m_response.isNull()); | 606 ASSERT(!m_response.isNull()); |
| 609 if (m_cacheHandler) | 607 if (m_cacheHandler) |
| 610 m_cacheHandler->setSerializedCachedMetadata(data, size); | 608 m_cacheHandler->setSerializedCachedMetadata(data, size); |
| 611 } | 609 } |
| 612 | 610 |
| 613 CachedMetadataHandler* Resource::cacheHandler() | 611 CachedMetadataHandler* Resource::cacheHandler() |
| 614 { | 612 { |
| 615 return m_cacheHandler.get(); | 613 return m_cacheHandler.get(); |
| 616 } | 614 } |
| 617 | 615 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 m_preloadResult = PreloadReferenced; | 692 m_preloadResult = PreloadReferenced; |
| 695 } | 693 } |
| 696 if (!hasClientsOrObservers()) | 694 if (!hasClientsOrObservers()) |
| 697 memoryCache()->makeLive(this); | 695 memoryCache()->makeLive(this); |
| 698 } | 696 } |
| 699 | 697 |
| 700 void Resource::addClient(ResourceClient* client) | 698 void Resource::addClient(ResourceClient* client) |
| 701 { | 699 { |
| 702 willAddClientOrObserver(); | 700 willAddClientOrObserver(); |
| 703 | 701 |
| 704 if (!m_revalidatingRequest.isNull()) { | 702 if (m_isRevalidating) { |
| 705 m_clients.add(client); | 703 m_clients.add(client); |
|
yhirano
2016/05/23 11:40:38
Not related to this CL but it looks a |didAddClien
Nate Chapin
2016/05/26 21:43:02
I don't think we want didAddClient here: that woul
yhirano
2016/05/27 01:55:56
Ah, I see, thank you.
| |
| 706 return; | 704 return; |
| 707 } | 705 } |
| 708 | 706 |
| 709 // If we have existing data to send to the new client and the resource type supprts it, send it asynchronously. | 707 // If we have existing data to send to the new client and the resource type supprts it, send it asynchronously. |
| 710 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp e()) && !m_needsSynchronousCacheHit) { | 708 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp e()) && !m_needsSynchronousCacheHit) { |
| 711 m_clientsAwaitingCallback.add(client); | 709 m_clientsAwaitingCallback.add(client); |
| 712 ResourceCallback::callbackHandler().schedule(this); | 710 ResourceCallback::callbackHandler().schedule(this); |
| 713 return; | 711 return; |
| 714 } | 712 } |
| 715 | 713 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 911 const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields(); | 909 const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields(); |
| 912 for (const auto& header : newHeaders) { | 910 for (const auto& header : newHeaders) { |
| 913 // Entity headers should not be sent by servers when generating a 304 | 911 // Entity headers should not be sent by servers when generating a 304 |
| 914 // response; misconfigured servers send them anyway. We shouldn't allow | 912 // response; misconfigured servers send them anyway. We shouldn't allow |
| 915 // such headers to update the original request. We'll base this on the | 913 // such headers to update the original request. We'll base this on the |
| 916 // list defined by RFC2616 7.1, with a few additions for extension heade rs | 914 // list defined by RFC2616 7.1, with a few additions for extension heade rs |
| 917 // we care about. | 915 // we care about. |
| 918 if (!shouldUpdateHeaderAfterRevalidation(header.key)) | 916 if (!shouldUpdateHeaderAfterRevalidation(header.key)) |
| 919 continue; | 917 continue; |
| 920 m_response.setHTTPHeaderField(header.key, header.value); | 918 m_response.setHTTPHeaderField(header.key, header.value); |
| 921 } | 919 } |
|
yhirano
2016/05/23 11:40:38
m_isRevalidating = false;
Nate Chapin
2016/05/26 21:43:03
This is now set in responseReceived(), just before
| |
| 922 | |
| 923 m_resourceRequest = m_revalidatingRequest; | |
| 924 m_revalidatingRequest = ResourceRequest(); | |
| 925 } | 920 } |
| 926 | 921 |
| 927 void Resource::revalidationFailed() | 922 void Resource::revalidationFailed() |
| 928 { | 923 { |
| 929 m_resourceRequest = m_revalidatingRequest; | |
| 930 m_revalidatingRequest = ResourceRequest(); | |
| 931 m_redirectChain.clear(); | 924 m_redirectChain.clear(); |
|
yhirano
2016/05/23 11:40:38
ditto
Nate Chapin
2016/05/26 21:43:02
ditto :)
| |
| 932 m_data.clear(); | 925 m_data.clear(); |
| 933 m_cacheHandler.clear(); | 926 m_cacheHandler.clear(); |
| 934 destroyDecodedDataForFailedRevalidation(); | 927 destroyDecodedDataForFailedRevalidation(); |
| 935 } | 928 } |
| 936 | 929 |
| 937 bool Resource::canReuseRedirectChain() | 930 bool Resource::canReuseRedirectChain() |
| 938 { | 931 { |
| 939 for (auto& redirect : m_redirectChain) { | 932 for (auto& redirect : m_redirectChain) { |
| 940 if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp)) | 933 if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp)) |
| 941 return false; | 934 return false; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 case Resource::Media: | 1122 case Resource::Media: |
| 1130 return "Media"; | 1123 return "Media"; |
| 1131 case Resource::Manifest: | 1124 case Resource::Manifest: |
| 1132 return "Manifest"; | 1125 return "Manifest"; |
| 1133 } | 1126 } |
| 1134 ASSERT_NOT_REACHED(); | 1127 ASSERT_NOT_REACHED(); |
| 1135 return "Unknown"; | 1128 return "Unknown"; |
| 1136 } | 1129 } |
| 1137 | 1130 |
| 1138 } // namespace blink | 1131 } // namespace blink |
| OLD | NEW |