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

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

Issue 202243003: Fix crashes in MemoryCache related to successful revalidation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/fetch/MemoryCacheTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 { 320 {
321 unsigned accessCount = std::max(entry->m_resource->accessCount(), 1U); 321 unsigned accessCount = std::max(entry->m_resource->accessCount(), 1U);
322 unsigned queueIndex = WTF::fastLog2(entry->m_resource->size() / accessCount) ; 322 unsigned queueIndex = WTF::fastLog2(entry->m_resource->size() / accessCount) ;
323 if (m_allResources.size() <= queueIndex) 323 if (m_allResources.size() <= queueIndex)
324 m_allResources.grow(queueIndex + 1); 324 m_allResources.grow(queueIndex + 1);
325 return &m_allResources[queueIndex]; 325 return &m_allResources[queueIndex];
326 } 326 }
327 327
328 void MemoryCache::removeFromLRUList(Resource* resource) 328 void MemoryCache::removeFromLRUList(Resource* resource)
329 { 329 {
330 // If we've never been accessed, then we're brand new and not in any list.
331 if (!resource->accessCount())
332 return;
333
334 MemoryCacheEntry* entry = m_resources.get(resource->url()); 330 MemoryCacheEntry* entry = m_resources.get(resource->url());
335 ASSERT(entry->m_resource == resource); 331 ASSERT(entry->m_resource == resource);
332
336 LRUList* list = lruListFor(entry); 333 LRUList* list = lruListFor(entry);
334 MemoryCacheEntry* next = entry->m_nextInAllResourcesList;
335 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList;
336 if (!next && !previous && list->m_head != entry)
337 return;
337 338
338 #if !ASSERT_DISABLED 339 #if !ASSERT_DISABLED
339 // Verify that we are in fact in this list. 340 // Verify that we are in fact in this list.
340 bool found = false; 341 bool found = false;
341 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) { 342 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) {
342 if (current == entry) { 343 if (current == entry) {
343 found = true; 344 found = true;
344 break; 345 break;
345 } 346 }
346 } 347 }
347 ASSERT(found); 348 ASSERT(found);
348 #endif 349 #endif
349 350
350 MemoryCacheEntry* next = entry->m_nextInAllResourcesList;
351 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList;
352
353 entry->m_nextInAllResourcesList = 0; 351 entry->m_nextInAllResourcesList = 0;
354 entry->m_previousInAllResourcesList = 0; 352 entry->m_previousInAllResourcesList = 0;
355 353
356 if (next) 354 if (next)
357 next->m_previousInAllResourcesList = previous; 355 next->m_previousInAllResourcesList = previous;
358 else 356 else
359 list->m_tail = previous; 357 list->m_tail = previous;
360 358
361 if (previous) 359 if (previous)
362 previous->m_nextInAllResourcesList = next; 360 previous->m_nextInAllResourcesList = next;
363 else 361 else
364 list->m_head = next; 362 list->m_head = next;
365 } 363 }
366 364
367 void MemoryCache::insertInLRUList(Resource* resource) 365 void MemoryCache::insertInLRUList(Resource* resource)
368 { 366 {
369 MemoryCacheEntry* entry = m_resources.get(resource->url()); 367 MemoryCacheEntry* entry = m_resources.get(resource->url());
370 ASSERT(entry->m_resource == resource); 368 ASSERT(entry->m_resource == resource);
371 369
372 // Make sure we aren't in some list already. 370 // Make sure we aren't in some list already.
373 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist); 371 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist);
374 ASSERT(resource->inCache()); 372 ASSERT(resource->inCache());
375 ASSERT(resource->accessCount() > 0);
376 373
377 LRUList* list = lruListFor(entry); 374 LRUList* list = lruListFor(entry);
378 375
379 entry->m_nextInAllResourcesList = list->m_head; 376 entry->m_nextInAllResourcesList = list->m_head;
380 if (list->m_head) 377 if (list->m_head)
381 list->m_head->m_previousInAllResourcesList = entry; 378 list->m_head->m_previousInAllResourcesList = entry;
382 list->m_head = entry; 379 list->m_head = entry;
383 380
384 if (!entry->m_nextInAllResourcesList) 381 if (!entry->m_nextInAllResourcesList)
385 list->m_tail = entry; 382 list->m_tail = entry;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 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()); 679 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());
683 680
684 current = prev; 681 current = prev;
685 } 682 }
686 } 683 }
687 } 684 }
688 685
689 #endif // MEMORY_CACHE_STATS 686 #endif // MEMORY_CACHE_STATS
690 687
691 } // namespace WebCore 688 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/core/fetch/MemoryCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698