| 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) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
| 8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
| 9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
| 10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return emptyString; | 120 return emptyString; |
| 121 } | 121 } |
| 122 | 122 |
| 123 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap( | 123 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap( |
| 124 const String& cacheIdentifier) { | 124 const String& cacheIdentifier) { |
| 125 if (!m_resourceMaps.contains(cacheIdentifier)) { | 125 if (!m_resourceMaps.contains(cacheIdentifier)) { |
| 126 ResourceMapIndex::AddResult result = | 126 ResourceMapIndex::AddResult result = |
| 127 m_resourceMaps.insert(cacheIdentifier, new ResourceMap); | 127 m_resourceMaps.insert(cacheIdentifier, new ResourceMap); |
| 128 CHECK(result.isNewEntry); | 128 CHECK(result.isNewEntry); |
| 129 } | 129 } |
| 130 return m_resourceMaps.get(cacheIdentifier); | 130 return m_resourceMaps.at(cacheIdentifier); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void MemoryCache::add(Resource* resource) { | 133 void MemoryCache::add(Resource* resource) { |
| 134 DCHECK(resource); | 134 DCHECK(resource); |
| 135 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier()); | 135 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier()); |
| 136 addInternal(resources, MemoryCacheEntry::create(resource)); | 136 addInternal(resources, MemoryCacheEntry::create(resource)); |
| 137 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " | 137 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " |
| 138 << resource->url().getString() << ", resource " | 138 << resource->url().getString() << ", resource " |
| 139 << resource; | 139 << resource; |
| 140 } | 140 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 161 } | 161 } |
| 162 | 162 |
| 163 void MemoryCache::remove(Resource* resource) { | 163 void MemoryCache::remove(Resource* resource) { |
| 164 DCHECK(WTF::isMainThread()); | 164 DCHECK(WTF::isMainThread()); |
| 165 DCHECK(resource); | 165 DCHECK(resource); |
| 166 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " | 166 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " |
| 167 << resource->url().getString() << " from cache"; | 167 << resource->url().getString() << " from cache"; |
| 168 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", | 168 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", |
| 169 resource->url().getString().utf8()); | 169 resource->url().getString().utf8()); |
| 170 | 170 |
| 171 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); | 171 ResourceMap* resources = m_resourceMaps.at(resource->cacheIdentifier()); |
| 172 if (!resources) | 172 if (!resources) |
| 173 return; | 173 return; |
| 174 | 174 |
| 175 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); | 175 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); |
| 176 ResourceMap::iterator it = resources->find(url); | 176 ResourceMap::iterator it = resources->find(url); |
| 177 if (it == resources->end() || it->value->resource() != resource) | 177 if (it == resources->end() || it->value->resource() != resource) |
| 178 return; | 178 return; |
| 179 removeInternal(resources, it); | 179 removeInternal(resources, it); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void MemoryCache::removeInternal(ResourceMap* resourceMap, | 182 void MemoryCache::removeInternal(ResourceMap* resourceMap, |
| 183 const ResourceMap::iterator& it) { | 183 const ResourceMap::iterator& it) { |
| 184 DCHECK(WTF::isMainThread()); | 184 DCHECK(WTF::isMainThread()); |
| 185 DCHECK(resourceMap); | 185 DCHECK(resourceMap); |
| 186 | 186 |
| 187 Resource* resource = it->value->resource(); | 187 Resource* resource = it->value->resource(); |
| 188 DCHECK(resource); | 188 DCHECK(resource); |
| 189 | 189 |
| 190 update(resource, resource->size(), 0); | 190 update(resource, resource->size(), 0); |
| 191 resourceMap->remove(it); | 191 resourceMap->remove(it); |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool MemoryCache::contains(const Resource* resource) const { | 194 bool MemoryCache::contains(const Resource* resource) const { |
| 195 if (!resource || resource->url().isEmpty()) | 195 if (!resource || resource->url().isEmpty()) |
| 196 return false; | 196 return false; |
| 197 const ResourceMap* resources = | 197 const ResourceMap* resources = m_resourceMaps.at(resource->cacheIdentifier()); |
| 198 m_resourceMaps.get(resource->cacheIdentifier()); | |
| 199 if (!resources) | 198 if (!resources) |
| 200 return false; | 199 return false; |
| 201 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); | 200 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); |
| 202 MemoryCacheEntry* entry = resources->get(url); | 201 MemoryCacheEntry* entry = resources->at(url); |
| 203 return entry && resource == entry->resource(); | 202 return entry && resource == entry->resource(); |
| 204 } | 203 } |
| 205 | 204 |
| 206 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) const { | 205 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) const { |
| 207 return resourceForURL(resourceURL, defaultCacheIdentifier()); | 206 return resourceForURL(resourceURL, defaultCacheIdentifier()); |
| 208 } | 207 } |
| 209 | 208 |
| 210 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, | 209 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, |
| 211 const String& cacheIdentifier) const { | 210 const String& cacheIdentifier) const { |
| 212 DCHECK(WTF::isMainThread()); | 211 DCHECK(WTF::isMainThread()); |
| 213 if (!resourceURL.isValid() || resourceURL.isNull()) | 212 if (!resourceURL.isValid() || resourceURL.isNull()) |
| 214 return nullptr; | 213 return nullptr; |
| 215 DCHECK(!cacheIdentifier.isNull()); | 214 DCHECK(!cacheIdentifier.isNull()); |
| 216 const ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); | 215 const ResourceMap* resources = m_resourceMaps.at(cacheIdentifier); |
| 217 if (!resources) | 216 if (!resources) |
| 218 return nullptr; | 217 return nullptr; |
| 219 MemoryCacheEntry* entry = | 218 MemoryCacheEntry* entry = |
| 220 resources->get(removeFragmentIdentifierIfNeeded(resourceURL)); | 219 resources->at(removeFragmentIdentifierIfNeeded(resourceURL)); |
| 221 if (!entry) | 220 if (!entry) |
| 222 return nullptr; | 221 return nullptr; |
| 223 return entry->resource(); | 222 return entry->resource(); |
| 224 } | 223 } |
| 225 | 224 |
| 226 HeapVector<Member<Resource>> MemoryCache::resourcesForURL( | 225 HeapVector<Member<Resource>> MemoryCache::resourcesForURL( |
| 227 const KURL& resourceURL) const { | 226 const KURL& resourceURL) const { |
| 228 DCHECK(WTF::isMainThread()); | 227 DCHECK(WTF::isMainThread()); |
| 229 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 228 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
| 230 HeapVector<Member<Resource>> results; | 229 HeapVector<Member<Resource>> results; |
| 231 for (const auto& resourceMapIter : m_resourceMaps) { | 230 for (const auto& resourceMapIter : m_resourceMaps) { |
| 232 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) { | 231 if (MemoryCacheEntry* entry = resourceMapIter.value->at(url)) { |
| 233 Resource* resource = entry->resource(); | 232 Resource* resource = entry->resource(); |
| 234 DCHECK(resource); | 233 DCHECK(resource); |
| 235 results.push_back(resource); | 234 results.push_back(resource); |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 return results; | 237 return results; |
| 239 } | 238 } |
| 240 | 239 |
| 241 void MemoryCache::pruneResources(PruneStrategy strategy) { | 240 void MemoryCache::pruneResources(PruneStrategy strategy) { |
| 242 DCHECK(!m_prunePending); | 241 DCHECK(!m_prunePending); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 457 } |
| 459 } | 458 } |
| 460 return true; | 459 return true; |
| 461 } | 460 } |
| 462 | 461 |
| 463 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level) { | 462 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level) { |
| 464 pruneAll(); | 463 pruneAll(); |
| 465 } | 464 } |
| 466 | 465 |
| 467 } // namespace blink | 466 } // namespace blink |
| OLD | NEW |