Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #import "base/ios/crb_protocol_observers.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.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" |
| 25 #import "ios/chrome/browser/chrome_url_util.h" | 24 #import "ios/chrome/browser/chrome_url_util.h" |
| 26 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" | 25 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" |
| 27 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" | 26 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" |
| 28 #import "ios/chrome/browser/sessions/session_service.h" | 27 #import "ios/chrome/browser/sessions/session_service.h" |
| 29 #import "ios/chrome/browser/sessions/session_window.h" | 28 #import "ios/chrome/browser/sessions/session_window.h" |
| 30 #import "ios/chrome/browser/snapshots/snapshot_cache.h" | 29 #import "ios/chrome/browser/snapshots/snapshot_cache.h" |
| 31 #include "ios/chrome/browser/tab_parenting_global_observer.h" | 30 #include "ios/chrome/browser/tab_parenting_global_observer.h" |
| 32 #import "ios/chrome/browser/tabs/tab.h" | 31 #import "ios/chrome/browser/tabs/tab.h" |
| 33 #import "ios/chrome/browser/tabs/tab_model_list.h" | 32 #import "ios/chrome/browser/tabs/tab_model_list.h" |
| 34 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 33 #import "ios/chrome/browser/tabs/tab_model_observers.h" |
| 35 #import "ios/chrome/browser/tabs/tab_model_order_controller.h" | 34 #import "ios/chrome/browser/tabs/tab_model_order_controller.h" |
| 36 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" | 35 #import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h" |
| 37 #import "ios/chrome/browser/xcallback_parameters.h" | 36 #import "ios/chrome/browser/xcallback_parameters.h" |
| 38 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 37 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
| 39 #import "ios/web/navigation/crw_session_controller.h" | 38 #import "ios/web/navigation/crw_session_controller.h" |
| 40 #include "ios/web/public/browser_state.h" | 39 #include "ios/web/public/browser_state.h" |
| 41 #include "ios/web/public/certificate_policy_cache.h" | 40 #include "ios/web/public/certificate_policy_cache.h" |
| 42 #include "ios/web/public/navigation_item.h" | 41 #include "ios/web/public/navigation_item.h" |
| 43 #import "ios/web/public/navigation_manager.h" | 42 #import "ios/web/public/navigation_manager.h" |
| 44 #include "ios/web/public/web_thread.h" | 43 #include "ios/web/public/web_thread.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 task_tracker->PostTaskAndReply( | 101 task_tracker->PostTaskAndReply( |
| 103 task_runner.get(), FROM_HERE, | 102 task_runner.get(), FROM_HERE, |
| 104 base::Bind(&web::CertificatePolicyCache::ClearCertificatePolicies, | 103 base::Bind(&web::CertificatePolicyCache::ClearCertificatePolicies, |
| 105 policy_cache), | 104 policy_cache), |
| 106 base::Bind(&RestoreCertificatePolicyCacheFromModel, policy_cache, | 105 base::Bind(&RestoreCertificatePolicyCacheFromModel, policy_cache, |
| 107 base::Unretained(tab_model))); | 106 base::Unretained(tab_model))); |
| 108 } | 107 } |
| 109 | 108 |
| 110 } // anonymous namespace | 109 } // anonymous namespace |
| 111 | 110 |
| 112 @interface TabModelObservers : CRBProtocolObservers<TabModelObserver> | |
| 113 @end | |
| 114 @implementation TabModelObservers | |
| 115 @end | |
| 116 | |
| 117 @interface TabModel ()<TabUsageRecorderDelegate> { | 111 @interface TabModel ()<TabUsageRecorderDelegate> { |
| 118 // Array of |Tab| objects. | 112 // Array of |Tab| objects. |
| 119 base::scoped_nsobject<NSMutableArray> _tabs; | 113 base::scoped_nsobject<NSMutableArray> _tabs; |
| 120 // Maintains policy for where new tabs go and the selection when a tab | 114 // Maintains policy for where new tabs go and the selection when a tab |
| 121 // is removed. | 115 // is removed. |
| 122 base::scoped_nsobject<TabModelOrderController> _orderController; | 116 base::scoped_nsobject<TabModelOrderController> _orderController; |
| 123 // The delegate for sync. | 117 // The delegate for sync. |
| 124 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate; | 118 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate; |
| 125 // Currently selected tab. May be nil. | 119 // Currently selected tab. May be nil. |
| 126 base::WeakNSObject<Tab> _currentTab; | 120 base::WeakNSObject<Tab> _currentTab; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 243 |
| 250 - (NSUInteger)count { | 244 - (NSUInteger)count { |
| 251 return [_tabs count]; | 245 return [_tabs count]; |
| 252 } | 246 } |
| 253 | 247 |
| 254 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window | 248 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window |
| 255 sessionService:(SessionServiceIOS*)service | 249 sessionService:(SessionServiceIOS*)service |
| 256 browserState:(ios::ChromeBrowserState*)browserState { | 250 browserState:(ios::ChromeBrowserState*)browserState { |
| 257 if ((self = [super init])) { | 251 if ((self = [super init])) { |
| 258 _observers.reset([[TabModelObservers | 252 _observers.reset([[TabModelObservers |
| 259 observersWithProtocol:@protocol(TabModelObserver)] retain]); | 253 observersWithProtocol:@protocol(TabModelObserver)] retain]); |
|
rohitrao (ping after 24h)
2017/02/13 19:24:28
Could you instead use the new +[TabModelObservers
sdefresne
2017/02/14 10:11:31
Oh, yeah this is why I added the +observers method
| |
| 260 | 254 |
| 261 _browserState = browserState; | 255 _browserState = browserState; |
| 262 DCHECK(_browserState); | 256 DCHECK(_browserState); |
| 263 | 257 |
| 264 // There must be a valid session service defined to consume session windows. | 258 // There must be a valid session service defined to consume session windows. |
| 265 DCHECK(service); | 259 DCHECK(service); |
| 266 _sessionService.reset([service retain]); | 260 _sessionService.reset([service retain]); |
| 267 | 261 |
| 268 // Normal browser states are the only ones to get tab restore. Tab sync | 262 // Normal browser states are the only ones to get tab restore. Tab sync |
| 269 // handles incognito browser states by filtering on profile, so it's | 263 // handles incognito browser states by filtering on profile, so it's |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1078 web::NavigationManager::WebLoadParams params(URL); | 1072 web::NavigationManager::WebLoadParams params(URL); |
| 1079 params.referrer = referrer; | 1073 params.referrer = referrer; |
| 1080 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 1074 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 1081 [[tab webController] loadWithParams:params]; | 1075 [[tab webController] loadWithParams:params]; |
| 1082 [tab webController].webUsageEnabled = webUsageEnabled_; | 1076 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 1083 [self insertTab:tab atIndex:index]; | 1077 [self insertTab:tab atIndex:index]; |
| 1084 return tab; | 1078 return tab; |
| 1085 } | 1079 } |
| 1086 | 1080 |
| 1087 @end | 1081 @end |
| OLD | NEW |