Commit b73e6271 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Rename sessionID to snapshotID in //ios/c/b/snapshots

It is time to remove the use of the term "session" in
//ios/chrome/browser/snapshots.

The identifier used to store and retrieve images from SnapshotCache
is called |snapshotID|. The SnapshotCache has no concept of a Tab
or WebState. It is merely a collection of images with identifiers.

However, SnapshotTabHelper and SnapshotGenerator are tied to a
WebState. Within those classes, the unique identifier for a WebState
is called |tabID|. When those classes call SnapshotCache, they use
the WebState's |tabID| as the identifier to be used in SnapshotCache.

Change-Id: Ic08cd0d70b66e4d699bf06c8b5d8afc093e90255
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354807
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarMohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799782}
parent 2f017bdc
......@@ -23,36 +23,36 @@
// only a singleton instance.
@property(nonatomic, copy) NSString* uniqueIdentifier;
// Track session IDs to not release on low memory and to reload on
// Track snapshot IDs to not release on low memory and to reload on
// |UIApplicationDidBecomeActiveNotification|.
@property(nonatomic, strong) NSSet* pinnedIDs;
// The scale that should be used for snapshots.
- (CGFloat)snapshotScaleForDevice;
// Retrieve a cached snapshot for the |sessionID| and return it via the callback
// if it exists. The callback is guaranteed to be called synchronously if the
// image is in memory. It will be called asynchronously if the image is on disk
// or with nil if the image is not present at all.
- (void)retrieveImageForSessionID:(NSString*)sessionID
// Retrieve a cached snapshot for the |snapshotID| and return it via the
// callback if it exists. The callback is guaranteed to be called synchronously
// if the image is in memory. It will be called asynchronously if the image is
// on disk or with nil if the image is not present at all.
- (void)retrieveImageForSnapshotID:(NSString*)snapshotID
callback:(void (^)(UIImage*))callback;
// Request the session's grey snapshot. If the image is already loaded in
// Request the grey snapshot for |snapshotID|. If the image is already loaded in
// memory, this will immediately call back on |callback|.
- (void)retrieveGreyImageForSessionID:(NSString*)sessionID
- (void)retrieveGreyImageForSnapshotID:(NSString*)snapshotID
callback:(void (^)(UIImage*))callback;
- (void)setImage:(UIImage*)img withSessionID:(NSString*)sessionID;
- (void)setImage:(UIImage*)image withSnapshotID:(NSString*)snapshotID;
// Removes the image from both the LRU and disk cache, unless it is marked for
// deferred deletion. Images marked for deferred deletion can only be removed by
// calling |-removeMarkedImages|.
- (void)removeImageWithSessionID:(NSString*)sessionID;
- (void)removeImageWithSnapshotID:(NSString*)snapshotID;
// Marks an image for deferred deletion. The image will not be immediately
// deleted when |-removeImageWithSessionID:| is called. Images marked for
// deleted when |-removeImageWithSnapshotID:| is called. Images marked for
// deferred deletion can only be removed by calling |-removeMarkedImages|.
- (void)markImageWithSessionID:(NSString*)sessionID;
- (void)markImageWithSnapshotID:(NSString*)snapshotID;
// Removes all marked images from both the LRU and disk cache.
- (void)removeMarkedImages;
......@@ -62,28 +62,28 @@
- (void)unmarkAllImages;
// Purge the cache of snapshots that are older than |date|. The snapshots for
// the sessions given in |liveSessionIds| will be kept. This will be done
// asynchronously on a background thread.
// |liveSnapshotIDs| will be kept. This will be done asynchronously on a
// background thread.
- (void)purgeCacheOlderThan:(const base::Time&)date
keeping:(NSSet*)liveSessionIds;
// Hint that the snapshot for |sessionID| will likely be saved to disk when the
keeping:(NSSet*)liveSnapshotIDs;
// Hint that the snapshot for |snapshotID| will likely be saved to disk when the
// application is backgrounded. The snapshot is then saved in memory, so it
// does not need to be read off disk.
- (void)willBeSavedGreyWhenBackgrounding:(NSString*)sessionID;
- (void)willBeSavedGreyWhenBackgrounding:(NSString*)snapshotID;
// Create temporary cache of grey images for tablet side swipe.
- (void)createGreyCache:(NSArray*)sessionIDs;
- (void)createGreyCache:(NSArray*)snapshotIDs;
// Release all images in grey cache.
- (void)removeGreyCache;
// Request the session's grey snapshot. If the image is already loaded this will
// immediately call back on |callback|. Otherwise, only use |callback| for the
// most recent caller. The callback is not guaranteed to be called.
- (void)greyImageForSessionID:(NSString*)sessionID
// Request the grey snapshot for |snapshotID|. If the image is already loaded
// this will immediately call back on |callback|. Otherwise, only use |callback|
// for the most recent caller. The callback is not guaranteed to be called.
- (void)greyImageForSnapshotID:(NSString*)snapshotID
callback:(void (^)(UIImage*))callback;
// Write a grey copy of the snapshot for |sessionID| to disk, but if and only if
// a color version of the snapshot already exists in memory or on disk.
- (void)saveGreyInBackgroundForSessionID:(NSString*)sessionID;
// Write a grey copy of the snapshot for |snapshotID| to disk, but if and only
// if a color version of the snapshot already exists in memory or on disk.
- (void)saveGreyInBackgroundForSnapshotID:(NSString*)snapshotID;
// Adds an observer to this snapshot cache.
- (void)addObserver:(id<SnapshotCacheObserver>)observer;
......@@ -99,8 +99,8 @@
// Additionnal methods that should only be used for tests.
@interface SnapshotCache (TestingAdditions)
- (BOOL)hasImageInMemory:(NSString*)sessionID;
- (BOOL)hasGreyImageInMemory:(NSString*)sessionID;
- (BOOL)hasImageInMemory:(NSString*)snapshotID;
- (BOOL)hasGreyImageInMemory:(NSString*)snapshotID;
- (NSUInteger)lruCacheMaxSize;
@end
......
......@@ -14,10 +14,10 @@ class FilePath;
@class NSString;
@interface SnapshotCache (Internal)
// Returns filepath to the color snapshot of |sessionID|.
- (base::FilePath)imagePathForSessionID:(NSString*)sessionID;
// Returns filepath to the greyscale snapshot of |sessionID|.
- (base::FilePath)greyImagePathForSessionID:(NSString*)sessionID;
// Returns filepath to the color snapshot of |snapshotID|.
- (base::FilePath)imagePathForSnapshotID:(NSString*)snapshotID;
// Returns filepath to the greyscale snapshot of |snapshotID|.
- (base::FilePath)greyImagePathForSnapshotID:(NSString*)snapshotID;
@end
#endif // IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_INTERNAL_H_
......@@ -24,8 +24,7 @@ class WebState;
// Designated initializer.
- (instancetype)initWithWebState:(web::WebState*)webState
snapshotSessionId:(NSString*)snapshotSessionId
NS_DESIGNATED_INITIALIZER;
tabID:(NSString*)tabID NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -56,7 +56,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
@interface SnapshotGenerator ()<CRWWebStateObserver>
// The unique ID for the web state.
@property(nonatomic, copy) NSString* sessionID;
@property(nonatomic, copy) NSString* tabID;
// The associated web state.
@property(nonatomic, assign) web::WebState* webState;
......@@ -68,12 +68,12 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
}
- (instancetype)initWithWebState:(web::WebState*)webState
snapshotSessionId:(NSString*)snapshotSessionId {
tabID:(NSString*)tabID {
if ((self = [super init])) {
DCHECK(webState);
DCHECK(snapshotSessionId);
DCHECK(tabID);
_webState = webState;
_sessionID = snapshotSessionId;
_tabID = tabID;
_webStateObserver = std::make_unique<web::WebStateObserverBridge>(self);
_webState->AddObserver(_webStateObserver.get());
......@@ -92,7 +92,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
- (void)retrieveSnapshot:(void (^)(UIImage*))callback {
DCHECK(callback);
if (self.snapshotCache) {
[self.snapshotCache retrieveImageForSessionID:self.sessionID
[self.snapshotCache retrieveImageForSnapshotID:self.tabID
callback:callback];
} else {
callback(nil);
......@@ -114,7 +114,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
SnapshotCache* snapshotCache = self.snapshotCache;
if (snapshotCache) {
[snapshotCache retrieveGreyImageForSessionID:self.sessionID
[snapshotCache retrieveGreyImageForSnapshotID:self.tabID
callback:wrappedCallback];
} else {
wrappedCallback(nil);
......@@ -178,7 +178,7 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
}
- (void)removeSnapshot {
[self.snapshotCache removeImageWithSessionID:self.sessionID];
[self.snapshotCache removeImageWithSnapshotID:self.tabID];
}
#pragma mark - Private methods
......@@ -277,10 +277,10 @@ BOOL ViewHierarchyContainsWKWebView(UIView* view) {
// Updates the snapshot cache with |snapshot|.
- (void)updateSnapshotCacheWithImage:(UIImage*)snapshot {
if (snapshot) {
[self.snapshotCache setImage:snapshot withSessionID:self.sessionID];
[self.snapshotCache setImage:snapshot withSnapshotID:self.tabID];
} else {
// Remove any stale snapshot since the snapshot failed.
[self.snapshotCache removeImageWithSessionID:self.sessionID];
[self.snapshotCache removeImageWithSnapshotID:self.tabID];
}
}
......
......@@ -30,9 +30,9 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer,
~SnapshotTabHelper() override;
// Creates the tab helper for |web_state| if it does not exists. The
// unique identifier |session_id| is used when interacting with the
// unique identifier |tab_id| is used when interacting with the
// cache to save or fetch snapshots.
static void CreateForWebState(web::WebState* web_state, NSString* session_id);
static void CreateForWebState(web::WebState* web_state, NSString* tab_id);
// Sets the delegate. Capturing snapshot before setting a delegate will
// results in failures. The delegate is not owned by the tab helper.
......@@ -81,7 +81,7 @@ class SnapshotTabHelper : public infobars::InfoBarManager::Observer,
private:
friend class web::WebStateUserData<SnapshotTabHelper>;
SnapshotTabHelper(web::WebState* web_state, NSString* session_id);
SnapshotTabHelper(web::WebState* web_state, NSString* tab_id);
// web::WebStateObserver implementation.
void PageLoaded(
......
......@@ -47,12 +47,12 @@ SnapshotTabHelper::~SnapshotTabHelper() {
// static
void SnapshotTabHelper::CreateForWebState(web::WebState* web_state,
NSString* session_id) {
NSString* tab_id) {
DCHECK(web_state);
if (!FromWebState(web_state)) {
web_state->SetUserData(
UserDataKey(),
base::WrapUnique(new SnapshotTabHelper(web_state, session_id)));
base::WrapUnique(new SnapshotTabHelper(web_state, tab_id)));
}
}
......@@ -109,14 +109,13 @@ void SnapshotTabHelper::IgnoreNextLoad() {
ignore_next_load_ = true;
}
SnapshotTabHelper::SnapshotTabHelper(web::WebState* web_state,
NSString* session_id)
SnapshotTabHelper::SnapshotTabHelper(web::WebState* web_state, NSString* tab_id)
: web_state_(web_state),
web_state_observer_(this),
infobar_observer_(this),
weak_ptr_factory_(this) {
snapshot_generator_ = [[SnapshotGenerator alloc] initWithWebState:web_state_
snapshotSessionId:session_id];
tabID:tab_id];
web_state_observer_.Add(web_state_);
// Supports missing InfoBarManager to make testing easier.
......
......@@ -86,9 +86,9 @@ class SnapshotTabHelperTest : public PlatformTest {
public:
SnapshotTabHelperTest() {
// Create the SnapshotTabHelper with a fake delegate.
snapshot_session_id_ = [[NSUUID UUID] UUIDString];
snapshot_id_ = [[NSUUID UUID] UUIDString];
delegate_ = [[TabHelperSnapshotGeneratorDelegate alloc] init];
SnapshotTabHelper::CreateForWebState(&web_state_, snapshot_session_id_);
SnapshotTabHelper::CreateForWebState(&web_state_, snapshot_id_);
SnapshotTabHelper::FromWebState(&web_state_)->SetDelegate(delegate_);
// Set custom snapshot cache.
......@@ -106,7 +106,7 @@ class SnapshotTabHelperTest : public PlatformTest {
~SnapshotTabHelperTest() override { [snapshot_cache_ shutdown]; }
void SetCachedSnapshot(UIImage* image) {
[snapshot_cache_ setImage:image withSessionID:snapshot_session_id_];
[snapshot_cache_ setImage:image withSnapshotID:snapshot_id_];
}
UIImage* GetCachedSnapshot() {
......@@ -114,7 +114,7 @@ class SnapshotTabHelperTest : public PlatformTest {
base::RunLoop* run_loop_ptr = &run_loop;
__block UIImage* snapshot = nil;
[snapshot_cache_ retrieveImageForSessionID:snapshot_session_id_
[snapshot_cache_ retrieveImageForSnapshotID:snapshot_id_
callback:^(UIImage* cached_snapshot) {
snapshot = cached_snapshot;
run_loop_ptr->Quit();
......@@ -128,7 +128,7 @@ class SnapshotTabHelperTest : public PlatformTest {
web::WebTaskEnvironment task_environment_;
TabHelperSnapshotGeneratorDelegate* delegate_ = nil;
SnapshotCache* snapshot_cache_ = nil;
NSString* snapshot_session_id_ = nil;
NSString* snapshot_id_ = nil;
web::TestWebState web_state_;
private:
......@@ -340,14 +340,14 @@ TEST_F(SnapshotTabHelperTest, ClosingWebStateDoesNotRemoveSnapshot) {
NSString* tab_id = TabIdTabHelper::FromWebState(web_state.get())->tab_id();
SnapshotTabHelper::CreateForWebState(web_state.get(), tab_id);
[[partialMock reject] removeImageWithSessionID:tab_id];
[[partialMock reject] removeImageWithSnapshotID:tab_id];
// Use @try/@catch as -reject raises an exception.
@try {
web_state.reset();
EXPECT_OCMOCK_VERIFY(partialMock);
} @catch (NSException* exception) {
// The exception is raised when -removeImageWithSessionID: is invoked. As
// The exception is raised when -removeImageWithSnapshotID: is invoked. As
// this should not happen, mark the test as failed.
GTEST_FAIL();
}
......
......@@ -295,7 +295,7 @@ void RecordInterfaceOrientationMetric() {
->tab_id();
[_snapshotBrowserAgent->GetSnapshotCache()
saveGreyInBackgroundForSessionID:tabId];
saveGreyInBackgroundForSnapshotID:tabId];
}
}
......
......@@ -308,7 +308,7 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list,
for (int i = 0; i < self.webStateList->count(); i++) {
web::WebState* webState = self.webStateList->GetWebStateAt(i);
TabIdTabHelper* tabHelper = TabIdTabHelper::FromWebState(webState);
[self.snapshotCache markImageWithSessionID:tabHelper->tab_id()];
[self.snapshotCache markImageWithSnapshotID:tabHelper->tab_id()];
}
self.closedSessionWindow = SerializeWebStateList(self.webStateList);
int old_size =
......
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