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

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

Issue 2703333006: Move the notion of current Tab from TabModel to WebStateList. (Closed)
Patch Set: 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
Index: ios/chrome/browser/tabs/tab_model_selected_tab_observer.mm
diff --git a/ios/chrome/browser/tabs/tab_model_selected_tab_observer.mm b/ios/chrome/browser/tabs/tab_model_selected_tab_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..f8b7cd8b7f0dfdd8841042d3421f118c554226e3
--- /dev/null
+++ b/ios/chrome/browser/tabs/tab_model_selected_tab_observer.mm
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h"
+
+#include "base/logging.h"
+#import "ios/chrome/browser/tabs/legacy_tab_helper.h"
+#import "ios/chrome/browser/tabs/tab.h"
+#import "ios/chrome/browser/tabs/tab_model.h"
+
+@implementation TabModelSelectedTabObserver {
+ __weak TabModel* _tabModel;
sdefresne 2017/02/21 17:09:49 This is an Objective-C class because I cannot use
+}
+
+- (instancetype)initWithTabModel:(TabModel*)tabModel {
+ DCHECK(tabModel);
+ if ((self = [super init])) {
+ _tabModel = tabModel;
+ }
+ return self;
+}
+
+#pragma mark WebStateListObserving
+
+- (void)webStateList:(WebStateList*)webStateList
+ didChangeActiveWebState:(web::WebState*)newWebState
+ oldWebState:(web::WebState*)oldWebState
+ atIndex:(int)atIndex
+ userAction:(BOOL)userAction {
+ Tab* oldTab = nil;
+ Tab* newTab = nil;
+ if (oldWebState) {
+ // Save state, such as scroll position, before switching tabs.
rohitrao (ping after 24h) 2017/02/22 15:13:43 This comment is half stale, because we no longer s
sdefresne 2017/02/23 15:43:48 Fixed the comment.
+ oldTab = LegacyTabHelper::GetTabForWebState(oldWebState);
+ if (userAction)
+ [oldTab recordStateInHistory];
+
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:kTabModelTabDeselectedNotification
+ object:@{kTabModelTabKey : oldTab}];
+ }
+
+ if (newWebState) {
+ newTab = LegacyTabHelper::GetTabForWebState(newWebState);
+ [newTab updateLastVisitedTimestamp];
+
+ // Persist the session state.
+ if (newTab.loadFinished)
+ [_tabModel saveSessionImmediately:NO];
+ }
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698