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