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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 , m_protectorCount(0) | 107 , m_protectorCount(0) |
108 , m_preloadResult(PreloadNotReferenced) | 108 , m_preloadResult(PreloadNotReferenced) |
109 , m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow) | 109 , m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow) |
110 , m_requestedFromNetworkingLayer(false) | 110 , m_requestedFromNetworkingLayer(false) |
111 , m_loading(false) | 111 , m_loading(false) |
112 , m_switchingClientsToRevalidatedResource(false) | 112 , m_switchingClientsToRevalidatedResource(false) |
113 , m_type(type) | 113 , m_type(type) |
114 , m_status(Pending) | 114 , m_status(Pending) |
115 , m_wasPurged(false) | 115 , m_wasPurged(false) |
116 , m_needsSynchronousCacheHit(false) | 116 , m_needsSynchronousCacheHit(false) |
117 #ifndef NDEBUG | 117 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
118 , m_deleted(false) | 118 , m_deleted(false) |
119 #endif | 119 #endif |
120 , m_resourceToRevalidate(0) | 120 , m_resourceToRevalidate(0) |
121 , m_proxyResource(0) | 121 , m_proxyResource(0) |
122 { | 122 { |
123 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car
eless updates of the enum. | 123 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car
eless updates of the enum. |
124 #ifndef NDEBUG | 124 #ifndef NDEBUG |
125 cachedResourceLeakCounter.increment(); | 125 cachedResourceLeakCounter.increment(); |
126 #endif | 126 #endif |
127 | 127 |
128 if (!m_resourceRequest.url().hasFragmentIdentifier()) | 128 if (!m_resourceRequest.url().hasFragmentIdentifier()) |
129 return; | 129 return; |
130 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR
equest.url()); | 130 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR
equest.url()); |
131 if (urlForCache.hasFragmentIdentifier()) | 131 if (urlForCache.hasFragmentIdentifier()) |
132 return; | 132 return; |
133 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); | 133 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier(
); |
134 m_resourceRequest.setURL(urlForCache); | 134 m_resourceRequest.setURL(urlForCache); |
135 } | 135 } |
136 | 136 |
137 Resource::~Resource() | 137 Resource::~Resource() |
138 { | 138 { |
139 ASSERT(!m_resourceToRevalidate); // Should be true because canDelete() check
s this. | 139 ASSERT(!m_resourceToRevalidate); // Should be true because canDelete() check
s this. |
140 ASSERT(canDelete()); | 140 ASSERT(canDelete()); |
141 RELEASE_ASSERT(!memoryCache()->contains(this)); | 141 RELEASE_ASSERT(!memoryCache()->contains(this)); |
142 RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this)); | 142 RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this)); |
143 ASSERT(!m_deleted); | |
144 ASSERT(url().isNull() || memoryCache()->resourceForURL(KURL(ParsedURLString,
url())) != this); | 143 ASSERT(url().isNull() || memoryCache()->resourceForURL(KURL(ParsedURLString,
url())) != this); |
| 144 assertAlive(); |
145 | 145 |
| 146 #ifdef ENABLE_RESOURCE_IS_DELETED_CHECK |
| 147 m_deleted = true; |
| 148 #endif |
146 #ifndef NDEBUG | 149 #ifndef NDEBUG |
147 m_deleted = true; | |
148 cachedResourceLeakCounter.decrement(); | 150 cachedResourceLeakCounter.decrement(); |
149 #endif | 151 #endif |
150 } | 152 } |
151 | 153 |
152 void Resource::failBeforeStarting() | 154 void Resource::failBeforeStarting() |
153 { | 155 { |
154 WTF_LOG(ResourceLoading, "Cannot start loading '%s'", url().string().latin1(
).data()); | 156 WTF_LOG(ResourceLoading, "Cannot start loading '%s'", url().string().latin1(
).data()); |
155 error(Resource::LoadError); | 157 error(Resource::LoadError); |
156 } | 158 } |
157 | 159 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 | 728 |
727 // Calling evict() can potentially delete revalidatingResource, which we use | 729 // Calling evict() can potentially delete revalidatingResource, which we use |
728 // below. This mustn't be the case since revalidation means it is loaded | 730 // below. This mustn't be the case since revalidation means it is loaded |
729 // and so canDelete() is false. | 731 // and so canDelete() is false. |
730 ASSERT(!canDelete()); | 732 ASSERT(!canDelete()); |
731 | 733 |
732 m_resourceToRevalidate->updateResponseAfterRevalidation(response); | 734 m_resourceToRevalidate->updateResponseAfterRevalidation(response); |
733 memoryCache()->replace(m_resourceToRevalidate, this); | 735 memoryCache()->replace(m_resourceToRevalidate, this); |
734 | 736 |
735 switchClientsToRevalidatedResource(); | 737 switchClientsToRevalidatedResource(); |
736 ASSERT(!m_deleted); | 738 assertAlive(); |
737 // clearResourceToRevalidate deletes this. | 739 // clearResourceToRevalidate deletes this. |
738 clearResourceToRevalidate(); | 740 clearResourceToRevalidate(); |
739 } | 741 } |
740 | 742 |
741 void Resource::revalidationFailed() | 743 void Resource::revalidationFailed() |
742 { | 744 { |
743 ASSERT(WTF::isMainThread()); | 745 ASSERT(WTF::isMainThread()); |
744 WTF_LOG(ResourceLoading, "Revalidation failed for %p", this); | 746 WTF_LOG(ResourceLoading, "Revalidation failed for %p", this); |
745 ASSERT(resourceToRevalidate()); | 747 ASSERT(resourceToRevalidate()); |
746 clearResourceToRevalidate(); | 748 clearResourceToRevalidate(); |
747 } | 749 } |
748 | 750 |
749 void Resource::registerHandle(ResourcePtrBase* h) | 751 void Resource::registerHandle(ResourcePtrBase* h) |
750 { | 752 { |
| 753 assertAlive(); |
751 ++m_handleCount; | 754 ++m_handleCount; |
752 if (m_resourceToRevalidate) | 755 if (m_resourceToRevalidate) |
753 m_handlesToRevalidate.add(h); | 756 m_handlesToRevalidate.add(h); |
754 } | 757 } |
755 | 758 |
756 void Resource::unregisterHandle(ResourcePtrBase* h) | 759 void Resource::unregisterHandle(ResourcePtrBase* h) |
757 { | 760 { |
| 761 assertAlive(); |
758 ASSERT(m_handleCount > 0); | 762 ASSERT(m_handleCount > 0); |
759 --m_handleCount; | 763 --m_handleCount; |
760 | 764 |
761 if (m_resourceToRevalidate) | 765 if (m_resourceToRevalidate) |
762 m_handlesToRevalidate.remove(h); | 766 m_handlesToRevalidate.remove(h); |
763 | 767 |
764 if (!m_handleCount) { | 768 if (!m_handleCount) { |
765 if (deleteIfPossible()) | 769 if (deleteIfPossible()) |
766 return; | 770 return; |
767 unlock(); | 771 unlock(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 | 844 |
841 Resource::ResourceCallback::ResourceCallback() | 845 Resource::ResourceCallback::ResourceCallback() |
842 : m_callbackTimer(this, &ResourceCallback::timerFired) | 846 : m_callbackTimer(this, &ResourceCallback::timerFired) |
843 { | 847 { |
844 } | 848 } |
845 | 849 |
846 void Resource::ResourceCallback::schedule(Resource* resource) | 850 void Resource::ResourceCallback::schedule(Resource* resource) |
847 { | 851 { |
848 if (!m_callbackTimer.isActive()) | 852 if (!m_callbackTimer.isActive()) |
849 m_callbackTimer.startOneShot(0, FROM_HERE); | 853 m_callbackTimer.startOneShot(0, FROM_HERE); |
| 854 resource->assertAlive(); |
850 m_resourcesWithPendingClients.add(resource); | 855 m_resourcesWithPendingClients.add(resource); |
851 } | 856 } |
852 | 857 |
853 void Resource::ResourceCallback::cancel(Resource* resource) | 858 void Resource::ResourceCallback::cancel(Resource* resource) |
854 { | 859 { |
| 860 resource->assertAlive(); |
855 m_resourcesWithPendingClients.remove(resource); | 861 m_resourcesWithPendingClients.remove(resource); |
856 if (m_callbackTimer.isActive() && m_resourcesWithPendingClients.isEmpty()) | 862 if (m_callbackTimer.isActive() && m_resourcesWithPendingClients.isEmpty()) |
857 m_callbackTimer.stop(); | 863 m_callbackTimer.stop(); |
858 } | 864 } |
859 | 865 |
860 bool Resource::ResourceCallback::isScheduled(Resource* resource) const | 866 bool Resource::ResourceCallback::isScheduled(Resource* resource) const |
861 { | 867 { |
862 return m_resourcesWithPendingClients.contains(resource); | 868 return m_resourcesWithPendingClients.contains(resource); |
863 } | 869 } |
864 | 870 |
865 void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*) | 871 void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*) |
866 { | 872 { |
867 HashSet<Resource*>::iterator end = m_resourcesWithPendingClients.end(); | 873 HashSet<Resource*>::iterator end = m_resourcesWithPendingClients.end(); |
868 Vector<ResourcePtr<Resource> > resources; | 874 Vector<ResourcePtr<Resource> > resources; |
869 for (HashSet<Resource*>::iterator it = m_resourcesWithPendingClients.begin()
; it != end; ++it) | 875 for (HashSet<Resource*>::iterator it = m_resourcesWithPendingClients.begin()
; it != end; ++it) |
870 resources.append(*it); | 876 resources.append(*it); |
871 m_resourcesWithPendingClients.clear(); | 877 m_resourcesWithPendingClients.clear(); |
| 878 |
| 879 for (size_t i = 0; i < resources.size(); i++) { |
| 880 resources[i]->assertAlive(); |
| 881 resources[i]->finishPendingClients(); |
| 882 resources[i]->assertAlive(); |
| 883 } |
| 884 |
872 for (size_t i = 0; i < resources.size(); i++) | 885 for (size_t i = 0; i < resources.size(); i++) |
873 resources[i]->finishPendingClients(); | 886 resources[i]->assertAlive(); |
874 } | 887 } |
875 | 888 |
876 static const char* initatorTypeNameToString(const AtomicString& initiatorTypeNam
e) | 889 static const char* initatorTypeNameToString(const AtomicString& initiatorTypeNam
e) |
877 { | 890 { |
878 if (initiatorTypeName == FetchInitiatorTypeNames::css) | 891 if (initiatorTypeName == FetchInitiatorTypeNames::css) |
879 return "CSS resource"; | 892 return "CSS resource"; |
880 if (initiatorTypeName == FetchInitiatorTypeNames::document) | 893 if (initiatorTypeName == FetchInitiatorTypeNames::document) |
881 return "Document"; | 894 return "Document"; |
882 if (initiatorTypeName == FetchInitiatorTypeNames::icon) | 895 if (initiatorTypeName == FetchInitiatorTypeNames::icon) |
883 return "Icon"; | 896 return "Icon"; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 return "Shader"; | 974 return "Shader"; |
962 case Resource::ImportResource: | 975 case Resource::ImportResource: |
963 return "ImportResource"; | 976 return "ImportResource"; |
964 } | 977 } |
965 ASSERT_NOT_REACHED(); | 978 ASSERT_NOT_REACHED(); |
966 return "Unknown"; | 979 return "Unknown"; |
967 } | 980 } |
968 #endif // !LOG_DISABLED | 981 #endif // !LOG_DISABLED |
969 | 982 |
970 } | 983 } |
OLD | NEW |