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) 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 // Strip away fragment identifier from HTTP URLs. | 146 // Strip away fragment identifier from HTTP URLs. |
| 147 // Data URLs must be unmodified. For file and custom URLs clients may expect resources | 147 // Data URLs must be unmodified. For file and custom URLs clients may expect resources |
| 148 // to be unique even when they differ by the fragment identifier only. | 148 // to be unique even when they differ by the fragment identifier only. |
| 149 if (!originalURL.protocolIsInHTTPFamily()) | 149 if (!originalURL.protocolIsInHTTPFamily()) |
| 150 return originalURL; | 150 return originalURL; |
| 151 KURL url = originalURL; | 151 KURL url = originalURL; |
| 152 url.removeFragmentIdentifier(); | 152 url.removeFragmentIdentifier(); |
| 153 return url; | 153 return url; |
| 154 } | 154 } |
| 155 | 155 |
| 156 String MemoryCache::defaultCacheIdentifier() | |
| 157 { | |
| 158 return emptyString(); | |
| 159 } | |
| 160 | |
| 161 MemoryCache::ResourceMap* MemoryCache::getResourceMap(const String& cacheIdentif ier) | |
| 162 { | |
| 163 if (!m_resources.contains(cacheIdentifier)) | |
| 164 m_resources.add(cacheIdentifier, adoptPtrWillBeNoop(new ResourceMap())); | |
|
Mike West
2014/10/24 12:42:59
`add()` can fail, can't it? That could cause a nul
nhiroki
2014/10/27 14:30:12
Hmmm... I think a null-deref never happens because
| |
| 165 return m_resources.get(cacheIdentifier); | |
| 166 } | |
| 167 | |
| 156 void MemoryCache::add(Resource* resource) | 168 void MemoryCache::add(Resource* resource) |
| 157 { | 169 { |
| 158 ASSERT(WTF::isMainThread()); | 170 ASSERT(WTF::isMainThread()); |
| 159 ASSERT(resource->url().isValid()); | 171 ASSERT(resource->url().isValid()); |
| 160 RELEASE_ASSERT(!m_resources.contains(resource->url())); | 172 ResourceMap* resources = getResourceMap(resource->cacheIdentifier()); |
| 161 m_resources.set(resource->url().string(), MemoryCacheEntry::create(resource) ); | 173 RELEASE_ASSERT(!resources->contains(resource->url())); |
| 174 resources->set(resource->url(), MemoryCacheEntry::create(resource)); | |
| 162 update(resource, 0, resource->size(), true); | 175 update(resource, 0, resource->size(), true); |
| 163 | 176 |
| 164 WTF_LOG(ResourceLoading, "MemoryCache::add Added '%s', resource %p\n", resou rce->url().string().latin1().data(), resource); | 177 WTF_LOG(ResourceLoading, "MemoryCache::add Added '%s', resource %p\n", resou rce->url().string().latin1().data(), resource); |
| 165 } | 178 } |
| 166 | 179 |
| 167 void MemoryCache::replace(Resource* newResource, Resource* oldResource) | 180 void MemoryCache::replace(Resource* newResource, Resource* oldResource) |
| 168 { | 181 { |
| 169 if (MemoryCacheEntry* oldEntry = m_resources.get(oldResource->url())) | 182 ASSERT(newResource->cacheIdentifier() == oldResource->cacheIdentifier()); |
| 183 ResourceMap* resources = getResourceMap(oldResource->cacheIdentifier()); | |
| 184 if (MemoryCacheEntry* oldEntry = resources->get(oldResource->url())) | |
| 170 evict(oldEntry); | 185 evict(oldEntry); |
| 171 add(newResource); | 186 add(newResource); |
| 172 if (newResource->decodedSize() && newResource->hasClients()) | 187 if (newResource->decodedSize() && newResource->hasClients()) |
| 173 insertInLiveDecodedResourcesList(m_resources.get(newResource->url())); | 188 insertInLiveDecodedResourcesList(resources->get(newResource->url())); |
| 174 } | 189 } |
| 175 | 190 |
| 176 void MemoryCache::remove(Resource* resource) | 191 void MemoryCache::remove(Resource* resource) |
| 177 { | 192 { |
| 178 // The resource may have already been removed by someone other than our call er, | 193 // The resource may have already been removed by someone other than our call er, |
| 179 // who needed a fresh copy for a reload. | 194 // who needed a fresh copy for a reload. |
| 180 if (!contains(resource)) | 195 if (!contains(resource)) |
|
Mike West
2014/10/24 12:42:59
Rather than doing the lookup twice, it might make
nhiroki
2014/10/27 14:30:13
Good point! Removed redundant contains() calls.
| |
| 181 return; | 196 return; |
| 182 evict(m_resources.get(resource->url())); | 197 evict(getEntryForResource(resource)); |
| 183 } | 198 } |
| 184 | 199 |
| 185 bool MemoryCache::contains(const Resource* resource) const | 200 bool MemoryCache::contains(const Resource* resource) const |
| 186 { | 201 { |
| 187 if (resource->url().isNull()) | 202 if (resource->url().isNull()) |
| 188 return false; | 203 return false; |
| 189 const MemoryCacheEntry* entry = m_resources.get(resource->url()); | 204 ResourceMap* resources = m_resources.get(resource->cacheIdentifier()); |
|
Mike West
2014/10/24 12:43:00
It's odd to have `getResourceMap` and not use it h
nhiroki
2014/10/27 14:30:12
Yes, that's right.
| |
| 205 if (!resources) | |
| 206 return false; | |
| 207 MemoryCacheEntry* entry = resources->get(resource->url()); | |
| 190 return entry && entry->m_resource == resource; | 208 return entry && entry->m_resource == resource; |
| 191 } | 209 } |
| 192 | 210 |
| 193 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) | 211 Resource* MemoryCache::resourceForURL(const String& cacheIdentifier, const KURL& resourceURL) |
| 194 { | 212 { |
| 195 ASSERT(WTF::isMainThread()); | 213 ASSERT(WTF::isMainThread()); |
| 214 ResourceMap* resources = getResourceMap(cacheIdentifier); | |
| 196 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | 215 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); |
| 197 MemoryCacheEntry* entry = m_resources.get(url); | 216 MemoryCacheEntry* entry = resources->get(url); |
| 198 if (!entry) | 217 if (!entry) |
| 199 return 0; | 218 return 0; |
| 200 Resource* resource = entry->m_resource.get(); | 219 Resource* resource = entry->m_resource.get(); |
| 201 if (resource && !resource->lock()) { | 220 if (resource && !resource->lock()) { |
| 202 ASSERT(!resource->hasClients()); | 221 ASSERT(!resource->hasClients()); |
| 203 bool didEvict = evict(entry); | 222 bool didEvict = evict(entry); |
| 204 ASSERT_UNUSED(didEvict, didEvict); | 223 ASSERT_UNUSED(didEvict, didEvict); |
| 205 return 0; | 224 return 0; |
| 206 } | 225 } |
| 207 return resource; | 226 return resource; |
| 208 } | 227 } |
| 209 | 228 |
| 229 WillBeHeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& reso urceURL) | |
| 230 { | |
| 231 ASSERT(WTF::isMainThread()); | |
| 232 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); | |
| 233 WillBeHeapVector<Member<Resource>> results; | |
| 234 for (const auto& resources : m_resources) { | |
|
Mike West
2014/10/24 12:42:59
"ResourceMap" seems clearer than "auto".
nhiroki
2014/10/27 14:30:12
"m_resources" is a HashMap object, so this "auto"
| |
| 235 MemoryCacheEntry* entry = resources.value->get(url); | |
| 236 if (entry) | |
| 237 results.append(entry->m_resource.get()); | |
| 238 } | |
| 239 return results; | |
| 240 } | |
| 241 | |
| 210 size_t MemoryCache::deadCapacity() const | 242 size_t MemoryCache::deadCapacity() const |
| 211 { | 243 { |
| 212 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum. | 244 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum. |
| 213 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity. | 245 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity. |
| 214 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum. | 246 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum. |
| 215 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum. | 247 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum. |
| 216 return capacity; | 248 return capacity; |
| 217 } | 249 } |
| 218 | 250 |
| 219 size_t MemoryCache::liveCapacity() const | 251 size_t MemoryCache::liveCapacity() const |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 ASSERT(WTF::isMainThread()); | 399 ASSERT(WTF::isMainThread()); |
| 368 | 400 |
| 369 Resource* resource = entry->m_resource.get(); | 401 Resource* resource = entry->m_resource.get(); |
| 370 bool canDelete = resource->canDelete(); | 402 bool canDelete = resource->canDelete(); |
| 371 WTF_LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resourc e, resource->url().string().latin1().data()); | 403 WTF_LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", resourc e, resource->url().string().latin1().data()); |
| 372 // The resource may have already been removed by someone other than our call er, | 404 // The resource may have already been removed by someone other than our call er, |
| 373 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>. | 405 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>. |
| 374 update(resource, resource->size(), 0, false); | 406 update(resource, resource->size(), 0, false); |
| 375 removeFromLiveDecodedResourcesList(entry); | 407 removeFromLiveDecodedResourcesList(entry); |
| 376 | 408 |
| 377 ResourceMap::iterator it = m_resources.find(resource->url()); | 409 ResourceMap* resources = getResourceMap(resource->cacheIdentifier()); |
| 378 ASSERT(it != m_resources.end()); | 410 ResourceMap::iterator it = resources->find(resource->url()); |
| 411 ASSERT(it != resources->end()); | |
| 379 #if ENABLE(OILPAN) | 412 #if ENABLE(OILPAN) |
| 380 MemoryCacheEntry* entryPtr = it->value; | 413 MemoryCacheEntry* entryPtr = it->value; |
| 381 #else | 414 #else |
| 382 OwnPtr<MemoryCacheEntry> entryPtr; | 415 OwnPtr<MemoryCacheEntry> entryPtr; |
| 383 entryPtr.swap(it->value); | 416 entryPtr.swap(it->value); |
| 384 #endif | 417 #endif |
| 385 m_resources.remove(it); | 418 resources->remove(it); |
| 386 #if ENABLE(OILPAN) | 419 #if ENABLE(OILPAN) |
| 387 if (entryPtr) | 420 if (entryPtr) |
| 388 entryPtr->dispose(); | 421 entryPtr->dispose(); |
| 389 #endif | 422 #endif |
| 390 return canDelete; | 423 return canDelete; |
| 391 } | 424 } |
| 392 | 425 |
| 426 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con st | |
| 427 { | |
| 428 if (resource->url().isNull()) | |
|
Mike West
2014/10/24 12:43:00
isNull or isEmpty?
nhiroki
2014/10/27 14:30:13
Done.
| |
| 429 return nullptr; | |
| 430 ResourceMap* resources = m_resources.get(resource->cacheIdentifier()); | |
| 431 if (!resources) | |
| 432 return nullptr; | |
| 433 MemoryCacheEntry* entry = resources->get(resource->url()); | |
| 434 if (!entry || entry->m_resource != resource) | |
| 435 return nullptr; | |
| 436 return entry; | |
| 437 } | |
| 438 | |
| 393 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size) | 439 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size) |
| 394 { | 440 { |
| 395 ASSERT(accessCount > 0); | 441 ASSERT(accessCount > 0); |
| 396 unsigned queueIndex = WTF::fastLog2(size / accessCount); | 442 unsigned queueIndex = WTF::fastLog2(size / accessCount); |
| 397 if (m_allResources.size() <= queueIndex) | 443 if (m_allResources.size() <= queueIndex) |
| 398 m_allResources.grow(queueIndex + 1); | 444 m_allResources.grow(queueIndex + 1); |
| 399 return &m_allResources[queueIndex]; | 445 return &m_allResources[queueIndex]; |
| 400 } | 446 } |
| 401 | 447 |
| 402 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) | 448 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 m_liveSize += resource->size(); | 561 m_liveSize += resource->size(); |
| 516 m_deadSize -= resource->size(); | 562 m_deadSize -= resource->size(); |
| 517 } | 563 } |
| 518 | 564 |
| 519 void MemoryCache::makeDead(Resource* resource) | 565 void MemoryCache::makeDead(Resource* resource) |
| 520 { | 566 { |
| 521 if (!contains(resource)) | 567 if (!contains(resource)) |
| 522 return; | 568 return; |
| 523 m_liveSize -= resource->size(); | 569 m_liveSize -= resource->size(); |
| 524 m_deadSize += resource->size(); | 570 m_deadSize += resource->size(); |
| 525 removeFromLiveDecodedResourcesList(m_resources.get(resource->url())); | 571 removeFromLiveDecodedResourcesList(getEntryForResource(resource)); |
| 526 } | 572 } |
| 527 | 573 |
| 528 void MemoryCache::update(Resource* resource, size_t oldSize, size_t newSize, boo l wasAccessed) | 574 void MemoryCache::update(Resource* resource, size_t oldSize, size_t newSize, boo l wasAccessed) |
| 529 { | 575 { |
| 530 if (!contains(resource)) | 576 if (!contains(resource)) |
| 531 return; | 577 return; |
| 532 MemoryCacheEntry* entry = m_resources.get(resource->url()); | 578 MemoryCacheEntry* entry = getEntryForResource(resource); |
| 533 | 579 |
| 534 // The object must now be moved to a different queue, since either its size or its accessCount has been changed, | 580 // The object must now be moved to a different queue, since either its size or its accessCount has been changed, |
| 535 // and both of those are used to determine which LRU queue the resource shou ld be in. | 581 // and both of those are used to determine which LRU queue the resource shou ld be in. |
| 536 if (oldSize) | 582 if (oldSize) |
| 537 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); | 583 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); |
| 538 if (wasAccessed) | 584 if (wasAccessed) |
| 539 entry->m_accessCount++; | 585 entry->m_accessCount++; |
| 540 if (newSize) | 586 if (newSize) |
| 541 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); | 587 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); |
| 542 | 588 |
| 543 ptrdiff_t delta = newSize - oldSize; | 589 ptrdiff_t delta = newSize - oldSize; |
| 544 if (resource->hasClients()) { | 590 if (resource->hasClients()) { |
| 545 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); | 591 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); |
| 546 m_liveSize += delta; | 592 m_liveSize += delta; |
| 547 } else { | 593 } else { |
| 548 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); | 594 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); |
| 549 m_deadSize += delta; | 595 m_deadSize += delta; |
| 550 } | 596 } |
| 551 } | 597 } |
| 552 | 598 |
| 553 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason, MemoryCacheLiveResourcePriority priority) | 599 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason, MemoryCacheLiveResourcePriority priority) |
| 554 { | 600 { |
| 555 if (!contains(resource)) | 601 if (!contains(resource)) |
| 556 return; | 602 return; |
| 557 MemoryCacheEntry* entry = m_resources.get(resource->url()); | 603 MemoryCacheEntry* entry = getEntryForResource(resource); |
| 558 | 604 |
| 559 removeFromLiveDecodedResourcesList(entry); | 605 removeFromLiveDecodedResourcesList(entry); |
| 560 if (priority != MemoryCacheLiveResourcePriorityUnknown && priority != entry- >m_liveResourcePriority) | 606 if (priority != MemoryCacheLiveResourcePriorityUnknown && priority != entry- >m_liveResourcePriority) |
| 561 entry->m_liveResourcePriority = priority; | 607 entry->m_liveResourcePriority = priority; |
| 562 if (resource->decodedSize() && resource->hasClients()) | 608 if (resource->decodedSize() && resource->hasClients()) |
| 563 insertInLiveDecodedResourcesList(entry); | 609 insertInLiveDecodedResourcesList(entry); |
| 564 | 610 |
| 565 if (reason != UpdateForAccess) | 611 if (reason != UpdateForAccess) |
| 566 return; | 612 return; |
| 567 | 613 |
| 568 double timestamp = resource->isImage() ? FrameView::currentFrameTimeStamp() : 0.0; | 614 double timestamp = resource->isImage() ? FrameView::currentFrameTimeStamp() : 0.0; |
| 569 if (!timestamp) | 615 if (!timestamp) |
| 570 timestamp = currentTime(); | 616 timestamp = currentTime(); |
| 571 entry->m_lastDecodedAccessTime = timestamp; | 617 entry->m_lastDecodedAccessTime = timestamp; |
| 572 } | 618 } |
| 573 | 619 |
| 574 MemoryCacheLiveResourcePriority MemoryCache::priority(Resource* resource) const | 620 MemoryCacheLiveResourcePriority MemoryCache::priority(Resource* resource) const |
| 575 { | 621 { |
| 576 if (!contains(resource)) | 622 if (!contains(resource)) |
| 577 return MemoryCacheLiveResourcePriorityUnknown; | 623 return MemoryCacheLiveResourcePriorityUnknown; |
| 578 MemoryCacheEntry* entry = m_resources.get(resource->url()); | 624 MemoryCacheEntry* entry = getEntryForResource(resource); |
| 579 return entry->m_liveResourcePriority; | 625 return entry->m_liveResourcePriority; |
| 580 } | 626 } |
| 581 | 627 |
| 582 void MemoryCache::removeURLFromCache(ExecutionContext* context, const KURL& url) | 628 void MemoryCache::removeURLFromCache(ExecutionContext* context, const KURL& url) |
| 583 { | 629 { |
| 584 if (context->isWorkerGlobalScope()) { | 630 if (context->isWorkerGlobalScope()) { |
| 585 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); | 631 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
| 586 workerGlobalScope->thread()->workerLoaderProxy().postTaskToLoader(create CrossThreadTask(&removeURLFromCacheInternal, url)); | 632 workerGlobalScope->thread()->workerLoaderProxy().postTaskToLoader(create CrossThreadTask(&removeURLFromCacheInternal, url)); |
| 587 return; | 633 return; |
| 588 } | 634 } |
| 589 removeURLFromCacheInternal(context, url); | 635 removeURLFromCacheInternal(context, url); |
| 590 } | 636 } |
| 591 | 637 |
| 592 void MemoryCache::removeURLFromCacheInternal(ExecutionContext*, const KURL& url) | 638 void MemoryCache::removeURLFromCacheInternal(ExecutionContext*, const KURL& url) |
| 593 { | 639 { |
| 594 if (Resource* resource = memoryCache()->resourceForURL(url)) | 640 auto resources = memoryCache()->resourcesForURL(url); |
| 641 for (const auto& resource : resources) | |
|
Mike West
2014/10/24 12:42:59
"Resource" seems clearer than "auto".
nhiroki
2014/10/27 14:30:12
Done.
| |
| 595 memoryCache()->remove(resource); | 642 memoryCache()->remove(resource); |
| 596 } | 643 } |
| 597 | 644 |
| 598 void MemoryCache::TypeStatistic::addResource(Resource* o) | 645 void MemoryCache::TypeStatistic::addResource(Resource* o) |
| 599 { | 646 { |
| 600 bool purged = o->wasPurged(); | 647 bool purged = o->wasPurged(); |
| 601 bool purgeable = o->isPurgeable() && !purged; | 648 bool purgeable = o->isPurgeable() && !purged; |
| 602 size_t pageSize = (o->encodedSize() + o->overheadSize() + 4095) & ~4095; | 649 size_t pageSize = (o->encodedSize() + o->overheadSize() + 4095) & ~4095; |
| 603 count++; | 650 count++; |
| 604 size += purged ? 0 : o->size(); | 651 size += purged ? 0 : o->size(); |
| 605 liveSize += o->hasClients() ? o->size() : 0; | 652 liveSize += o->hasClients() ? o->size() : 0; |
| 606 decodedSize += o->decodedSize(); | 653 decodedSize += o->decodedSize(); |
| 607 encodedSize += o->encodedSize(); | 654 encodedSize += o->encodedSize(); |
| 608 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz e() : 0; | 655 encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSiz e() : 0; |
| 609 purgeableSize += purgeable ? pageSize : 0; | 656 purgeableSize += purgeable ? pageSize : 0; |
| 610 purgedSize += purged ? pageSize : 0; | 657 purgedSize += purged ? pageSize : 0; |
| 611 } | 658 } |
| 612 | 659 |
| 613 MemoryCache::Statistics MemoryCache::getStatistics() | 660 MemoryCache::Statistics MemoryCache::getStatistics() |
| 614 { | 661 { |
| 615 Statistics stats; | 662 Statistics stats; |
| 616 for (const auto& resourceIter : m_resources) { | 663 for (const auto& resources : m_resources) { |
|
Mike West
2014/10/24 12:42:59
"ResourceMap* resourceMap" seems clearer.
nhiroki
2014/10/27 14:30:13
Ditto ("const OwnPtr<ResourceMap>& resources"?).
| |
| 617 Resource* resource = resourceIter.value->m_resource.get(); | 664 for (const auto& resourceIter : *resources.value) { |
|
Mike West
2014/10/24 12:42:59
Resource rather than auto.
nhiroki
2014/10/27 14:30:12
Ditto.
| |
| 618 switch (resource->type()) { | 665 Resource* resource = resourceIter.value->m_resource.get(); |
| 619 case Resource::Image: | 666 switch (resource->type()) { |
| 620 stats.images.addResource(resource); | 667 case Resource::Image: |
| 621 break; | 668 stats.images.addResource(resource); |
| 622 case Resource::CSSStyleSheet: | 669 break; |
| 623 stats.cssStyleSheets.addResource(resource); | 670 case Resource::CSSStyleSheet: |
| 624 break; | 671 stats.cssStyleSheets.addResource(resource); |
| 625 case Resource::Script: | 672 break; |
| 626 stats.scripts.addResource(resource); | 673 case Resource::Script: |
| 627 break; | 674 stats.scripts.addResource(resource); |
| 628 case Resource::XSLStyleSheet: | 675 break; |
| 629 stats.xslStyleSheets.addResource(resource); | 676 case Resource::XSLStyleSheet: |
| 630 break; | 677 stats.xslStyleSheets.addResource(resource); |
| 631 case Resource::Font: | 678 break; |
| 632 stats.fonts.addResource(resource); | 679 case Resource::Font: |
| 633 break; | 680 stats.fonts.addResource(resource); |
| 634 default: | 681 break; |
| 635 stats.other.addResource(resource); | 682 default: |
| 636 break; | 683 stats.other.addResource(resource); |
| 684 break; | |
| 685 } | |
| 637 } | 686 } |
| 638 } | 687 } |
| 639 return stats; | 688 return stats; |
| 640 } | 689 } |
| 641 | 690 |
| 642 void MemoryCache::evictResources() | 691 void MemoryCache::evictResources() |
| 643 { | 692 { |
| 644 for (;;) { | 693 for (;;) { |
| 645 ResourceMap::iterator i = m_resources.begin(); | 694 ResourceMapIndex::iterator indexIter = m_resources.begin(); |
| 646 if (i == m_resources.end()) | 695 if (indexIter == m_resources.end()) |
| 647 break; | 696 break; |
| 648 evict(i->value.get()); | 697 ResourceMap* resources = indexIter->value.get(); |
| 698 for (;;) { | |
|
Mike West
2014/10/24 12:42:59
Would you mind changing this, and line 693, to `wh
nhiroki
2014/10/27 14:30:13
Done.
| |
| 699 ResourceMap::iterator resourceIter = resources->begin(); | |
| 700 if (resourceIter == resources->end()) | |
| 701 break; | |
| 702 evict(resourceIter->value.get()); | |
| 703 } | |
| 704 m_resources.remove(indexIter); | |
| 649 } | 705 } |
| 650 } | 706 } |
| 651 | 707 |
| 652 void MemoryCache::prune(Resource* justReleasedResource) | 708 void MemoryCache::prune(Resource* justReleasedResource) |
| 653 { | 709 { |
| 654 TRACE_EVENT0("renderer", "MemoryCache::prune()"); | 710 TRACE_EVENT0("renderer", "MemoryCache::prune()"); |
| 655 | 711 |
| 656 if (m_inPruneResources) | 712 if (m_inPruneResources) |
| 657 return; | 713 return; |
| 658 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && m_deadSize <= m_maxDeadCapacity) // Fast path. | 714 if (m_liveSize + m_deadSize <= m_capacity && m_maxDeadCapacity && m_deadSize <= m_maxDeadCapacity) // Fast path. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 683 if (m_prunePending && m_deadSize > m_maxDeferredPruneDeadCapacity && justRel easedResource) { | 739 if (m_prunePending && m_deadSize > m_maxDeferredPruneDeadCapacity && justRel easedResource) { |
| 684 // The following eviction does not respect LRU order, but it can be done | 740 // The following eviction does not respect LRU order, but it can be done |
| 685 // immediately in constant time, as opposed to pruneDeadResources, which | 741 // immediately in constant time, as opposed to pruneDeadResources, which |
| 686 // we would rather defer because it is O(N), which would make tear-down of N | 742 // we would rather defer because it is O(N), which would make tear-down of N |
| 687 // objects O(N^2) if we pruned immediately. This immediate eviction is a | 743 // objects O(N^2) if we pruned immediately. This immediate eviction is a |
| 688 // safeguard against runaway memory consumption by dead resources | 744 // safeguard against runaway memory consumption by dead resources |
| 689 // while a prune is pending. | 745 // while a prune is pending. |
| 690 // Main Resources in the cache are only substitue data that was | 746 // Main Resources in the cache are only substitue data that was |
| 691 // precached and should not be evicted. | 747 // precached and should not be evicted. |
| 692 if (contains(justReleasedResource) && justReleasedResource->type() != Re source::MainResource) | 748 if (contains(justReleasedResource) && justReleasedResource->type() != Re source::MainResource) |
| 693 evict(m_resources.get(justReleasedResource->url())); | 749 evict(getEntryForResource(justReleasedResource)); |
| 694 | 750 |
| 695 // As a last resort, prune immediately | 751 // As a last resort, prune immediately |
| 696 if (m_deadSize > m_maxDeferredPruneDeadCapacity) | 752 if (m_deadSize > m_maxDeferredPruneDeadCapacity) |
| 697 pruneNow(currentTime); | 753 pruneNow(currentTime); |
| 698 } | 754 } |
| 699 } | 755 } |
| 700 | 756 |
| 701 void MemoryCache::willProcessTask() | 757 void MemoryCache::willProcessTask() |
| 702 { | 758 { |
| 703 } | 759 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was Purged()); | 841 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was Purged()); |
| 786 | 842 |
| 787 current = prev; | 843 current = prev; |
| 788 } | 844 } |
| 789 } | 845 } |
| 790 } | 846 } |
| 791 | 847 |
| 792 #endif // MEMORY_CACHE_STATS | 848 #endif // MEMORY_CACHE_STATS |
| 793 | 849 |
| 794 } // namespace blink | 850 } // namespace blink |
| OLD | NEW |