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

Side by Side Diff: ios/chrome/browser/snapshots/snapshot_cache.mm

Issue 1687453002: Fixed leak on LRU snapshot cache implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/snapshots/snapshot_cache.h" 5 #import "ios/chrome/browser/snapshots/snapshot_cache.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/critical_closure.h" 9 #include "base/critical_closure.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 backgroundingColorImage_.reset([[lruCache_ objectForKey:sessionID] retain]); 382 backgroundingColorImage_.reset([[lruCache_ objectForKey:sessionID] retain]);
383 } else { 383 } else {
384 backgroundingColorImage_.reset( 384 backgroundingColorImage_.reset(
385 [[imageDictionary_ objectForKey:sessionID] retain]); 385 [[imageDictionary_ objectForKey:sessionID] retain]);
386 } 386 }
387 } 387 }
388 388
389 - (void)handleLowMemory { 389 - (void)handleLowMemory {
390 DCHECK(!IsIPadIdiom()); 390 DCHECK(!IsIPadIdiom());
391 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); 391 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
392 NSMutableDictionary* dictionary = 392 base::scoped_nsobject<NSMutableDictionary> dictionary(
393 [[NSMutableDictionary alloc] initWithCapacity:2]; 393 [[NSMutableDictionary alloc] initWithCapacity:2]);
394 for (NSString* sessionID in pinnedIDs_) { 394 for (NSString* sessionID in pinnedIDs_) {
395 UIImage* image = nil; 395 UIImage* image = nil;
396 if (lruCache_) 396 if (lruCache_)
397 image = [lruCache_ objectForKey:sessionID]; 397 image = [lruCache_ objectForKey:sessionID];
398 else 398 else
399 image = [imageDictionary_ objectForKey:sessionID]; 399 image = [imageDictionary_ objectForKey:sessionID];
400 if (image) 400 if (image)
401 [dictionary setObject:image forKey:sessionID]; 401 [dictionary setObject:image forKey:sessionID];
402 } 402 }
403 if (lruCache_) { 403 if (lruCache_) {
404 [lruCache_ removeAllObjects]; 404 [lruCache_ removeAllObjects];
405 for (NSString* sessionID in pinnedIDs_) 405 for (NSString* sessionID in pinnedIDs_)
406 [lruCache_ setObject:dictionary[sessionID] forKey:sessionID]; 406 [lruCache_ setObject:[dictionary objectForKey:sessionID]
407 forKey:sessionID];
407 } else { 408 } else {
408 imageDictionary_.reset(dictionary); 409 imageDictionary_ = dictionary;
409 } 410 }
410 } 411 }
411 412
412 - (void)handleEnterBackground { 413 - (void)handleEnterBackground {
413 DCHECK(!IsIPadIdiom()); 414 DCHECK(!IsIPadIdiom());
414 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); 415 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
415 [imageDictionary_ removeAllObjects]; 416 [imageDictionary_ removeAllObjects];
416 [lruCache_ removeAllObjects]; 417 [lruCache_ removeAllObjects];
417 } 418 }
418 419
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 576 }
576 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { 577 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID {
577 return [greyImageDictionary_ objectForKey:sessionID] != nil; 578 return [greyImageDictionary_ objectForKey:sessionID] != nil;
578 } 579 }
579 580
580 - (NSUInteger)lruCacheMaxSize { 581 - (NSUInteger)lruCacheMaxSize {
581 return [lruCache_ maxCacheSize]; 582 return [lruCache_ maxCacheSize];
582 } 583 }
583 584
584 @end 585 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698