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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/navigation/crw_session_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/tabs/tab.h" 5 #import "ios/chrome/browser/tabs/tab.h"
6 6
7 #import <CoreLocation/CoreLocation.h> 7 #import <CoreLocation/CoreLocation.h>
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 NSString* const kTabIDKey = @"TabID"; 179 NSString* const kTabIDKey = @"TabID";
180 180
181 // The key under which the opener Tab ID is stored in the WebState's 181 // The key under which the opener Tab ID is stored in the WebState's
182 // serializable user data. 182 // serializable user data.
183 NSString* const kOpenerIDKey = @"OpenerID"; 183 NSString* const kOpenerIDKey = @"OpenerID";
184 184
185 // The key under which the opener navigation index is stored in the WebState's 185 // The key under which the opener navigation index is stored in the WebState's
186 // serializable user data. 186 // serializable user data.
187 NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex"; 187 NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex";
188 188
189 // The key under which the last visited timestamp is stored in the WebState's
190 // serializable user data.
191 NSString* const kLastVisitedTimestampKey = @"LastVisitedTimestamp";
192
189 // Name of histogram for recording the state of the tab when the renderer is 193 // Name of histogram for recording the state of the tab when the renderer is
190 // terminated. 194 // terminated.
191 const char kRendererTerminationStateHistogram[] = 195 const char kRendererTerminationStateHistogram[] =
192 "Tab.StateAtRendererTermination"; 196 "Tab.StateAtRendererTermination";
193 197
194 // Referrer used for clicks on article suggestions on the NTP. 198 // Referrer used for clicks on article suggestions on the NTP.
195 const char kChromeContentSuggestionsReferrer[] = 199 const char kChromeContentSuggestionsReferrer[] =
196 "https://www.googleapis.com/auth/chrome-content-suggestions"; 200 "https://www.googleapis.com/auth/chrome-content-suggestions";
197 201
198 // Enum corresponding to UMA's TabForegroundState, for 202 // Enum corresponding to UMA's TabForegroundState, for
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (self) { 538 if (self) {
535 propertyReleaser_Tab_.Init(self, [Tab class]); 539 propertyReleaser_Tab_.Init(self, [Tab class]);
536 tabHistoryContext_.reset(new TabHistoryContext()); 540 tabHistoryContext_.reset(new TabHistoryContext());
537 parentTabModel_ = parentModel; 541 parentTabModel_ = parentModel;
538 browserState_ = 542 browserState_ =
539 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); 543 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState());
540 544
541 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); 545 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release()));
542 webStateObserver_.reset( 546 webStateObserver_.reset(
543 new web::WebStateObserverBridge(webStateImpl_.get(), self)); 547 new web::WebStateObserverBridge(webStateImpl_.get(), self));
548 [self updateLastVisitedTimestamp];
544 549
545 // Do not respect |attachTabHelpers| as this tab helper is required for 550 // Do not respect |attachTabHelpers| as this tab helper is required for
546 // proper conversion from WebState to Tab. 551 // proper conversion from WebState to Tab.
547 LegacyTabHelper::CreateForWebState(webStateImpl_.get(), self); 552 LegacyTabHelper::CreateForWebState(webStateImpl_.get(), self);
548 553
549 [self.webController setDelegate:self]; 554 [self.webController setDelegate:self];
550 555
551 NSString* sessionID = self.tabId; 556 NSString* sessionID = self.tabId;
552 DCHECK(sessionID); 557 DCHECK(sessionID);
553 snapshotManager_.reset([[SnapshotManager alloc] init]); 558 snapshotManager_.reset([[SnapshotManager alloc] init]);
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 linkClicked:linkClicked]) { 1874 linkClicked:linkClicked]) {
1870 return YES; 1875 return YES;
1871 } 1876 }
1872 1877
1873 // Auto-open didn't work. Reset the auto-open flag. 1878 // Auto-open didn't work. Reset the auto-open flag.
1874 [metadata unsetShouldAutoOpenLinks]; 1879 [metadata unsetShouldAutoOpenLinks];
1875 return NO; 1880 return NO;
1876 } 1881 }
1877 1882
1878 - (double)lastVisitedTimestamp { 1883 - (double)lastVisitedTimestamp {
1879 DCHECK([self navigationManager]); 1884 DCHECK(self.webState);
1880 return [[self navigationManagerImpl]->GetSessionController() 1885 web::SerializableUserDataManager* userDataManager =
1881 lastVisitedTimestamp]; 1886 web::SerializableUserDataManager::FromWebState(self.webState);
1887 id<NSCoding> lastVisitedTimestamp =
1888 userDataManager->GetValueForSerializationKey(kLastVisitedTimestampKey);
1889 return lastVisitedTimestamp
1890 ? base::mac::ObjCCastStrict<NSNumber>(lastVisitedTimestamp)
1891 .doubleValue
1892 : 0.;
1882 } 1893 }
1883 1894
1884 - (void)updateLastVisitedTimestamp { 1895 - (void)updateLastVisitedTimestamp {
1885 // Stores this information in self.history and it will be written into disc 1896 DCHECK(self.webState);
1886 // with other information when needed. 1897 web::SerializableUserDataManager* userDataManager =
1887 DCHECK([self navigationManager]); 1898 web::SerializableUserDataManager::FromWebState(self.webState);
1888 [[self navigationManagerImpl]->GetSessionController() 1899 userDataManager->AddSerializableData(@([[NSDate date] timeIntervalSince1970]),
1889 setLastVisitedTimestamp:[[NSDate date] timeIntervalSince1970]]; 1900 kLastVisitedTimestampKey);
1890 } 1901 }
1891 1902
1892 - (infobars::InfoBarManager*)infoBarManager { 1903 - (infobars::InfoBarManager*)infoBarManager {
1893 DCHECK(self.webState); 1904 DCHECK(self.webState);
1894 return InfoBarManagerImpl::FromWebState(self.webState); 1905 return InfoBarManagerImpl::FromWebState(self.webState);
1895 } 1906 }
1896 1907
1897 - (NSArray*)snapshotOverlays { 1908 - (NSArray*)snapshotOverlays {
1898 return [snapshotOverlayProvider_ snapshotOverlaysForTab:self]; 1909 return [snapshotOverlayProvider_ snapshotOverlaysForTab:self];
1899 } 1910 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 2245
2235 - (TabModel*)parentTabModel { 2246 - (TabModel*)parentTabModel {
2236 return parentTabModel_; 2247 return parentTabModel_;
2237 } 2248 }
2238 2249
2239 - (FormInputAccessoryViewController*)inputAccessoryViewController { 2250 - (FormInputAccessoryViewController*)inputAccessoryViewController {
2240 return inputAccessoryViewController_.get(); 2251 return inputAccessoryViewController_.get();
2241 } 2252 }
2242 2253
2243 @end 2254 @end
OLDNEW
« 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