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

Unified Diff: ios/chrome/browser/snapshots/snapshot_cache.mm

Issue 1725533004: Enable iPad Tab Switcher by default on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unittests. 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 side-by-side diff with in-line comments
Download patch
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 7da1d618c584e5c2630faf08c3f14c384596dcc4..3302036916768effc2719c2a05bf75a91de54442 100644
--- a/ios/chrome/browser/snapshots/snapshot_cache.mm
+++ b/ios/chrome/browser/snapshots/snapshot_cache.mm
@@ -27,6 +27,11 @@
+ (base::FilePath)greyImagePathForSessionID:(NSString*)sessionID;
// Returns the directory where the thumbnails are saved.
+ (base::FilePath)cacheDirectory;
+// Returns whether the in-memory cache (as opposed to the on-disk cache) is
+// enabled.
+- (BOOL)inMemoryCacheIsEnabled;
+// Returns whether the snapshots are cached in a LRU cache.
+- (BOOL)useLRUCache;
// Returns the directory where the thumbnails were stored in M28 and earlier.
- (base::FilePath)oldCacheDirectory;
// Remove all UIImages from |imageDictionary_|.
@@ -144,52 +149,45 @@ void ConvertAndSaveGreyImage(
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]);
- // Always use the LRUCache when the tab switcher is enabled.
- if (experimental_flags::IsTabSwitcherEnabled() ||
- experimental_flags::IsLRUSnapshotCacheEnabled()) {
+ if ([self useLRUCache]) {
lruCache_.reset(
[[LRUCache alloc] initWithCacheSize:kLRUCacheMaxCapacity]);
} else {
imageDictionary_.reset(
[[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]);
}
-
- if (!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled()) {
- [[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];
- }
+ [[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 {
- if (!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled()) {
- [[NSNotificationCenter defaultCenter]
- removeObserver:self
- name:UIApplicationDidReceiveMemoryWarningNotification
- object:nil];
- [[NSNotificationCenter defaultCenter]
- removeObserver:self
- name:UIApplicationDidEnterBackgroundNotification
- object:nil];
- [[NSNotificationCenter defaultCenter]
- removeObserver:self
- name:UIApplicationDidBecomeActiveNotification
- object:nil];
- }
+ [[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];
}
@@ -210,9 +208,7 @@ void ConvertAndSaveGreyImage(
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
DCHECK(sessionID);
- // Cache on iPad is enabled only when the tab switcher is enabled.
- if ((IsIPadIdiom() && !experimental_flags::IsTabSwitcherEnabled()) &&
- !callback)
+ if (![self inMemoryCacheIsEnabled] && !callback)
return;
UIImage* img = nil;
@@ -236,9 +232,7 @@ void ConvertAndSaveGreyImage(
[SnapshotCache imagePathForSessionID:sessionID]) retain]);
}),
base::BindBlock(^(base::scoped_nsobject<UIImage> image) {
- // Cache on iPad is enabled only when the tab switcher is enabled.
- if ((!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled()) &&
- image) {
+ if ([self inMemoryCacheIsEnabled] && image) {
if (lruCache_)
[lruCache_ setObject:image forKey:sessionID];
else
@@ -254,8 +248,7 @@ void ConvertAndSaveGreyImage(
if (!img || !sessionID)
return;
- // Cache on iPad is enabled only when the tab switcher is enabled.
- if (!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled()) {
+ if ([self inMemoryCacheIsEnabled]) {
if (lruCache_)
[lruCache_ setObject:img forKey:sessionID];
else
@@ -386,8 +379,18 @@ void ConvertAndSaveGreyImage(
}
}
+- (BOOL)inMemoryCacheIsEnabled {
+ // In-memory cache on iPad is enabled only when the tab switcher is enabled.
+ return !IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled();
+}
+
+- (BOOL)useLRUCache {
+ // Always use the LRUCache when the tab switcher is enabled.
+ return experimental_flags::IsTabSwitcherEnabled() ||
+ experimental_flags::IsLRUSnapshotCacheEnabled();
+}
+
- (void)handleLowMemory {
- DCHECK(!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
NSMutableDictionary* dictionary =
[[NSMutableDictionary alloc] initWithCapacity:2];
@@ -410,14 +413,12 @@ void ConvertAndSaveGreyImage(
}
- (void)handleEnterBackground {
- DCHECK(!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
[imageDictionary_ removeAllObjects];
[lruCache_ removeAllObjects];
}
- (void)handleBecomeActive {
- DCHECK(!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled());
DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
for (NSString* sessionID in pinnedIDs_)
[self retrieveImageForSessionID:sessionID callback:nil];
@@ -568,11 +569,12 @@ void ConvertAndSaveGreyImage(
@implementation SnapshotCache (TestingAdditions)
- (BOOL)hasImageInMemory:(NSString*)sessionID {
- if (experimental_flags::IsLRUSnapshotCacheEnabled())
+ if ([self useLRUCache])
return [lruCache_ objectForKey:sessionID] != nil;
else
return [imageDictionary_ objectForKey:sessionID] != nil;
}
+
- (BOOL)hasGreyImageInMemory:(NSString*)sessionID {
return [greyImageDictionary_ objectForKey:sessionID] != nil;
}

Powered by Google App Engine
This is Rietveld 408576698