OLD | NEW |
---|---|
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 Loading... | |
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 NSMutableDictionary* dictionary = |
sdefresne
2016/02/09 16:17:07
nit: the recommended pattern in Chromium is to use
jbbegue (google)
2016/02/10 15:10:22
Done.
| |
393 [[NSMutableDictionary alloc] initWithCapacity:2]; | 393 [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease]; |
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[sessionID] forKey:sessionID]; |
407 } else { | 407 } else { |
408 imageDictionary_.reset(dictionary); | 408 imageDictionary_.reset([dictionary retain]); |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 - (void)handleEnterBackground { | 412 - (void)handleEnterBackground { |
413 DCHECK(!IsIPadIdiom()); | 413 DCHECK(!IsIPadIdiom()); |
414 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); | 414 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
415 [imageDictionary_ removeAllObjects]; | 415 [imageDictionary_ removeAllObjects]; |
416 [lruCache_ removeAllObjects]; | 416 [lruCache_ removeAllObjects]; |
417 } | 417 } |
418 | 418 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 } | 575 } |
576 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { | 576 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { |
577 return [greyImageDictionary_ objectForKey:sessionID] != nil; | 577 return [greyImageDictionary_ objectForKey:sessionID] != nil; |
578 } | 578 } |
579 | 579 |
580 - (NSUInteger)lruCacheMaxSize { | 580 - (NSUInteger)lruCacheMaxSize { |
581 return [lruCache_ maxCacheSize]; | 581 return [lruCache_ maxCacheSize]; |
582 } | 582 } |
583 | 583 |
584 @end | 584 @end |
OLD | NEW |