Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: third_party/WebKit/Source/core/fetch/MemoryCache.cpp

Issue 2327643003: Replace ASSERT*() with DCHECK*() in core/fetch/ and core/loader/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 static Persistent<MemoryCache>* gMemoryCache; 38 static Persistent<MemoryCache>* gMemoryCache;
39 39
40 static const unsigned cDefaultCacheCapacity = 8192 * 1024; 40 static const unsigned cDefaultCacheCapacity = 8192 * 1024;
41 static const unsigned cDeferredPruneDeadCapacityFactor = 2; 41 static const unsigned cDeferredPruneDeadCapacityFactor = 2;
42 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds. 42 static const int cMinDelayBeforeLiveDecodedPrune = 1; // Seconds.
43 static const double cMaxPruneDeferralDelay = 0.5; // Seconds. 43 static const double cMaxPruneDeferralDelay = 0.5; // Seconds.
44 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa rd which we prune, to avoid immediately pruning again. 44 static const float cTargetPrunePercentage = .95f; // Percentage of capacity towa rd which we prune, to avoid immediately pruning again.
45 45
46 MemoryCache* memoryCache() 46 MemoryCache* memoryCache()
47 { 47 {
48 ASSERT(WTF::isMainThread()); 48 DCHECK(WTF::isMainThread());
49 if (!gMemoryCache) 49 if (!gMemoryCache)
50 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create()); 50 gMemoryCache = new Persistent<MemoryCache>(MemoryCache::create());
51 return gMemoryCache->get(); 51 return gMemoryCache->get();
52 } 52 }
53 53
54 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache) 54 MemoryCache* replaceMemoryCacheForTesting(MemoryCache* cache)
55 { 55 {
56 memoryCache(); 56 memoryCache();
57 MemoryCache* oldCache = gMemoryCache->release(); 57 MemoryCache* oldCache = gMemoryCache->release();
58 *gMemoryCache = cache; 58 *gMemoryCache = cache;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 String MemoryCache::defaultCacheIdentifier() 150 String MemoryCache::defaultCacheIdentifier()
151 { 151 {
152 return emptyString(); 152 return emptyString();
153 } 153 }
154 154
155 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap(const String& cacheIden tifier) 155 MemoryCache::ResourceMap* MemoryCache::ensureResourceMap(const String& cacheIden tifier)
156 { 156 {
157 if (!m_resourceMaps.contains(cacheIdentifier)) { 157 if (!m_resourceMaps.contains(cacheIdentifier)) {
158 ResourceMapIndex::AddResult result = m_resourceMaps.add(cacheIdentifier, new ResourceMap); 158 ResourceMapIndex::AddResult result = m_resourceMaps.add(cacheIdentifier, new ResourceMap);
159 RELEASE_ASSERT(result.isNewEntry); 159 CHECK(result.isNewEntry);
160 } 160 }
161 return m_resourceMaps.get(cacheIdentifier); 161 return m_resourceMaps.get(cacheIdentifier);
162 } 162 }
163 163
164 void MemoryCache::add(Resource* resource) 164 void MemoryCache::add(Resource* resource)
165 { 165 {
166 ASSERT(WTF::isMainThread()); 166 DCHECK(WTF::isMainThread());
167 ASSERT(resource->url().isValid()); 167 DCHECK(resource->url().isValid());
168 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier()); 168 ResourceMap* resources = ensureResourceMap(resource->cacheIdentifier());
169 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); 169 KURL url = removeFragmentIdentifierIfNeeded(resource->url());
170 CHECK(!contains(resource)); 170 CHECK(!contains(resource));
171 resources->set(url, MemoryCacheEntry::create(resource)); 171 resources->set(url, MemoryCacheEntry::create(resource));
172 update(resource, 0, resource->size(), true); 172 update(resource, 0, resource->size(), true);
173 173
174 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " << resource->url().ge tString() << ", resource " << resource; 174 RESOURCE_LOADING_DVLOG(1) << "MemoryCache::add Added " << resource->url().ge tString() << ", resource " << resource;
175 } 175 }
176 176
177 void MemoryCache::remove(Resource* resource) 177 void MemoryCache::remove(Resource* resource)
178 { 178 {
179 // The resource may have already been removed by someone other than our call er, 179 // The resource may have already been removed by someone other than our call er,
180 // who needed a fresh copy for a reload. 180 // who needed a fresh copy for a reload.
181 if (MemoryCacheEntry* entry = getEntryForResource(resource)) 181 if (MemoryCacheEntry* entry = getEntryForResource(resource))
182 evict(entry); 182 evict(entry);
183 } 183 }
184 184
185 bool MemoryCache::contains(const Resource* resource) const 185 bool MemoryCache::contains(const Resource* resource) const
186 { 186 {
187 return getEntryForResource(resource); 187 return getEntryForResource(resource);
188 } 188 }
189 189
190 Resource* MemoryCache::resourceForURL(const KURL& resourceURL) 190 Resource* MemoryCache::resourceForURL(const KURL& resourceURL)
191 { 191 {
192 return resourceForURL(resourceURL, defaultCacheIdentifier()); 192 return resourceForURL(resourceURL, defaultCacheIdentifier());
193 } 193 }
194 194
195 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, const String& cac heIdentifier) 195 Resource* MemoryCache::resourceForURL(const KURL& resourceURL, const String& cac heIdentifier)
196 { 196 {
197 ASSERT(WTF::isMainThread()); 197 DCHECK(WTF::isMainThread());
198 if (!resourceURL.isValid() || resourceURL.isNull()) 198 if (!resourceURL.isValid() || resourceURL.isNull())
199 return nullptr; 199 return nullptr;
200 ASSERT(!cacheIdentifier.isNull()); 200 DCHECK(!cacheIdentifier.isNull());
201 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier); 201 ResourceMap* resources = m_resourceMaps.get(cacheIdentifier);
202 if (!resources) 202 if (!resources)
203 return nullptr; 203 return nullptr;
204 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); 204 KURL url = removeFragmentIdentifierIfNeeded(resourceURL);
205 MemoryCacheEntry* entry = resources->get(url); 205 MemoryCacheEntry* entry = resources->get(url);
206 if (!entry) 206 if (!entry)
207 return nullptr; 207 return nullptr;
208 return entry->resource(); 208 return entry->resource();
209 } 209 }
210 210
211 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L) 211 HeapVector<Member<Resource>> MemoryCache::resourcesForURL(const KURL& resourceUR L)
212 { 212 {
213 ASSERT(WTF::isMainThread()); 213 DCHECK(WTF::isMainThread());
214 KURL url = removeFragmentIdentifierIfNeeded(resourceURL); 214 KURL url = removeFragmentIdentifierIfNeeded(resourceURL);
215 HeapVector<Member<Resource>> results; 215 HeapVector<Member<Resource>> results;
216 for (const auto& resourceMapIter : m_resourceMaps) { 216 for (const auto& resourceMapIter : m_resourceMaps) {
217 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) { 217 if (MemoryCacheEntry* entry = resourceMapIter.value->get(url)) {
218 Resource* resource = entry->resource(); 218 Resource* resource = entry->resource();
219 DCHECK(resource); 219 DCHECK(resource);
220 results.append(resource); 220 results.append(resource);
221 } 221 }
222 } 222 }
223 return results; 223 return results;
224 } 224 }
225 225
226 size_t MemoryCache::deadCapacity() const 226 size_t MemoryCache::deadCapacity() const
227 { 227 {
228 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum. 228 // Dead resource capacity is whatever space is not occupied by live resource s, bounded by an independent minimum and maximum.
229 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity. 229 size_t capacity = m_capacity - std::min(m_liveSize, m_capacity); // Start wi th available capacity.
230 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum. 230 capacity = std::max(capacity, m_minDeadCapacity); // Make sure it's above th e minimum.
231 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum. 231 capacity = std::min(capacity, m_maxDeadCapacity); // Make sure it's below th e maximum.
232 return capacity; 232 return capacity;
233 } 233 }
234 234
235 size_t MemoryCache::liveCapacity() const 235 size_t MemoryCache::liveCapacity() const
236 { 236 {
237 // Live resource capacity is whatever is left over after calculating dead re source capacity. 237 // Live resource capacity is whatever is left over after calculating dead re source capacity.
238 return m_capacity - deadCapacity(); 238 return m_capacity - deadCapacity();
239 } 239 }
240 240
241 void MemoryCache::pruneLiveResources(PruneStrategy strategy) 241 void MemoryCache::pruneLiveResources(PruneStrategy strategy)
242 { 242 {
243 ASSERT(!m_prunePending); 243 DCHECK(!m_prunePending);
244 size_t capacity = liveCapacity(); 244 size_t capacity = liveCapacity();
245 if (strategy == MaximalPrune) 245 if (strategy == MaximalPrune)
246 capacity = 0; 246 capacity = 0;
247 if (!m_liveSize || (capacity && m_liveSize <= capacity)) 247 if (!m_liveSize || (capacity && m_liveSize <= capacity))
248 return; 248 return;
249 249
250 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again. 250 size_t targetSize = static_cast<size_t>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
251 251
252 // Destroy any decoded data in live objects that we can. 252 // Destroy any decoded data in live objects that we can.
253 // Start from the tail, since this is the lowest priority 253 // Start from the tail, since this is the lowest priority
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // empty LRU lists on future prunes. 348 // empty LRU lists on future prunes.
349 if (m_allResources[i].m_head) 349 if (m_allResources[i].m_head)
350 canShrinkLRULists = false; 350 canShrinkLRULists = false;
351 else if (canShrinkLRULists) 351 else if (canShrinkLRULists)
352 m_allResources.resize(i); 352 m_allResources.resize(i);
353 } 353 }
354 } 354 }
355 355
356 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalBytes) 356 void MemoryCache::setCapacities(size_t minDeadBytes, size_t maxDeadBytes, size_t totalBytes)
357 { 357 {
358 ASSERT(minDeadBytes <= maxDeadBytes); 358 DCHECK_LE(minDeadBytes, maxDeadBytes);
359 ASSERT(maxDeadBytes <= totalBytes); 359 DCHECK_LE(maxDeadBytes, totalBytes);
360 m_minDeadCapacity = minDeadBytes; 360 m_minDeadCapacity = minDeadBytes;
361 m_maxDeadCapacity = maxDeadBytes; 361 m_maxDeadCapacity = maxDeadBytes;
362 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB ytes; 362 m_maxDeferredPruneDeadCapacity = cDeferredPruneDeadCapacityFactor * maxDeadB ytes;
363 m_capacity = totalBytes; 363 m_capacity = totalBytes;
364 prune(); 364 prune();
365 } 365 }
366 366
367 void MemoryCache::evict(MemoryCacheEntry* entry) 367 void MemoryCache::evict(MemoryCacheEntry* entry)
368 { 368 {
369 ASSERT(WTF::isMainThread()); 369 DCHECK(WTF::isMainThread());
370 370
371 Resource* resource = entry->resource(); 371 Resource* resource = entry->resource();
372 DCHECK(resource); 372 DCHECK(resource);
373 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " << resource->url().getString() << " from cache"; 373 RESOURCE_LOADING_DVLOG(1) << "Evicting resource " << resource << " for " << resource->url().getString() << " from cache";
374 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", resource->url().getS tring().utf8()); 374 TRACE_EVENT1("blink", "MemoryCache::evict", "resource", resource->url().getS tring().utf8());
375 // The resource may have already been removed by someone other than our call er, 375 // The resource may have already been removed by someone other than our call er,
376 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>. 376 // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bu g.cgi?id=12479#c6>.
377 update(resource, resource->size(), 0, false); 377 update(resource, resource->size(), 0, false);
378 removeFromLiveDecodedResourcesList(entry); 378 removeFromLiveDecodedResourcesList(entry);
379 379
380 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); 380 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier());
381 ASSERT(resources); 381 DCHECK(resources);
382 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); 382 KURL url = removeFragmentIdentifierIfNeeded(resource->url());
383 ResourceMap::iterator it = resources->find(url); 383 ResourceMap::iterator it = resources->find(url);
384 ASSERT(it != resources->end()); 384 DCHECK_NE(it, resources->end());
385 385
386 MemoryCacheEntry* entryPtr = it->value; 386 MemoryCacheEntry* entryPtr = it->value;
387 resources->remove(it); 387 resources->remove(it);
388 if (entryPtr) 388 if (entryPtr)
389 entryPtr->dispose(); 389 entryPtr->dispose();
390 } 390 }
391 391
392 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con st 392 MemoryCacheEntry* MemoryCache::getEntryForResource(const Resource* resource) con st
393 { 393 {
394 if (!resource || resource->url().isNull() || resource->url().isEmpty()) 394 if (!resource || resource->url().isNull() || resource->url().isEmpty())
395 return nullptr; 395 return nullptr;
396 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier()); 396 ResourceMap* resources = m_resourceMaps.get(resource->cacheIdentifier());
397 if (!resources) 397 if (!resources)
398 return nullptr; 398 return nullptr;
399 KURL url = removeFragmentIdentifierIfNeeded(resource->url()); 399 KURL url = removeFragmentIdentifierIfNeeded(resource->url());
400 MemoryCacheEntry* entry = resources->get(url); 400 MemoryCacheEntry* entry = resources->get(url);
401 if (!entry || entry->resource() != resource) 401 if (!entry || entry->resource() != resource)
402 return nullptr; 402 return nullptr;
403 return entry; 403 return entry;
404 } 404 }
405 405
406 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size) 406 MemoryCacheLRUList* MemoryCache::lruListFor(unsigned accessCount, size_t size)
407 { 407 {
408 ASSERT(accessCount > 0); 408 DCHECK_GT(accessCount, 0u);
409 unsigned queueIndex = WTF::fastLog2(size / accessCount); 409 unsigned queueIndex = WTF::fastLog2(size / accessCount);
410 if (m_allResources.size() <= queueIndex) 410 if (m_allResources.size() <= queueIndex)
411 m_allResources.grow(queueIndex + 1); 411 m_allResources.grow(queueIndex + 1);
412 return &m_allResources[queueIndex]; 412 return &m_allResources[queueIndex];
413 } 413 }
414 414
415 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) 415 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list)
416 { 416 {
417 ASSERT(containedInLRUList(entry, list)); 417 DCHECK(containedInLRUList(entry, list));
418 418
419 MemoryCacheEntry* next = entry->m_nextInAllResourcesList; 419 MemoryCacheEntry* next = entry->m_nextInAllResourcesList;
420 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList; 420 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList;
421 entry->m_nextInAllResourcesList = nullptr; 421 entry->m_nextInAllResourcesList = nullptr;
422 entry->m_previousInAllResourcesList = nullptr; 422 entry->m_previousInAllResourcesList = nullptr;
423 423
424 if (next) 424 if (next)
425 next->m_previousInAllResourcesList = previous; 425 next->m_previousInAllResourcesList = previous;
426 else 426 else
427 list->m_tail = previous; 427 list->m_tail = previous;
428 428
429 if (previous) 429 if (previous)
430 previous->m_nextInAllResourcesList = next; 430 previous->m_nextInAllResourcesList = next;
431 else 431 else
432 list->m_head = next; 432 list->m_head = next;
433 433
434 ASSERT(!containedInLRUList(entry, list)); 434 DCHECK(!containedInLRUList(entry, list));
435 } 435 }
436 436
437 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist) 437 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist)
438 { 438 {
439 ASSERT(!containedInLRUList(entry, list)); 439 DCHECK(!containedInLRUList(entry, list));
440 440
441 entry->m_nextInAllResourcesList = list->m_head; 441 entry->m_nextInAllResourcesList = list->m_head;
442 list->m_head = entry; 442 list->m_head = entry;
443 443
444 if (entry->m_nextInAllResourcesList) 444 if (entry->m_nextInAllResourcesList)
445 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry; 445 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry;
446 else 446 else
447 list->m_tail = entry; 447 list->m_tail = entry;
448 448
449 ASSERT(containedInLRUList(entry, list)); 449 DCHECK(containedInLRUList(entry, list));
450 } 450 }
451 451
452 bool MemoryCache::containedInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList * list) 452 bool MemoryCache::containedInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList * list)
453 { 453 {
454 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) { 454 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) {
455 if (current == entry) 455 if (current == entry)
456 return true; 456 return true;
457 } 457 }
458 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist); 458 DCHECK(!entry->m_nextInAllResourcesList);
459 DCHECK(!entry->m_previousInAllResourcesList);
459 return false; 460 return false;
460 } 461 }
461 462
462 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry) 463 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry)
463 { 464 {
464 // If we've never been accessed, then we're brand new and not in any list. 465 // If we've never been accessed, then we're brand new and not in any list.
465 if (!entry->m_inLiveDecodedResourcesList) 466 if (!entry->m_inLiveDecodedResourcesList)
466 return; 467 return;
467 ASSERT(containedInLiveDecodedResourcesList(entry)); 468 DCHECK(containedInLiveDecodedResourcesList(entry));
468 469
469 entry->m_inLiveDecodedResourcesList = false; 470 entry->m_inLiveDecodedResourcesList = false;
470 471
471 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList; 472 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList;
472 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList; 473 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList;
473 474
474 entry->m_nextInLiveResourcesList = nullptr; 475 entry->m_nextInLiveResourcesList = nullptr;
475 entry->m_previousInLiveResourcesList = nullptr; 476 entry->m_previousInLiveResourcesList = nullptr;
476 477
477 if (next) 478 if (next)
478 next->m_previousInLiveResourcesList = previous; 479 next->m_previousInLiveResourcesList = previous;
479 else 480 else
480 m_liveDecodedResources.m_tail = previous; 481 m_liveDecodedResources.m_tail = previous;
481 482
482 if (previous) 483 if (previous)
483 previous->m_nextInLiveResourcesList = next; 484 previous->m_nextInLiveResourcesList = next;
484 else 485 else
485 m_liveDecodedResources.m_head = next; 486 m_liveDecodedResources.m_head = next;
486 487
487 ASSERT(!containedInLiveDecodedResourcesList(entry)); 488 DCHECK(!containedInLiveDecodedResourcesList(entry));
488 } 489 }
489 490
490 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry) 491 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry)
491 { 492 {
492 ASSERT(!containedInLiveDecodedResourcesList(entry)); 493 DCHECK(!containedInLiveDecodedResourcesList(entry));
493 494
494 entry->m_inLiveDecodedResourcesList = true; 495 entry->m_inLiveDecodedResourcesList = true;
495 496
496 entry->m_nextInLiveResourcesList = m_liveDecodedResources.m_head; 497 entry->m_nextInLiveResourcesList = m_liveDecodedResources.m_head;
497 if (m_liveDecodedResources.m_head) 498 if (m_liveDecodedResources.m_head)
498 m_liveDecodedResources.m_head->m_previousInLiveResourcesList = entry; 499 m_liveDecodedResources.m_head->m_previousInLiveResourcesList = entry;
499 m_liveDecodedResources.m_head = entry; 500 m_liveDecodedResources.m_head = entry;
500 501
501 if (!entry->m_nextInLiveResourcesList) 502 if (!entry->m_nextInLiveResourcesList)
502 m_liveDecodedResources.m_tail = entry; 503 m_liveDecodedResources.m_tail = entry;
503 504
504 ASSERT(containedInLiveDecodedResourcesList(entry)); 505 DCHECK(containedInLiveDecodedResourcesList(entry));
505 } 506 }
506 507
507 bool MemoryCache::containedInLiveDecodedResourcesList(MemoryCacheEntry* entry) 508 bool MemoryCache::containedInLiveDecodedResourcesList(MemoryCacheEntry* entry)
508 { 509 {
509 for (MemoryCacheEntry* current = m_liveDecodedResources.m_head; current; cur rent = current->m_nextInLiveResourcesList) { 510 for (MemoryCacheEntry* current = m_liveDecodedResources.m_head; current; cur rent = current->m_nextInLiveResourcesList) {
510 if (current == entry) { 511 if (current == entry) {
511 ASSERT(entry->m_inLiveDecodedResourcesList); 512 DCHECK(entry->m_inLiveDecodedResourcesList);
512 return true; 513 return true;
513 } 514 }
514 } 515 }
515 ASSERT(!entry->m_nextInLiveResourcesList && !entry->m_previousInLiveResource sList && !entry->m_inLiveDecodedResourcesList); 516 DCHECK(!entry->m_nextInLiveResourcesList);
517 DCHECK(!entry->m_previousInLiveResourcesList);
518 DCHECK(!entry->m_inLiveDecodedResourcesList);
516 return false; 519 return false;
517 } 520 }
518 521
519 void MemoryCache::makeLive(Resource* resource) 522 void MemoryCache::makeLive(Resource* resource)
520 { 523 {
521 if (!contains(resource)) 524 if (!contains(resource))
522 return; 525 return;
523 ASSERT(m_deadSize >= resource->size()); 526 DCHECK_GE(m_deadSize, resource->size());
524 m_liveSize += resource->size(); 527 m_liveSize += resource->size();
525 m_deadSize -= resource->size(); 528 m_deadSize -= resource->size();
526 } 529 }
527 530
528 void MemoryCache::makeDead(Resource* resource) 531 void MemoryCache::makeDead(Resource* resource)
529 { 532 {
530 if (!contains(resource)) 533 if (!contains(resource))
531 return; 534 return;
532 m_liveSize -= resource->size(); 535 m_liveSize -= resource->size();
533 m_deadSize += resource->size(); 536 m_deadSize += resource->size();
(...skipping 10 matching lines...) Expand all
544 // and both of those are used to determine which LRU queue the resource shou ld be in. 547 // and both of those are used to determine which LRU queue the resource shou ld be in.
545 if (oldSize) 548 if (oldSize)
546 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize)); 549 removeFromLRUList(entry, lruListFor(entry->m_accessCount, oldSize));
547 if (wasAccessed) 550 if (wasAccessed)
548 entry->m_accessCount++; 551 entry->m_accessCount++;
549 if (newSize) 552 if (newSize)
550 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize)); 553 insertInLRUList(entry, lruListFor(entry->m_accessCount, newSize));
551 554
552 ptrdiff_t delta = newSize - oldSize; 555 ptrdiff_t delta = newSize - oldSize;
553 if (resource->isAlive()) { 556 if (resource->isAlive()) {
554 ASSERT(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) ); 557 DCHECK(delta >= 0 || m_liveSize >= static_cast<size_t>(-delta) );
555 m_liveSize += delta; 558 m_liveSize += delta;
556 } else { 559 } else {
557 ASSERT(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) ); 560 DCHECK(delta >= 0 || m_deadSize >= static_cast<size_t>(-delta) );
558 m_deadSize += delta; 561 m_deadSize += delta;
559 } 562 }
560 } 563 }
561 564
562 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason) 565 void MemoryCache::updateDecodedResource(Resource* resource, UpdateReason reason)
563 { 566 {
564 MemoryCacheEntry* entry = getEntryForResource(resource); 567 MemoryCacheEntry* entry = getEntryForResource(resource);
565 if (!entry) 568 if (!entry)
566 return; 569 return;
567 570
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 694 }
692 } 695 }
693 696
694 void MemoryCache::willProcessTask() 697 void MemoryCache::willProcessTask()
695 { 698 {
696 } 699 }
697 700
698 void MemoryCache::didProcessTask() 701 void MemoryCache::didProcessTask()
699 { 702 {
700 // Perform deferred pruning 703 // Perform deferred pruning
701 ASSERT(m_prunePending); 704 DCHECK(m_prunePending);
702 pruneNow(WTF::currentTime(), AutomaticPrune); 705 pruneNow(WTF::currentTime(), AutomaticPrune);
703 } 706 }
704 707
705 void MemoryCache::pruneAll() 708 void MemoryCache::pruneAll()
706 { 709 {
707 double currentTime = WTF::currentTime(); 710 double currentTime = WTF::currentTime();
708 pruneNow(currentTime, MaximalPrune); 711 pruneNow(currentTime, MaximalPrune);
709 } 712 }
710 713
711 void MemoryCache::pruneNow(double currentTime, PruneStrategy strategy) 714 void MemoryCache::pruneNow(double currentTime, PruneStrategy strategy)
(...skipping 28 matching lines...) Expand all
740 743
741 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level) 744 void MemoryCache::onMemoryPressure(WebMemoryPressureLevel level)
742 { 745 {
743 pruneAll(); 746 pruneAll();
744 } 747 }
745 748
746 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y) 749 bool MemoryCache::isInSameLRUListForTest(const Resource* x, const Resource* y)
747 { 750 {
748 MemoryCacheEntry* ex = getEntryForResource(x); 751 MemoryCacheEntry* ex = getEntryForResource(x);
749 MemoryCacheEntry* ey = getEntryForResource(y); 752 MemoryCacheEntry* ey = getEntryForResource(y);
750 ASSERT(ex); 753 DCHECK(ex);
751 ASSERT(ey); 754 DCHECK(ey);
752 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size()); 755 return lruListFor(ex->m_accessCount, x->size()) == lruListFor(ey->m_accessCo unt, y->size());
753 } 756 }
754 757
755 } // namespace blink 758 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698