Commit 9b48f66b authored by sdefresne's avatar sdefresne Committed by Commit bot

[iOS] Fixed tab snapshot cache refresh issues on iPad.

BUG=463851

Review URL: https://codereview.chromium.org/1141423002

Cr-Commit-Position: refs/heads/master@{#330731}
parent 4369139d
...@@ -140,7 +140,8 @@ void ConvertAndSaveGreyImage( ...@@ -140,7 +140,8 @@ void ConvertAndSaveGreyImage(
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]); propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]);
// TODO(andybons): In the case where the cache grows, it is expensive. 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. // Make sure this doesn't suck when there are more than ten tabs.
imageDictionary_.reset( imageDictionary_.reset(
[[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]);
...@@ -160,10 +161,12 @@ void ConvertAndSaveGreyImage( ...@@ -160,10 +161,12 @@ void ConvertAndSaveGreyImage(
name:UIApplicationDidBecomeActiveNotification name:UIApplicationDidBecomeActiveNotification
object:nil]; object:nil];
} }
}
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
if (!IsIPadIdiom()) {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
removeObserver:self removeObserver:self
name:UIApplicationDidReceiveMemoryWarningNotification name:UIApplicationDidReceiveMemoryWarningNotification
...@@ -176,6 +179,7 @@ void ConvertAndSaveGreyImage( ...@@ -176,6 +179,7 @@ void ConvertAndSaveGreyImage(
removeObserver:self removeObserver:self
name:UIApplicationDidBecomeActiveNotification name:UIApplicationDidBecomeActiveNotification
object:nil]; object:nil];
}
[super dealloc]; [super dealloc];
} }
...@@ -195,6 +199,11 @@ void ConvertAndSaveGreyImage( ...@@ -195,6 +199,11 @@ void ConvertAndSaveGreyImage(
callback:(void (^)(UIImage*))callback { callback:(void (^)(UIImage*))callback {
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
DCHECK(sessionID); 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]; UIImage* img = [imageDictionary_ objectForKey:sessionID];
if (img) { if (img) {
if (callback) if (callback)
...@@ -205,14 +214,16 @@ void ConvertAndSaveGreyImage( ...@@ -205,14 +214,16 @@ void ConvertAndSaveGreyImage(
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
web::WebThread::GetMessageLoopProxyForThread( web::WebThread::GetMessageLoopProxyForThread(
web::WebThread::FILE_USER_BLOCKING).get(), web::WebThread::FILE_USER_BLOCKING).get(),
FROM_HERE, FROM_HERE, base::BindBlock(^base::scoped_nsobject<UIImage>() {
base::BindBlock(^base::scoped_nsobject<UIImage>() {
// Retrieve the image on a high priority thread. // Retrieve the image on a high priority thread.
return base::scoped_nsobject<UIImage>([ReadImageFromDisk( return base::scoped_nsobject<UIImage>([ReadImageFromDisk(
[SnapshotCache imagePathForSessionID:sessionID]) retain]); [SnapshotCache imagePathForSessionID:sessionID]) retain]);
}), }),
base::BindBlock(^(base::scoped_nsobject<UIImage> image) { 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]; [imageDictionary_ setObject:image forKey:sessionID];
if (callback) if (callback)
callback(image); callback(image);
...@@ -224,7 +235,9 @@ void ConvertAndSaveGreyImage( ...@@ -224,7 +235,9 @@ void ConvertAndSaveGreyImage(
if (!img || !sessionID) if (!img || !sessionID)
return; 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()) { if (!IsIPadIdiom()) {
[imageDictionary_ setObject:img forKey:sessionID]; [imageDictionary_ setObject:img forKey:sessionID];
} }
...@@ -346,6 +359,7 @@ void ConvertAndSaveGreyImage( ...@@ -346,6 +359,7 @@ void ConvertAndSaveGreyImage(
} }
- (void)handleLowMemory { - (void)handleLowMemory {
DCHECK(!IsIPadIdiom());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
NSMutableDictionary* dictionary = NSMutableDictionary* dictionary =
[[NSMutableDictionary alloc] initWithCapacity:2]; [[NSMutableDictionary alloc] initWithCapacity:2];
...@@ -358,11 +372,13 @@ void ConvertAndSaveGreyImage( ...@@ -358,11 +372,13 @@ void ConvertAndSaveGreyImage(
} }
- (void)handleEnterBackground { - (void)handleEnterBackground {
DCHECK(!IsIPadIdiom());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
[imageDictionary_ removeAllObjects]; [imageDictionary_ removeAllObjects];
} }
- (void)handleBecomeActive { - (void)handleBecomeActive {
DCHECK(!IsIPadIdiom());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI); DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
for (NSString* sessionID in pinnedIDs_) for (NSString* sessionID in pinnedIDs_)
[self retrieveImageForSessionID:sessionID callback:nil]; [self retrieveImageForSessionID:sessionID callback:nil];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment