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

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: 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
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..fb9846a13ae208ed03bd5eff0a4104d569ffc4c0
--- /dev/null
+++ b/ios/chrome/browser/tabs/tab_model_selected_tab_observer.mm
@@ -0,0 +1,62 @@
+// 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"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@implementation TabModelSelectedTabObserver {
+ __weak TabModel* _tabModel;
+}
+
+- (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, ... of the old selected Tab.
+ oldTab = LegacyTabHelper::GetTabForWebState(oldWebState);
+ if (userAction)
+ [oldTab recordStateInHistory];
+
+ // Avoid artificially extending the lifetime of oldTab until the global
+ // autoreleasepool is purged.
+ @autoreleasepool {
+ [[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
« no previous file with comments | « ios/chrome/browser/tabs/tab_model_selected_tab_observer.h ('k') | ios/chrome/browser/ui/browser_view_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698