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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 // | 616 // |
| 617 // 1. Clients can be added during the loop. Make sure they are not processed . | 617 // 1. Clients can be added during the loop. Make sure they are not processed . |
| 618 // 2. Clients can be removed during the loop. Make sure they are always avai lable to be | 618 // 2. Clients can be removed during the loop. Make sure they are always avai lable to be |
| 619 // removed. Also don't call removed clients or add them back. | 619 // removed. Also don't call removed clients or add them back. |
| 620 | 620 |
| 621 // Handle case (1) by saving a list of clients to notify. A separate list al so ensure | 621 // Handle case (1) by saving a list of clients to notify. A separate list al so ensure |
| 622 // a client is either in m_clients or m_clientsAwaitingCallback. | 622 // a client is either in m_clients or m_clientsAwaitingCallback. |
| 623 Vector<ResourceClient*> clientsToNotify; | 623 Vector<ResourceClient*> clientsToNotify; |
| 624 copyToVector(m_clientsAwaitingCallback, clientsToNotify); | 624 copyToVector(m_clientsAwaitingCallback, clientsToNotify); |
| 625 | 625 |
| 626 for (size_t i = 0; i < clientsToNotify.size(); ++i) { | 626 for (const auto& client : clientsToNotify) { |
| 627 ResourceClient* client = clientsToNotify[i]; | |
| 628 | |
| 629 // Handle case (2) to skip removed clients. | 627 // Handle case (2) to skip removed clients. |
| 630 if (!m_clientsAwaitingCallback.remove(client)) | 628 if (!m_clientsAwaitingCallback.remove(client)) |
| 631 continue; | 629 continue; |
| 632 m_clients.add(client); | 630 m_clients.add(client); |
| 633 didAddClient(client); | 631 didAddClient(client); |
| 634 } | 632 } |
| 635 | 633 |
| 636 // It is still possible for the above loop to finish a new client synchronou sly. | 634 // It is still possible for the above loop to finish a new client synchronou sly. |
| 637 // If there's no client waiting we should deschedule. | 635 // If there's no client waiting we should deschedule. |
| 638 bool scheduled = ResourceCallback::callbackHandler()->isScheduled(this); | 636 bool scheduled = ResourceCallback::callbackHandler()->isScheduled(this); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 { | 686 { |
| 689 ASSERT(m_resourceToRevalidate); | 687 ASSERT(m_resourceToRevalidate); |
| 690 ASSERT(memoryCache()->contains(m_resourceToRevalidate)); | 688 ASSERT(memoryCache()->contains(m_resourceToRevalidate)); |
| 691 ASSERT(!memoryCache()->contains(this)); | 689 ASSERT(!memoryCache()->contains(this)); |
| 692 | 690 |
| 693 WTF_LOG(ResourceLoading, "Resource %p switchClientsToRevalidatedResource %p" , this, m_resourceToRevalidate.get()); | 691 WTF_LOG(ResourceLoading, "Resource %p switchClientsToRevalidatedResource %p" , this, m_resourceToRevalidate.get()); |
| 694 | 692 |
| 695 m_resourceToRevalidate->m_identifier = m_identifier; | 693 m_resourceToRevalidate->m_identifier = m_identifier; |
| 696 | 694 |
| 697 m_switchingClientsToRevalidatedResource = true; | 695 m_switchingClientsToRevalidatedResource = true; |
| 698 HashSet<ResourcePtrBase*>::iterator end = m_handlesToRevalidate.end(); | 696 for (const auto& handle : m_handlesToRevalidate) { |
| 699 for (HashSet<ResourcePtrBase*>::iterator it = m_handlesToRevalidate.begin(); it != end; ++it) { | |
| 700 ResourcePtrBase* handle = *it; | |
| 701 handle->m_resource = m_resourceToRevalidate; | 697 handle->m_resource = m_resourceToRevalidate; |
| 702 m_resourceToRevalidate->registerHandle(handle); | 698 m_resourceToRevalidate->registerHandle(handle); |
| 703 --m_handleCount; | 699 --m_handleCount; |
| 704 } | 700 } |
| 705 ASSERT(!m_handleCount); | 701 ASSERT(!m_handleCount); |
| 706 m_handlesToRevalidate.clear(); | 702 m_handlesToRevalidate.clear(); |
| 707 | 703 |
| 708 Vector<ResourceClient*> clientsToMove; | 704 Vector<ResourceClient*> clientsToMove; |
| 709 HashCountedSet<ResourceClient*>::iterator end2 = m_clients.end(); | 705 for (const auto& client : m_clients) { |
|
Mike West
2014/10/17 10:38:49
Nit: How about "clientHash" rather than "client".
riju_
2014/10/17 18:36:48
Done.
| |
| 710 for (HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); it != end2; ++it) { | 706 unsigned count = client.value; |
| 711 ResourceClient* client = it->key; | |
| 712 unsigned count = it->value; | |
| 713 while (count) { | 707 while (count) { |
| 714 clientsToMove.append(client); | 708 clientsToMove.append(client.key); |
| 715 --count; | 709 --count; |
| 716 } | 710 } |
| 717 } | 711 } |
| 718 | 712 |
| 719 unsigned moveCount = clientsToMove.size(); | 713 unsigned moveCount = clientsToMove.size(); |
| 720 for (unsigned n = 0; n < moveCount; ++n) | 714 for (unsigned n = 0; n < moveCount; ++n) |
| 721 removeClient(clientsToMove[n]); | 715 removeClient(clientsToMove[n]); |
| 722 ASSERT(m_clients.isEmpty()); | 716 ASSERT(m_clients.isEmpty()); |
| 723 | 717 |
| 724 for (unsigned n = 0; n < moveCount; ++n) | 718 for (unsigned n = 0; n < moveCount; ++n) |
| 725 m_resourceToRevalidate->addClientToSet(clientsToMove[n]); | 719 m_resourceToRevalidate->addClientToSet(clientsToMove[n]); |
| 726 for (unsigned n = 0; n < moveCount; ++n) { | 720 for (unsigned n = 0; n < moveCount; ++n) { |
| 727 // Calling didAddClient may do anything, including trying to cancel reva lidation. | 721 // Calling didAddClient may do anything, including trying to cancel reva lidation. |
| 728 // Assert that it didn't succeed. | 722 // Assert that it didn't succeed. |
| 729 ASSERT(m_resourceToRevalidate); | 723 ASSERT(m_resourceToRevalidate); |
| 730 // Calling didAddClient for a client may end up removing another client. In that case it won't be in the set anymore. | 724 // Calling didAddClient for a client may end up removing another client. In that case it won't be in the set anymore. |
| 731 if (m_resourceToRevalidate->m_clients.contains(clientsToMove[n])) | 725 if (m_resourceToRevalidate->m_clients.contains(clientsToMove[n])) |
| 732 m_resourceToRevalidate->didAddClient(clientsToMove[n]); | 726 m_resourceToRevalidate->didAddClient(clientsToMove[n]); |
| 733 } | 727 } |
| 734 m_switchingClientsToRevalidatedResource = false; | 728 m_switchingClientsToRevalidatedResource = false; |
| 735 } | 729 } |
| 736 | 730 |
| 737 void Resource::updateResponseAfterRevalidation(const ResourceResponse& validatin gResponse) | 731 void Resource::updateResponseAfterRevalidation(const ResourceResponse& validatin gResponse) |
| 738 { | 732 { |
| 739 m_responseTimestamp = currentTime(); | 733 m_responseTimestamp = currentTime(); |
| 740 | 734 |
| 741 // RFC2616 10.3.5 | 735 // RFC2616 10.3.5 |
| 742 // Update cached headers from the 304 response | 736 // Update cached headers from the 304 response |
| 743 const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields(); | 737 const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields(); |
| 744 HTTPHeaderMap::const_iterator end = newHeaders.end(); | 738 for (const auto& header : newHeaders) { |
| 745 for (HTTPHeaderMap::const_iterator it = newHeaders.begin(); it != end; ++it) { | |
| 746 // Entity headers should not be sent by servers when generating a 304 | 739 // Entity headers should not be sent by servers when generating a 304 |
| 747 // response; misconfigured servers send them anyway. We shouldn't allow | 740 // response; misconfigured servers send them anyway. We shouldn't allow |
| 748 // such headers to update the original request. We'll base this on the | 741 // such headers to update the original request. We'll base this on the |
| 749 // list defined by RFC2616 7.1, with a few additions for extension heade rs | 742 // list defined by RFC2616 7.1, with a few additions for extension heade rs |
| 750 // we care about. | 743 // we care about. |
| 751 if (!shouldUpdateHeaderAfterRevalidation(it->key)) | 744 if (!shouldUpdateHeaderAfterRevalidation(header.key)) |
| 752 continue; | 745 continue; |
| 753 m_response.setHTTPHeaderField(it->key, it->value); | 746 m_response.setHTTPHeaderField(header.key, header.value); |
| 754 } | 747 } |
| 755 } | 748 } |
| 756 | 749 |
| 757 void Resource::revalidationSucceeded(const ResourceResponse& response) | 750 void Resource::revalidationSucceeded(const ResourceResponse& response) |
| 758 { | 751 { |
| 759 ASSERT(m_resourceToRevalidate); | 752 ASSERT(m_resourceToRevalidate); |
| 760 ASSERT(!memoryCache()->contains(m_resourceToRevalidate)); | 753 ASSERT(!memoryCache()->contains(m_resourceToRevalidate)); |
| 761 ASSERT(m_resourceToRevalidate->isLoaded()); | 754 ASSERT(m_resourceToRevalidate->isLoaded()); |
| 762 | 755 |
| 763 // Calling evict() can potentially delete revalidatingResource, which we use | 756 // Calling evict() can potentially delete revalidatingResource, which we use |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 unlock(); | 798 unlock(); |
| 806 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { | 799 } else if (m_handleCount == 1 && memoryCache()->contains(this)) { |
| 807 unlock(); | 800 unlock(); |
| 808 if (!hasClients()) | 801 if (!hasClients()) |
| 809 memoryCache()->prune(this); | 802 memoryCache()->prune(this); |
| 810 } | 803 } |
| 811 } | 804 } |
| 812 | 805 |
| 813 bool Resource::canReuseRedirectChain() | 806 bool Resource::canReuseRedirectChain() |
| 814 { | 807 { |
| 815 for (size_t i = 0; i < m_redirectChain.size(); ++i) { | 808 for (auto& redirect : m_redirectChain) { |
| 816 if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTim estamp)) | 809 if (!canUseResponse(redirect.m_redirectResponse, m_responseTimestamp)) |
| 817 return false; | 810 return false; |
| 818 if (m_redirectChain[i].m_request.cacheControlContainsNoCache() || m_redi rectChain[i].m_request.cacheControlContainsNoStore()) | 811 if (redirect.m_request.cacheControlContainsNoCache() || redirect.m_reque st.cacheControlContainsNoStore()) |
| 819 return false; | 812 return false; |
| 820 } | 813 } |
| 821 return true; | 814 return true; |
| 822 } | 815 } |
| 823 | 816 |
| 824 bool Resource::hasCacheControlNoStoreHeader() | 817 bool Resource::hasCacheControlNoStoreHeader() |
| 825 { | 818 { |
| 826 return m_response.cacheControlContainsNoStore() || m_resourceRequest.cacheCo ntrolContainsNoStore(); | 819 return m_response.cacheControlContainsNoStore() || m_resourceRequest.cacheCo ntrolContainsNoStore(); |
| 827 } | 820 } |
| 828 | 821 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 m_callbackTimer.stop(); | 899 m_callbackTimer.stop(); |
| 907 } | 900 } |
| 908 | 901 |
| 909 bool Resource::ResourceCallback::isScheduled(Resource* resource) const | 902 bool Resource::ResourceCallback::isScheduled(Resource* resource) const |
| 910 { | 903 { |
| 911 return m_resourcesWithPendingClients.contains(resource); | 904 return m_resourcesWithPendingClients.contains(resource); |
| 912 } | 905 } |
| 913 | 906 |
| 914 void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*) | 907 void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*) |
| 915 { | 908 { |
| 916 HashSet<Resource*>::iterator end = m_resourcesWithPendingClients.end(); | 909 Vector<ResourcePtr<Resource>> resources; |
| 917 Vector<ResourcePtr<Resource> > resources; | 910 for (const auto& resource : m_resourcesWithPendingClients) |
| 918 for (HashSet<Resource*>::iterator it = m_resourcesWithPendingClients.begin() ; it != end; ++it) | 911 resources.append(resource); |
| 919 resources.append(*it); | |
| 920 m_resourcesWithPendingClients.clear(); | 912 m_resourcesWithPendingClients.clear(); |
| 921 | 913 |
| 922 for (size_t i = 0; i < resources.size(); i++) { | 914 for (const auto& resource : resources) { |
| 923 resources[i]->assertAlive(); | 915 resource->assertAlive(); |
| 924 resources[i]->finishPendingClients(); | 916 resource->finishPendingClients(); |
| 925 resources[i]->assertAlive(); | 917 resource->assertAlive(); |
| 926 } | 918 } |
| 927 | 919 |
| 928 for (size_t i = 0; i < resources.size(); i++) | 920 for (const auto resource : resources) |
|
Mike West
2014/10/17 10:38:49
Why did you choose `const auto&` above, and `const
riju_
2014/10/17 18:36:48
my bad. Done.
| |
| 929 resources[i]->assertAlive(); | 921 resource->assertAlive(); |
| 930 } | 922 } |
| 931 | 923 |
| 932 static const char* initatorTypeNameToString(const AtomicString& initiatorTypeNam e) | 924 static const char* initatorTypeNameToString(const AtomicString& initiatorTypeNam e) |
| 933 { | 925 { |
| 934 if (initiatorTypeName == FetchInitiatorTypeNames::css) | 926 if (initiatorTypeName == FetchInitiatorTypeNames::css) |
| 935 return "CSS resource"; | 927 return "CSS resource"; |
| 936 if (initiatorTypeName == FetchInitiatorTypeNames::document) | 928 if (initiatorTypeName == FetchInitiatorTypeNames::document) |
| 937 return "Document"; | 929 return "Document"; |
| 938 if (initiatorTypeName == FetchInitiatorTypeNames::icon) | 930 if (initiatorTypeName == FetchInitiatorTypeNames::icon) |
| 939 return "Icon"; | 931 return "Icon"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 return "ImportResource"; | 1009 return "ImportResource"; |
| 1018 case Resource::Media: | 1010 case Resource::Media: |
| 1019 return "Media"; | 1011 return "Media"; |
| 1020 } | 1012 } |
| 1021 ASSERT_NOT_REACHED(); | 1013 ASSERT_NOT_REACHED(); |
| 1022 return "Unknown"; | 1014 return "Unknown"; |
| 1023 } | 1015 } |
| 1024 #endif // !LOG_DISABLED | 1016 #endif // !LOG_DISABLED |
| 1025 | 1017 |
| 1026 } | 1018 } |
| OLD | NEW |