Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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_model_selected_tab_observer.h" | 5 #import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" | 8 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" |
| 9 #import "ios/chrome/browser/tabs/tab.h" | 9 #import "ios/chrome/browser/tabs/tab.h" |
| 10 #import "ios/chrome/browser/tabs/tab_model.h" | 10 #import "ios/chrome/browser/tabs/tab_model.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 return self; | 25 return self; |
| 26 } | 26 } |
| 27 | 27 |
| 28 #pragma mark WebStateListObserving | 28 #pragma mark WebStateListObserving |
| 29 | 29 |
| 30 - (void)webStateList:(WebStateList*)webStateList | 30 - (void)webStateList:(WebStateList*)webStateList |
| 31 didChangeActiveWebState:(web::WebState*)newWebState | 31 didChangeActiveWebState:(web::WebState*)newWebState |
| 32 oldWebState:(web::WebState*)oldWebState | 32 oldWebState:(web::WebState*)oldWebState |
| 33 atIndex:(int)atIndex | 33 atIndex:(int)atIndex |
| 34 userAction:(BOOL)userAction { | 34 userAction:(BOOL)userAction { |
| 35 Tab* oldTab = nil; | |
| 36 Tab* newTab = nil; | |
| 37 if (oldWebState) { | 35 if (oldWebState) { |
| 38 // Save state, such as scroll position, ... of the old selected Tab. | 36 // Save state, such as scroll position, ... of the old selected Tab. |
| 39 oldTab = LegacyTabHelper::GetTabForWebState(oldWebState); | 37 Tab* oldTab = LegacyTabHelper::GetTabForWebState(oldWebState); |
| 40 if (userAction) | 38 DCHECK(oldTab); |
|
Eugene But (OOO till 7-30)
2017/04/11 14:50:48
nit: I don't think you need to DCHECK here. |@{kTa
| |
| 41 [oldTab recordStateInHistory]; | |
|
kkhorimoto
2017/04/11 18:20:00
From what I can tell, it looks like we're no longe
Eugene But (OOO till 7-30)
2017/04/11 18:39:39
Would it be useful to commit "safe" part in one CL
| |
| 42 | 39 |
| 43 // Avoid artificially extending the lifetime of oldTab until the global | 40 // Avoid artificially extending the lifetime of oldTab until the global |
| 44 // autoreleasepool is purged. | 41 // autoreleasepool is purged. |
| 45 @autoreleasepool { | 42 @autoreleasepool { |
| 46 [[NSNotificationCenter defaultCenter] | 43 [[NSNotificationCenter defaultCenter] |
| 47 postNotificationName:kTabModelTabDeselectedNotification | 44 postNotificationName:kTabModelTabDeselectedNotification |
| 48 object:_tabModel | 45 object:_tabModel |
| 49 userInfo:@{kTabModelTabKey : oldTab}]; | 46 userInfo:@{kTabModelTabKey : oldTab}]; |
| 50 } | 47 } |
| 51 } | 48 } |
| 52 | 49 |
| 53 if (newWebState) { | 50 if (newWebState) { |
| 54 newTab = LegacyTabHelper::GetTabForWebState(newWebState); | 51 Tab* newTab = LegacyTabHelper::GetTabForWebState(newWebState); |
| 55 [newTab updateLastVisitedTimestamp]; | 52 [newTab updateLastVisitedTimestamp]; |
| 56 | 53 |
| 57 // Persist the session state. | 54 // Persist the session state. |
| 58 if (newTab.loadFinished) | 55 if (newTab.loadFinished) |
| 59 [_tabModel saveSessionImmediately:NO]; | 56 [_tabModel saveSessionImmediately:NO]; |
| 60 } | 57 } |
| 61 } | 58 } |
| 62 | 59 |
| 63 @end | 60 @end |
| OLD | NEW |