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

Side by Side 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, 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h"
6
7 #include "base/logging.h"
8 #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
9 #import "ios/chrome/browser/tabs/tab.h"
10 #import "ios/chrome/browser/tabs/tab_model.h"
11
12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support."
14 #endif
15
16 @implementation TabModelSelectedTabObserver {
17 __weak TabModel* _tabModel;
18 }
19
20 - (instancetype)initWithTabModel:(TabModel*)tabModel {
21 DCHECK(tabModel);
22 if ((self = [super init])) {
23 _tabModel = tabModel;
24 }
25 return self;
26 }
27
28 #pragma mark WebStateListObserving
29
30 - (void)webStateList:(WebStateList*)webStateList
31 didChangeActiveWebState:(web::WebState*)newWebState
32 oldWebState:(web::WebState*)oldWebState
33 atIndex:(int)atIndex
34 userAction:(BOOL)userAction {
35 Tab* oldTab = nil;
36 Tab* newTab = nil;
37 if (oldWebState) {
38 // Save state, such as scroll position, ... of the old selected Tab.
39 oldTab = LegacyTabHelper::GetTabForWebState(oldWebState);
40 if (userAction)
41 [oldTab recordStateInHistory];
42
43 // Avoid artificially extending the lifetime of oldTab until the global
44 // autoreleasepool is purged.
45 @autoreleasepool {
46 [[NSNotificationCenter defaultCenter]
47 postNotificationName:kTabModelTabDeselectedNotification
48 object:@{kTabModelTabKey : oldTab}];
49 }
50 }
51
52 if (newWebState) {
53 newTab = LegacyTabHelper::GetTabForWebState(newWebState);
54 [newTab updateLastVisitedTimestamp];
55
56 // Persist the session state.
57 if (newTab.loadFinished)
58 [_tabModel saveSessionImmediately:NO];
59 }
60 }
61
62 @end
OLDNEW
« 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