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

Side by Side Diff: ios/chrome/browser/tabs/tab_model.mm

Issue 2710183003: Fix WebStateListObserver::WebStateDetachedAt() parameter lifetime. (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 unified diff | Download patch
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_model.h" 5 #import "ios/chrome/browser/tabs/tab_model.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 586
587 int index = _webStateList.GetIndexOfWebState(oldTab.webState); 587 int index = _webStateList.GetIndexOfWebState(oldTab.webState);
588 DCHECK_NE(index, WebStateList::kInvalidIndex); 588 DCHECK_NE(index, WebStateList::kInvalidIndex);
589 DCHECK_GE(index, 0); 589 DCHECK_GE(index, 0);
590 590
591 base::scoped_nsobject<Tab> tabSaver([oldTab retain]); 591 base::scoped_nsobject<Tab> tabSaver([oldTab retain]);
592 [_tabRetainer removeObject:oldTab]; 592 [_tabRetainer removeObject:oldTab];
593 [_tabRetainer addObject:newTab]; 593 [_tabRetainer addObject:newTab];
594 [newTab setParentTabModel:self]; 594 [newTab setParentTabModel:self];
595 595
596 _webStateList.ReplaceWebStateAt(index, newTab.webState, 596 // The WebState is owned by the associated Tab, so it is safe to ignore
597 GetOpenerForTab(self, newTab).webState); 597 // the result and won't cause a memory leak. Once the ownershipd is moved
598 // to WebStateList, this function will return a std::unique_ptr<> and the
599 // object destroyed as expected, so it will fine to ignore the result then
600 // too. See http://crbug.com/546222 for progress of changing the ownership
601 // of the WebStates.
602 ignore_result(_webStateList.ReplaceWebStateAt(
603 index, newTab.webState, GetOpenerForTab(self, newTab).webState));
598 604
599 if (self.currentTab == oldTab) 605 if (self.currentTab == oldTab)
600 [self changeSelectedTabFrom:nil to:newTab persistState:NO]; 606 [self changeSelectedTabFrom:nil to:newTab persistState:NO];
601 607
602 [oldTab setParentTabModel:nil]; 608 [oldTab setParentTabModel:nil];
603 [oldTab close]; 609 [oldTab close];
604 } 610 }
605 611
606 - (void)closeTabAtIndex:(NSUInteger)index { 612 - (void)closeTabAtIndex:(NSUInteger)index {
607 DCHECK(index < self.count); 613 DCHECK(index < self.count);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // If closing the current tab, clear |_currentTab| before sending any 757 // If closing the current tab, clear |_currentTab| before sending any
752 // notification. This avoids various parts of the code getting confused 758 // notification. This avoids various parts of the code getting confused
753 // when the current tab isn't in the tab model. 759 // when the current tab isn't in the tab model.
754 Tab* savedCurrentTab = _currentTab; 760 Tab* savedCurrentTab = _currentTab;
755 if (closedTab == _currentTab) 761 if (closedTab == _currentTab)
756 _currentTab.reset(nil); 762 _currentTab.reset(nil);
757 763
758 DCHECK([_tabRetainer containsObject:closedTab]); 764 DCHECK([_tabRetainer containsObject:closedTab]);
759 [_tabRetainer removeObject:closedTab]; 765 [_tabRetainer removeObject:closedTab];
760 766
761 _webStateList.DetachWebStateAt(closedTabIndex); 767 // The WebState is owned by the associated Tab, so it is safe to ignore
768 // the result and won't cause a memory leak. Once the ownershipd is moved
769 // to WebStateList, this function will return a std::unique_ptr<> and the
770 // object destroyed as expected, so it will fine to ignore the result then
771 // too. See http://crbug.com/546222 for progress of changing the ownership
772 // of the WebStates.
773 ignore_result(_webStateList.DetachWebStateAt(closedTabIndex));
762 774
763 // Current tab has closed, update the selected tab and swap in its 775 // Current tab has closed, update the selected tab and swap in its
764 // contents. There is nothing to do if a non-selected tab is closed as 776 // contents. There is nothing to do if a non-selected tab is closed as
765 // the selection isn't index-based, therefore it hasn't changed. 777 // the selection isn't index-based, therefore it hasn't changed.
766 // -changeSelectedTabFrom: will persist the state change, so only do it 778 // -changeSelectedTabFrom: will persist the state change, so only do it
767 // if the selection isn't changing. 779 // if the selection isn't changing.
768 if (closedTab == savedCurrentTab) { 780 if (closedTab == savedCurrentTab) {
769 [self changeSelectedTabFrom:closedTab to:newSelection persistState:NO]; 781 [self changeSelectedTabFrom:closedTab to:newSelection persistState:NO];
770 } else { 782 } else {
771 [self saveSessionImmediately:NO]; 783 [self saveSessionImmediately:NO];
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 web::NavigationManager::WebLoadParams params(URL); 1144 web::NavigationManager::WebLoadParams params(URL);
1133 params.referrer = referrer; 1145 params.referrer = referrer;
1134 params.transition_type = ui::PAGE_TRANSITION_TYPED; 1146 params.transition_type = ui::PAGE_TRANSITION_TYPED;
1135 [[tab webController] loadWithParams:params]; 1147 [[tab webController] loadWithParams:params];
1136 [tab webController].webUsageEnabled = webUsageEnabled_; 1148 [tab webController].webUsageEnabled = webUsageEnabled_;
1137 [self insertTab:tab atIndex:index opener:parentTab]; 1149 [self insertTab:tab atIndex:index opener:parentTab];
1138 return tab; 1150 return tab;
1139 } 1151 }
1140 1152
1141 @end 1153 @end
OLDNEW
« no previous file with comments | « no previous file | ios/shared/chrome/browser/tabs/web_state_list.h » ('j') | ios/shared/chrome/browser/tabs/web_state_list.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698