| OLD | NEW |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 @end | 131 @end |
| 132 | 132 |
| 133 @interface TabModel ()<TabUsageRecorderDelegate> { | 133 @interface TabModel ()<TabUsageRecorderDelegate> { |
| 134 // Delegate for the WebStateList. | 134 // Delegate for the WebStateList. |
| 135 std::unique_ptr<WebStateListDelegate> _webStateListDelegate; | 135 std::unique_ptr<WebStateListDelegate> _webStateListDelegate; |
| 136 | 136 |
| 137 // Underlying shared model implementation. | 137 // Underlying shared model implementation. |
| 138 std::unique_ptr<WebStateList> _webStateList; | 138 std::unique_ptr<WebStateList> _webStateList; |
| 139 | 139 |
| 140 // Helper providing NSFastEnumeration implementation over the WebStateList. | 140 // Helper providing NSFastEnumeration implementation over the WebStateList. |
| 141 base::scoped_nsobject<WebStateListFastEnumerationHelper> | 141 std::unique_ptr<WebStateListFastEnumerationHelper> _fastEnumerationHelper; |
| 142 _fastEnumerationHelper; | |
| 143 | 142 |
| 144 // WebStateListObservers reacting to modifications of the model (may send | 143 // WebStateListObservers reacting to modifications of the model (may send |
| 145 // notification, translate and forward events, update metrics, ...). | 144 // notification, translate and forward events, update metrics, ...). |
| 146 std::vector<std::unique_ptr<WebStateListObserver>> _webStateListObservers; | 145 std::vector<std::unique_ptr<WebStateListObserver>> _webStateListObservers; |
| 147 | 146 |
| 148 // Strong references to id<WebStateListObserving> wrapped by non-owning | 147 // Strong references to id<WebStateListObserving> wrapped by non-owning |
| 149 // WebStateListObserverBridges. | 148 // WebStateListObserverBridges. |
| 150 base::scoped_nsobject<NSArray<id<WebStateListObserving>>> | 149 base::scoped_nsobject<NSArray<id<WebStateListObserving>>> |
| 151 _retainedWebStateListObservers; | 150 _retainedWebStateListObservers; |
| 152 | 151 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window | 267 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window |
| 269 sessionService:(SessionServiceIOS*)service | 268 sessionService:(SessionServiceIOS*)service |
| 270 browserState:(ios::ChromeBrowserState*)browserState { | 269 browserState:(ios::ChromeBrowserState*)browserState { |
| 271 if ((self = [super init])) { | 270 if ((self = [super init])) { |
| 272 _observers.reset([[TabModelObservers observers] retain]); | 271 _observers.reset([[TabModelObservers observers] retain]); |
| 273 | 272 |
| 274 _webStateListDelegate = | 273 _webStateListDelegate = |
| 275 base::MakeUnique<TabModelWebStateListDelegate>(self); | 274 base::MakeUnique<TabModelWebStateListDelegate>(self); |
| 276 _webStateList = base::MakeUnique<WebStateList>(_webStateListDelegate.get()); | 275 _webStateList = base::MakeUnique<WebStateList>(_webStateListDelegate.get()); |
| 277 | 276 |
| 278 _fastEnumerationHelper.reset([[WebStateListFastEnumerationHelper alloc] | 277 _fastEnumerationHelper = |
| 279 initWithWebStateList:_webStateList.get() | 278 base::MakeUnique<WebStateListFastEnumerationHelper>( |
| 280 proxyFactory:[[TabModelWebStateProxyFactory alloc] init]]); | 279 _webStateList.get(), [[TabModelWebStateProxyFactory alloc] init]); |
| 281 | 280 |
| 282 _browserState = browserState; | 281 _browserState = browserState; |
| 283 DCHECK(_browserState); | 282 DCHECK(_browserState); |
| 284 | 283 |
| 285 // Normal browser states are the only ones to get tab restore. Tab sync | 284 // Normal browser states are the only ones to get tab restore. Tab sync |
| 286 // handles incognito browser states by filtering on profile, so it's | 285 // handles incognito browser states by filtering on profile, so it's |
| 287 // important to the backend code to always have a sync window delegate. | 286 // important to the backend code to always have a sync window delegate. |
| 288 if (!_browserState->IsOffTheRecord()) { | 287 if (!_browserState->IsOffTheRecord()) { |
| 289 // Set up the usage recorder before tabs are created. | 288 // Set up the usage recorder before tabs are created. |
| 290 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self); | 289 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 664 |
| 666 int tabCount = static_cast<int>(self.count); | 665 int tabCount = static_cast<int>(self.count); |
| 667 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tabCount, 1, 200, 50); | 666 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tabCount, 1, 200, 50); |
| 668 } | 667 } |
| 669 | 668 |
| 670 #pragma mark - NSFastEnumeration | 669 #pragma mark - NSFastEnumeration |
| 671 | 670 |
| 672 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state | 671 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state |
| 673 objects:(id*)objects | 672 objects:(id*)objects |
| 674 count:(NSUInteger)count { | 673 count:(NSUInteger)count { |
| 675 return [_fastEnumerationHelper countByEnumeratingWithState:state | 674 return [_fastEnumerationHelper->GetFastEnumeration() |
| 676 objects:objects | 675 countByEnumeratingWithState:state |
| 677 count:count]; | 676 objects:objects |
| 677 count:count]; |
| 678 } | 678 } |
| 679 | 679 |
| 680 #pragma mark - TabUsageRecorderDelegate | 680 #pragma mark - TabUsageRecorderDelegate |
| 681 | 681 |
| 682 - (NSUInteger)liveTabsCount { | 682 - (NSUInteger)liveTabsCount { |
| 683 NSUInteger count = 0; | 683 NSUInteger count = 0; |
| 684 for (Tab* tab in self) { | 684 for (Tab* tab in self) { |
| 685 if ([tab.webController isViewAlive]) | 685 if ([tab.webController isViewAlive]) |
| 686 count++; | 686 count++; |
| 687 } | 687 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 821 } |
| 822 | 822 |
| 823 // Called when UIApplicationWillEnterForegroundNotification is received. | 823 // Called when UIApplicationWillEnterForegroundNotification is received. |
| 824 - (void)applicationWillEnterForeground:(NSNotification*)notify { | 824 - (void)applicationWillEnterForeground:(NSNotification*)notify { |
| 825 if (_tabUsageRecorder) { | 825 if (_tabUsageRecorder) { |
| 826 _tabUsageRecorder->AppWillEnterForeground(); | 826 _tabUsageRecorder->AppWillEnterForeground(); |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 | 829 |
| 830 @end | 830 @end |
| OLD | NEW |