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

Unified Diff: ios/chrome/browser/tabs/tab.mm

Issue 2722013002: Use custom user data to serialize Tab last visited timestamp. (Closed)
Patch Set: Rebase. Created 3 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
« no previous file with comments | « no previous file | ios/web/navigation/crw_session_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/tabs/tab.mm
diff --git a/ios/chrome/browser/tabs/tab.mm b/ios/chrome/browser/tabs/tab.mm
index bca7ffb2322290a0b6a81cf53a28835708c0c823..b5dcec7c595a68381200dc730515e6b08b4baa69 100644
--- a/ios/chrome/browser/tabs/tab.mm
+++ b/ios/chrome/browser/tabs/tab.mm
@@ -186,6 +186,10 @@ NSString* const kOpenerIDKey = @"OpenerID";
// serializable user data.
NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex";
+// The key under which the last visited timestamp is stored in the WebState's
+// serializable user data.
+NSString* const kLastVisitedTimestampKey = @"LastVisitedTimestamp";
+
// Name of histogram for recording the state of the tab when the renderer is
// terminated.
const char kRendererTerminationStateHistogram[] =
@@ -541,6 +545,7 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release()));
webStateObserver_.reset(
new web::WebStateObserverBridge(webStateImpl_.get(), self));
+ [self updateLastVisitedTimestamp];
// Do not respect |attachTabHelpers| as this tab helper is required for
// proper conversion from WebState to Tab.
@@ -1876,17 +1881,23 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
}
- (double)lastVisitedTimestamp {
- DCHECK([self navigationManager]);
- return [[self navigationManagerImpl]->GetSessionController()
- lastVisitedTimestamp];
+ DCHECK(self.webState);
+ web::SerializableUserDataManager* userDataManager =
+ web::SerializableUserDataManager::FromWebState(self.webState);
+ id<NSCoding> lastVisitedTimestamp =
+ userDataManager->GetValueForSerializationKey(kLastVisitedTimestampKey);
+ return lastVisitedTimestamp
+ ? base::mac::ObjCCastStrict<NSNumber>(lastVisitedTimestamp)
+ .doubleValue
+ : 0.;
}
- (void)updateLastVisitedTimestamp {
- // Stores this information in self.history and it will be written into disc
- // with other information when needed.
- DCHECK([self navigationManager]);
- [[self navigationManagerImpl]->GetSessionController()
- setLastVisitedTimestamp:[[NSDate date] timeIntervalSince1970]];
+ DCHECK(self.webState);
+ web::SerializableUserDataManager* userDataManager =
+ web::SerializableUserDataManager::FromWebState(self.webState);
+ userDataManager->AddSerializableData(@([[NSDate date] timeIntervalSince1970]),
+ kLastVisitedTimestampKey);
}
- (infobars::InfoBarManager*)infoBarManager {
« no previous file with comments | « no previous file | ios/web/navigation/crw_session_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698