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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #import "base/mac/foundation_util.h" | 13 #import "base/mac/foundation_util.h" |
14 #import "base/mac/scoped_nsobject.h" | |
15 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
16 #include "base/metrics/user_metrics_action.h" | 15 #include "base/metrics/user_metrics_action.h" |
17 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
18 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
19 #include "components/sessions/core/serialized_navigation_entry.h" | 18 #include "components/sessions/core/serialized_navigation_entry.h" |
20 #include "components/sessions/core/session_id.h" | 19 #include "components/sessions/core/session_id.h" |
21 #include "components/sessions/core/tab_restore_service.h" | 20 #include "components/sessions/core/tab_restore_service.h" |
22 #include "components/sessions/ios/ios_live_tab.h" | 21 #include "components/sessions/ios/ios_live_tab.h" |
23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
24 #include "ios/chrome/browser/chrome_url_constants.h" | 23 #include "ios/chrome/browser/chrome_url_constants.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
53 #include "ios/web/public/certificate_policy_cache.h" | 52 #include "ios/web/public/certificate_policy_cache.h" |
54 #include "ios/web/public/navigation_item.h" | 53 #include "ios/web/public/navigation_item.h" |
55 #import "ios/web/public/navigation_manager.h" | 54 #import "ios/web/public/navigation_manager.h" |
56 #import "ios/web/public/serializable_user_data_manager.h" | 55 #import "ios/web/public/serializable_user_data_manager.h" |
57 #include "ios/web/public/web_state/session_certificate_policy_cache.h" | 56 #include "ios/web/public/web_state/session_certificate_policy_cache.h" |
58 #include "ios/web/public/web_thread.h" | 57 #include "ios/web/public/web_thread.h" |
59 #import "ios/web/web_state/ui/crw_web_controller.h" | 58 #import "ios/web/web_state/ui/crw_web_controller.h" |
60 #import "ios/web/web_state/web_state_impl.h" | 59 #import "ios/web/web_state/web_state_impl.h" |
61 #include "url/gurl.h" | 60 #include "url/gurl.h" |
62 | 61 |
62 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
63 #error "This file requires ARC support." | |
64 #endif | |
65 | |
63 NSString* const kTabModelTabWillStartLoadingNotification = | 66 NSString* const kTabModelTabWillStartLoadingNotification = |
64 @"kTabModelTabWillStartLoadingNotification"; | 67 @"kTabModelTabWillStartLoadingNotification"; |
65 NSString* const kTabModelTabDidStartLoadingNotification = | 68 NSString* const kTabModelTabDidStartLoadingNotification = |
66 @"kTabModelTabDidStartLoadingNotification"; | 69 @"kTabModelTabDidStartLoadingNotification"; |
67 NSString* const kTabModelTabDidFinishLoadingNotification = | 70 NSString* const kTabModelTabDidFinishLoadingNotification = |
68 @"kTabModelTabDidFinishLoadingNotification"; | 71 @"kTabModelTabDidFinishLoadingNotification"; |
69 NSString* const kTabModelAllTabsDidCloseNotification = | 72 NSString* const kTabModelAllTabsDidCloseNotification = |
70 @"kTabModelAllTabsDidCloseNotification"; | 73 @"kTabModelAllTabsDidCloseNotification"; |
71 NSString* const kTabModelTabDeselectedNotification = | 74 NSString* const kTabModelTabDeselectedNotification = |
72 @"kTabModelTabDeselectedNotification"; | 75 @"kTabModelTabDeselectedNotification"; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 143 |
141 // Helper providing NSFastEnumeration implementation over the WebStateList. | 144 // Helper providing NSFastEnumeration implementation over the WebStateList. |
142 std::unique_ptr<WebStateListFastEnumerationHelper> _fastEnumerationHelper; | 145 std::unique_ptr<WebStateListFastEnumerationHelper> _fastEnumerationHelper; |
143 | 146 |
144 // WebStateListObservers reacting to modifications of the model (may send | 147 // WebStateListObservers reacting to modifications of the model (may send |
145 // notification, translate and forward events, update metrics, ...). | 148 // notification, translate and forward events, update metrics, ...). |
146 std::vector<std::unique_ptr<WebStateListObserver>> _webStateListObservers; | 149 std::vector<std::unique_ptr<WebStateListObserver>> _webStateListObservers; |
147 | 150 |
148 // Strong references to id<WebStateListObserving> wrapped by non-owning | 151 // Strong references to id<WebStateListObserving> wrapped by non-owning |
149 // WebStateListObserverBridges. | 152 // WebStateListObserverBridges. |
150 base::scoped_nsobject<NSArray<id<WebStateListObserving>>> | 153 NSArray<id<WebStateListObserving>>* _retainedWebStateListObservers; |
151 _retainedWebStateListObservers; | |
152 | 154 |
153 // The delegate for sync. | 155 // The delegate for sync. |
154 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate; | 156 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate; |
155 | 157 |
156 // Counters for metrics. | 158 // Counters for metrics. |
157 WebStateListMetricsObserver* _webStateListMetricsObserver; | 159 WebStateListMetricsObserver* _webStateListMetricsObserver; |
158 | 160 |
159 // Backs up property with the same name. | 161 // Backs up property with the same name. |
160 std::unique_ptr<TabUsageRecorder> _tabUsageRecorder; | 162 std::unique_ptr<TabUsageRecorder> _tabUsageRecorder; |
161 // Backs up property with the same name. | 163 // Backs up property with the same name. |
162 const SessionID _sessionID; | 164 const SessionID _sessionID; |
163 // Saves session's state. | 165 // Saves session's state. |
164 base::scoped_nsobject<SessionServiceIOS> _sessionService; | 166 SessionServiceIOS* _sessionService; |
165 // List of TabModelObservers. | 167 // List of TabModelObservers. |
166 base::scoped_nsobject<TabModelObservers> _observers; | 168 TabModelObservers* _observers; |
167 | 169 |
168 // Used to ensure thread-safety of the certificate policy management code. | 170 // Used to ensure thread-safety of the certificate policy management code. |
169 base::CancelableTaskTracker _clearPoliciesTaskTracker; | 171 base::CancelableTaskTracker _clearPoliciesTaskTracker; |
170 } | 172 } |
171 | 173 |
172 // Session window for the contents of the tab model. | 174 // Session window for the contents of the tab model. |
173 @property(nonatomic, readonly) SessionIOS* sessionForSaving; | 175 @property(nonatomic, readonly) SessionIOS* sessionForSaving; |
174 | 176 |
175 // Helper method that posts a notification with the given name with |tab| | 177 // Helper method that posts a notification with the given name with |tab| |
176 // in the userInfo dictionary under the kTabModelTabKey. | 178 // in the userInfo dictionary under the kTabModelTabKey. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 // the WebStateList destructor is called. | 215 // the WebStateList destructor is called. |
214 @autoreleasepool { | 216 @autoreleasepool { |
215 [self closeAllTabs]; | 217 [self closeAllTabs]; |
216 } | 218 } |
217 | 219 |
218 // Unregister all observers after closing all the tabs as some of them are | 220 // Unregister all observers after closing all the tabs as some of them are |
219 // required to properly clean up the Tabs. | 221 // required to properly clean up the Tabs. |
220 for (const auto& webStateListObserver : _webStateListObservers) | 222 for (const auto& webStateListObserver : _webStateListObservers) |
221 _webStateList->RemoveObserver(webStateListObserver.get()); | 223 _webStateList->RemoveObserver(webStateListObserver.get()); |
222 _webStateListObservers.clear(); | 224 _webStateListObservers.clear(); |
223 _retainedWebStateListObservers.reset(); | 225 _retainedWebStateListObservers = nil; |
224 | 226 |
225 _clearPoliciesTaskTracker.TryCancelAll(); | 227 _clearPoliciesTaskTracker.TryCancelAll(); |
226 | 228 |
stkhapugin
2017/05/03 11:56:12
nit: remove newline
sdefresne
2017/05/03 13:03:10
Done.
| |
227 [super dealloc]; | |
228 } | 229 } |
229 | 230 |
230 #pragma mark - Public methods | 231 #pragma mark - Public methods |
231 | 232 |
232 - (Tab*)currentTab { | 233 - (Tab*)currentTab { |
233 web::WebState* webState = _webStateList->GetActiveWebState(); | 234 web::WebState* webState = _webStateList->GetActiveWebState(); |
234 return webState ? LegacyTabHelper::GetTabForWebState(webState) : nil; | 235 return webState ? LegacyTabHelper::GetTabForWebState(webState) : nil; |
235 } | 236 } |
236 | 237 |
237 - (void)setCurrentTab:(Tab*)newTab { | 238 - (void)setCurrentTab:(Tab*)newTab { |
(...skipping 24 matching lines...) Expand all Loading... | |
262 } | 263 } |
263 | 264 |
264 - (WebStateList*)webStateList { | 265 - (WebStateList*)webStateList { |
265 return _webStateList.get(); | 266 return _webStateList.get(); |
266 } | 267 } |
267 | 268 |
268 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window | 269 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window |
269 sessionService:(SessionServiceIOS*)service | 270 sessionService:(SessionServiceIOS*)service |
270 browserState:(ios::ChromeBrowserState*)browserState { | 271 browserState:(ios::ChromeBrowserState*)browserState { |
271 if ((self = [super init])) { | 272 if ((self = [super init])) { |
272 _observers.reset([[TabModelObservers observers] retain]); | 273 _observers = [TabModelObservers observers]; |
273 | 274 |
274 _webStateListDelegate = | 275 _webStateListDelegate = |
275 base::MakeUnique<TabModelWebStateListDelegate>(self); | 276 base::MakeUnique<TabModelWebStateListDelegate>(self); |
276 _webStateList = base::MakeUnique<WebStateList>(_webStateListDelegate.get()); | 277 _webStateList = base::MakeUnique<WebStateList>(_webStateListDelegate.get()); |
277 | 278 |
278 _fastEnumerationHelper = | 279 _fastEnumerationHelper = |
279 base::MakeUnique<WebStateListFastEnumerationHelper>( | 280 base::MakeUnique<WebStateListFastEnumerationHelper>( |
280 _webStateList.get(), [[TabModelWebStateProxyFactory alloc] init]); | 281 _webStateList.get(), [[TabModelWebStateProxyFactory alloc] init]); |
281 | 282 |
282 _browserState = browserState; | 283 _browserState = browserState; |
283 DCHECK(_browserState); | 284 DCHECK(_browserState); |
284 | 285 |
285 // Normal browser states are the only ones to get tab restore. Tab sync | 286 // 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 | 287 // handles incognito browser states by filtering on profile, so it's |
287 // important to the backend code to always have a sync window delegate. | 288 // important to the backend code to always have a sync window delegate. |
288 if (!_browserState->IsOffTheRecord()) { | 289 if (!_browserState->IsOffTheRecord()) { |
289 // Set up the usage recorder before tabs are created. | 290 // Set up the usage recorder before tabs are created. |
290 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self); | 291 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self); |
291 } | 292 } |
292 _syncedWindowDelegate = base::MakeUnique<TabModelSyncedWindowDelegate>( | 293 _syncedWindowDelegate = base::MakeUnique<TabModelSyncedWindowDelegate>( |
293 _webStateList.get(), _sessionID); | 294 _webStateList.get(), _sessionID); |
294 | 295 |
295 // There must be a valid session service defined to consume session windows. | 296 // There must be a valid session service defined to consume session windows. |
296 DCHECK(service); | 297 DCHECK(service); |
297 _sessionService.reset([service retain]); | 298 _sessionService = service; |
298 | 299 |
299 base::scoped_nsobject<NSMutableArray<id<WebStateListObserving>>> | 300 NSMutableArray<id<WebStateListObserving>>* retainedWebStateListObservers = |
300 retainedWebStateListObservers([[NSMutableArray alloc] init]); | 301 [[NSMutableArray alloc] init]; |
301 | 302 |
302 base::scoped_nsobject<TabModelClosingWebStateObserver> | 303 TabModelClosingWebStateObserver* tabModelClosingWebStateObserver = [ |
303 tabModelClosingWebStateObserver([[TabModelClosingWebStateObserver alloc] | 304 [TabModelClosingWebStateObserver alloc] |
304 initWithTabModel:self | 305 initWithTabModel:self |
305 restoreService:IOSChromeTabRestoreServiceFactory:: | 306 restoreService:IOSChromeTabRestoreServiceFactory::GetForBrowserState( |
306 GetForBrowserState(_browserState)]); | 307 _browserState)]; |
307 [retainedWebStateListObservers addObject:tabModelClosingWebStateObserver]; | 308 [retainedWebStateListObservers addObject:tabModelClosingWebStateObserver]; |
308 | 309 |
309 _webStateListObservers.push_back( | 310 _webStateListObservers.push_back( |
310 base::MakeUnique<WebStateListObserverBridge>( | 311 base::MakeUnique<WebStateListObserverBridge>( |
311 tabModelClosingWebStateObserver)); | 312 tabModelClosingWebStateObserver)); |
312 | 313 |
313 _webStateListObservers.push_back( | 314 _webStateListObservers.push_back( |
314 base::MakeUnique<SnapshotCacheWebStateListObserver>( | 315 base::MakeUnique<SnapshotCacheWebStateListObserver>( |
315 [SnapshotCache sharedInstance])); | 316 [SnapshotCache sharedInstance])); |
316 if (_tabUsageRecorder) { | 317 if (_tabUsageRecorder) { |
317 _webStateListObservers.push_back( | 318 _webStateListObservers.push_back( |
318 base::MakeUnique<TabUsageRecorderWebStateListObserver>( | 319 base::MakeUnique<TabUsageRecorderWebStateListObserver>( |
319 _tabUsageRecorder.get())); | 320 _tabUsageRecorder.get())); |
320 } | 321 } |
321 _webStateListObservers.push_back(base::MakeUnique<TabParentingObserver>()); | 322 _webStateListObservers.push_back(base::MakeUnique<TabParentingObserver>()); |
322 | 323 |
323 base::scoped_nsobject<TabModelSelectedTabObserver> | 324 TabModelSelectedTabObserver* tabModelSelectedTabObserver = |
324 tabModelSelectedTabObserver( | 325 [[TabModelSelectedTabObserver alloc] initWithTabModel:self]; |
325 [[TabModelSelectedTabObserver alloc] initWithTabModel:self]); | |
326 [retainedWebStateListObservers addObject:tabModelSelectedTabObserver]; | 326 [retainedWebStateListObservers addObject:tabModelSelectedTabObserver]; |
327 _webStateListObservers.push_back( | 327 _webStateListObservers.push_back( |
328 base::MakeUnique<WebStateListObserverBridge>( | 328 base::MakeUnique<WebStateListObserverBridge>( |
329 tabModelSelectedTabObserver)); | 329 tabModelSelectedTabObserver)); |
330 | 330 |
331 base::scoped_nsobject<TabModelObserversBridge> tabModelObserversBridge( | 331 TabModelObserversBridge* tabModelObserversBridge = |
332 [[TabModelObserversBridge alloc] initWithTabModel:self | 332 [[TabModelObserversBridge alloc] initWithTabModel:self |
333 tabModelObservers:_observers.get()]); | 333 tabModelObservers:_observers]; |
334 [retainedWebStateListObservers addObject:tabModelObserversBridge]; | 334 [retainedWebStateListObservers addObject:tabModelObserversBridge]; |
335 _webStateListObservers.push_back( | 335 _webStateListObservers.push_back( |
336 base::MakeUnique<WebStateListObserverBridge>(tabModelObserversBridge)); | 336 base::MakeUnique<WebStateListObserverBridge>(tabModelObserversBridge)); |
337 | 337 |
338 auto webStateListMetricsObserver = | 338 auto webStateListMetricsObserver = |
339 base::MakeUnique<WebStateListMetricsObserver>(); | 339 base::MakeUnique<WebStateListMetricsObserver>(); |
340 _webStateListMetricsObserver = webStateListMetricsObserver.get(); | 340 _webStateListMetricsObserver = webStateListMetricsObserver.get(); |
341 _webStateListObservers.push_back(std::move(webStateListMetricsObserver)); | 341 _webStateListObservers.push_back(std::move(webStateListMetricsObserver)); |
342 | 342 |
343 for (const auto& webStateListObserver : _webStateListObservers) | 343 for (const auto& webStateListObserver : _webStateListObservers) |
344 _webStateList->AddObserver(webStateListObserver.get()); | 344 _webStateList->AddObserver(webStateListObserver.get()); |
345 _retainedWebStateListObservers.reset([retainedWebStateListObservers copy]); | 345 _retainedWebStateListObservers = [retainedWebStateListObservers copy]; |
346 | 346 |
347 if (window) { | 347 if (window) { |
348 DCHECK([_observers empty]); | 348 DCHECK([_observers empty]); |
349 // Restore the session and reset the session metrics (as the event have | 349 // Restore the session and reset the session metrics (as the event have |
350 // not been generated by the user but by a cold start cycle). | 350 // not been generated by the user but by a cold start cycle). |
351 [self restoreSessionWindow:window persistState:NO]; | 351 [self restoreSessionWindow:window persistState:NO]; |
352 [self resetSessionMetrics]; | 352 [self resetSessionMetrics]; |
353 } | 353 } |
354 | 354 |
355 // Register for resign active notification. | 355 // Register for resign active notification. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 } | 663 } |
664 } | 664 } |
665 | 665 |
666 int tabCount = static_cast<int>(self.count); | 666 int tabCount = static_cast<int>(self.count); |
667 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tabCount, 1, 200, 50); | 667 UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tabCount, 1, 200, 50); |
668 } | 668 } |
669 | 669 |
670 #pragma mark - NSFastEnumeration | 670 #pragma mark - NSFastEnumeration |
671 | 671 |
672 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state | 672 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state |
673 objects:(id*)objects | 673 objects:(id __unsafe_unretained*)objects |
674 count:(NSUInteger)count { | 674 count:(NSUInteger)count { |
675 return [_fastEnumerationHelper->GetFastEnumeration() | 675 return [_fastEnumerationHelper->GetFastEnumeration() |
676 countByEnumeratingWithState:state | 676 countByEnumeratingWithState:state |
677 objects:objects | 677 objects:objects |
678 count:count]; | 678 count:count]; |
679 } | 679 } |
680 | 680 |
681 #pragma mark - TabUsageRecorderDelegate | 681 #pragma mark - TabUsageRecorderDelegate |
682 | 682 |
683 - (NSUInteger)liveTabsCount { | 683 - (NSUInteger)liveTabsCount { |
(...skipping 10 matching lines...) Expand all Loading... | |
694 - (SessionIOS*)sessionForSaving { | 694 - (SessionIOS*)sessionForSaving { |
695 // Build the array of sessions. Copy the session objects as the saving will | 695 // Build the array of sessions. Copy the session objects as the saving will |
696 // be done on a separate thread. | 696 // be done on a separate thread. |
697 // TODO(crbug.com/661986): This could get expensive especially since this | 697 // TODO(crbug.com/661986): This could get expensive especially since this |
698 // window may never be saved (if another call comes in before the delay). | 698 // window may never be saved (if another call comes in before the delay). |
699 return [[SessionIOS alloc] | 699 return [[SessionIOS alloc] |
700 initWithWindows:@[ SerializeWebStateList(_webStateList.get()) ]]; | 700 initWithWindows:@[ SerializeWebStateList(_webStateList.get()) ]]; |
701 } | 701 } |
702 | 702 |
703 - (void)postNotificationName:(NSString*)notificationName withTab:(Tab*)tab { | 703 - (void)postNotificationName:(NSString*)notificationName withTab:(Tab*)tab { |
704 // A scoped_nsobject is used rather than an NSDictionary with static | 704 @autoreleasepool { |
stkhapugin
2017/05/03 11:56:12
Thank you very much for doing this. If you also kn
sdefresne
2017/05/03 13:03:10
This method was never invoked, so instead I just r
| |
705 // initializer dictionaryWithObject, because that approach adds the dictionary | 705 NSDictionary* userInfo = @{kTabModelTabKey : tab}; |
706 // to the autorelease pool, which in turn holds Tab alive longer than | 706 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName |
707 // necessary. | 707 object:self |
708 base::scoped_nsobject<NSDictionary> userInfo( | 708 userInfo:userInfo]; |
709 [[NSDictionary alloc] initWithObjectsAndKeys:tab, kTabModelTabKey, nil]); | 709 } |
710 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName | |
711 object:self | |
712 userInfo:userInfo]; | |
713 } | 710 } |
714 | 711 |
715 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window | 712 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window |
716 persistState:(BOOL)persistState { | 713 persistState:(BOOL)persistState { |
717 DCHECK(_browserState); | 714 DCHECK(_browserState); |
718 DCHECK(window); | 715 DCHECK(window); |
719 | 716 |
720 if (!window.sessions.count) | 717 if (!window.sessions.count) |
721 return NO; | 718 return NO; |
722 | 719 |
723 int oldCount = _webStateList->count(); | 720 int oldCount = _webStateList->count(); |
724 DCHECK_GE(oldCount, 0); | 721 DCHECK_GE(oldCount, 0); |
725 | 722 |
726 web::WebState::CreateParams createParams(_browserState); | 723 web::WebState::CreateParams createParams(_browserState); |
727 DeserializeWebStateList( | 724 DeserializeWebStateList( |
728 _webStateList.get(), window, | 725 _webStateList.get(), window, |
729 base::BindRepeating(&web::WebState::CreateWithStorageSession, | 726 base::BindRepeating(&web::WebState::CreateWithStorageSession, |
730 createParams)); | 727 createParams)); |
731 | 728 |
732 DCHECK_GT(_webStateList->count(), oldCount); | 729 DCHECK_GT(_webStateList->count(), oldCount); |
733 int restoredCount = _webStateList->count() - oldCount; | 730 int restoredCount = _webStateList->count() - oldCount; |
734 DCHECK_EQ(window.sessions.count, static_cast<NSUInteger>(restoredCount)); | 731 DCHECK_EQ(window.sessions.count, static_cast<NSUInteger>(restoredCount)); |
735 | 732 |
736 scoped_refptr<web::CertificatePolicyCache> policyCache = | 733 scoped_refptr<web::CertificatePolicyCache> policyCache = |
737 web::BrowserState::GetCertificatePolicyCache(_browserState); | 734 web::BrowserState::GetCertificatePolicyCache(_browserState); |
738 | 735 |
739 base::scoped_nsobject<NSMutableArray<Tab*>> restoredTabs( | 736 NSMutableArray<Tab*>* restoredTabs = |
740 [[NSMutableArray alloc] initWithCapacity:window.sessions.count]); | 737 [[NSMutableArray alloc] initWithCapacity:window.sessions.count]; |
741 | 738 |
742 for (int index = oldCount; index < _webStateList->count(); ++index) { | 739 for (int index = oldCount; index < _webStateList->count(); ++index) { |
743 web::WebState* webState = _webStateList->GetWebStateAt(index); | 740 web::WebState* webState = _webStateList->GetWebStateAt(index); |
744 Tab* tab = LegacyTabHelper::GetTabForWebState(webState); | 741 Tab* tab = LegacyTabHelper::GetTabForWebState(webState); |
745 | 742 |
746 webState->SetWebUsageEnabled(webUsageEnabled_ ? true : false); | 743 webState->SetWebUsageEnabled(webUsageEnabled_ ? true : false); |
747 tab.webController.usePlaceholderOverlay = YES; | 744 tab.webController.usePlaceholderOverlay = YES; |
748 | 745 |
749 // Restore the CertificatePolicyCache (note that webState is invalid after | 746 // Restore the CertificatePolicyCache (note that webState is invalid after |
750 // passing it via move semantic to -initWithWebState:model:). | 747 // passing it via move semantic to -initWithWebState:model:). |
751 UpdateCertificatePolicyCacheFromWebState(policyCache, [tab webState]); | 748 UpdateCertificatePolicyCacheFromWebState(policyCache, [tab webState]); |
752 [restoredTabs addObject:tab]; | 749 [restoredTabs addObject:tab]; |
753 } | 750 } |
754 | 751 |
755 // If there was only one tab and it was the new tab page, clobber it. | 752 // If there was only one tab and it was the new tab page, clobber it. |
756 BOOL closedNTPTab = NO; | 753 BOOL closedNTPTab = NO; |
757 if (oldCount == 1) { | 754 if (oldCount == 1) { |
758 Tab* tab = [self tabAtIndex:0]; | 755 Tab* tab = [self tabAtIndex:0]; |
759 if (tab.url == GURL(kChromeUINewTabURL)) { | 756 if (tab.url == GURL(kChromeUINewTabURL)) { |
760 [self closeTab:tab]; | 757 [self closeTab:tab]; |
761 closedNTPTab = YES; | 758 closedNTPTab = YES; |
762 oldCount = 0; | 759 oldCount = 0; |
763 } | 760 } |
764 } | 761 } |
765 if (_tabUsageRecorder) | 762 if (_tabUsageRecorder) |
766 _tabUsageRecorder->InitialRestoredTabs(self.currentTab, restoredTabs.get()); | 763 _tabUsageRecorder->InitialRestoredTabs(self.currentTab, restoredTabs); |
767 return closedNTPTab; | 764 return closedNTPTab; |
768 } | 765 } |
769 | 766 |
770 #pragma mark - Notification Handlers | 767 #pragma mark - Notification Handlers |
771 | 768 |
772 // Called when UIApplicationWillResignActiveNotification is received. | 769 // Called when UIApplicationWillResignActiveNotification is received. |
773 - (void)willResignActive:(NSNotification*)notify { | 770 - (void)willResignActive:(NSNotification*)notify { |
774 if (webUsageEnabled_ && self.currentTab) { | 771 if (webUsageEnabled_ && self.currentTab) { |
775 [[SnapshotCache sharedInstance] | 772 [[SnapshotCache sharedInstance] |
776 willBeSavedGreyWhenBackgrounding:self.currentTab.tabId]; | 773 willBeSavedGreyWhenBackgrounding:self.currentTab.tabId]; |
(...skipping 28 matching lines...) Expand all Loading... | |
805 } | 802 } |
806 | 803 |
807 // Called when UIApplicationWillEnterForegroundNotification is received. | 804 // Called when UIApplicationWillEnterForegroundNotification is received. |
808 - (void)applicationWillEnterForeground:(NSNotification*)notify { | 805 - (void)applicationWillEnterForeground:(NSNotification*)notify { |
809 if (_tabUsageRecorder) { | 806 if (_tabUsageRecorder) { |
810 _tabUsageRecorder->AppWillEnterForeground(); | 807 _tabUsageRecorder->AppWillEnterForeground(); |
811 } | 808 } |
812 } | 809 } |
813 | 810 |
814 @end | 811 @end |
OLD | NEW |