Index: ios/chrome/browser/snapshots/snapshot_cache.mm |
diff --git a/ios/chrome/browser/snapshots/snapshot_cache.mm b/ios/chrome/browser/snapshots/snapshot_cache.mm |
index 59dad9c73eb111355d928ed444b5cc159ad59dfb..2ba981775814ecb6c9c1226ebf0700f27c48acba 100644 |
--- a/ios/chrome/browser/snapshots/snapshot_cache.mm |
+++ b/ios/chrome/browser/snapshots/snapshot_cache.mm |
@@ -140,42 +140,46 @@ void ConvertAndSaveGreyImage( |
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]); |
- // TODO(andybons): In the case where the cache grows, it is expensive. |
- // Make sure this doesn't suck when there are more than ten tabs. |
- imageDictionary_.reset( |
- [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); |
- [[NSNotificationCenter defaultCenter] |
- addObserver:self |
- selector:@selector(handleLowMemory) |
- name:UIApplicationDidReceiveMemoryWarningNotification |
- object:nil]; |
- [[NSNotificationCenter defaultCenter] |
- addObserver:self |
- selector:@selector(handleEnterBackground) |
- name:UIApplicationDidEnterBackgroundNotification |
- object:nil]; |
- [[NSNotificationCenter defaultCenter] |
- addObserver:self |
- selector:@selector(handleBecomeActive) |
- name:UIApplicationDidBecomeActiveNotification |
- object:nil]; |
+ if (!IsIPadIdiom()) { |
+ // TODO(jbbegue): In the case where the cache grows, it is expensive. |
+ // Make sure this doesn't suck when there are more than ten tabs. |
+ imageDictionary_.reset( |
+ [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); |
+ [[NSNotificationCenter defaultCenter] |
+ addObserver:self |
+ selector:@selector(handleLowMemory) |
+ name:UIApplicationDidReceiveMemoryWarningNotification |
+ object:nil]; |
+ [[NSNotificationCenter defaultCenter] |
+ addObserver:self |
+ selector:@selector(handleEnterBackground) |
+ name:UIApplicationDidEnterBackgroundNotification |
+ object:nil]; |
+ [[NSNotificationCenter defaultCenter] |
+ addObserver:self |
+ selector:@selector(handleBecomeActive) |
+ name:UIApplicationDidBecomeActiveNotification |
+ object:nil]; |
+ } |
} |
return self; |
} |
- (void)dealloc { |
- [[NSNotificationCenter defaultCenter] |
- removeObserver:self |
- name:UIApplicationDidReceiveMemoryWarningNotification |
- object:nil]; |
- [[NSNotificationCenter defaultCenter] |
- removeObserver:self |
- name:UIApplicationDidEnterBackgroundNotification |
- object:nil]; |
- [[NSNotificationCenter defaultCenter] |
- removeObserver:self |
- name:UIApplicationDidBecomeActiveNotification |
- object:nil]; |
+ if (!IsIPadIdiom()) { |
+ [[NSNotificationCenter defaultCenter] |
+ removeObserver:self |
+ name:UIApplicationDidReceiveMemoryWarningNotification |
+ object:nil]; |
+ [[NSNotificationCenter defaultCenter] |
+ removeObserver:self |
+ name:UIApplicationDidEnterBackgroundNotification |
+ object:nil]; |
+ [[NSNotificationCenter defaultCenter] |
+ removeObserver:self |
+ name:UIApplicationDidBecomeActiveNotification |
+ object:nil]; |
+ } |
[super dealloc]; |
} |
@@ -195,6 +199,11 @@ void ConvertAndSaveGreyImage( |
callback:(void (^)(UIImage*))callback { |
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
DCHECK(sessionID); |
+ // iPad does not cache images, so if there is no callback we can avoid an |
+ // expensive read from storage. |
+ if (IsIPadIdiom() && !callback) |
+ return; |
+ |
UIImage* img = [imageDictionary_ objectForKey:sessionID]; |
if (img) { |
if (callback) |
@@ -205,14 +214,16 @@ void ConvertAndSaveGreyImage( |
base::PostTaskAndReplyWithResult( |
web::WebThread::GetMessageLoopProxyForThread( |
web::WebThread::FILE_USER_BLOCKING).get(), |
- FROM_HERE, |
- base::BindBlock(^base::scoped_nsobject<UIImage>() { |
+ FROM_HERE, base::BindBlock(^base::scoped_nsobject<UIImage>() { |
// Retrieve the image on a high priority thread. |
return base::scoped_nsobject<UIImage>([ReadImageFromDisk( |
[SnapshotCache imagePathForSessionID:sessionID]) retain]); |
}), |
base::BindBlock(^(base::scoped_nsobject<UIImage> image) { |
- if (image) |
+ // The iPad tab switcher is currently using its own memory cache so the |
+ // image is not stored in memory here if running on iPad. |
+ // The same logic is used on image writes (code below). |
+ if (!IsIPadIdiom() && image) |
[imageDictionary_ setObject:image forKey:sessionID]; |
if (callback) |
callback(image); |
@@ -224,7 +235,9 @@ void ConvertAndSaveGreyImage( |
if (!img || !sessionID) |
return; |
- // Color snapshots are not used on tablets, so don't keep them in memory. |
+ // The iPad tab switcher is currently using its own memory cache so the image |
+ // is not stored in memory here if running on iPad. |
+ // The same logic is used on image reads (code above). |
if (!IsIPadIdiom()) { |
[imageDictionary_ setObject:img forKey:sessionID]; |
} |
@@ -346,6 +359,7 @@ void ConvertAndSaveGreyImage( |
} |
- (void)handleLowMemory { |
+ DCHECK(!IsIPadIdiom()); |
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
NSMutableDictionary* dictionary = |
[[NSMutableDictionary alloc] initWithCapacity:2]; |
@@ -358,11 +372,13 @@ void ConvertAndSaveGreyImage( |
} |
- (void)handleEnterBackground { |
+ DCHECK(!IsIPadIdiom()); |
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
[imageDictionary_ removeAllObjects]; |
} |
- (void)handleBecomeActive { |
+ DCHECK(!IsIPadIdiom()); |
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); |
for (NSString* sessionID in pinnedIDs_) |
[self retrieveImageForSessionID:sessionID callback:nil]; |