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

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

Issue 2769193002: [ios] Expose TabModel underlying WebStateList. (Closed)
Patch Set: Rebase on origin/master. Created 3 years, 9 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
« no previous file with comments | « ios/chrome/browser/tabs/tab_model.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 // Helper providing NSFastEnumeration implementation over the WebStateList. 157 // Helper providing NSFastEnumeration implementation over the WebStateList.
158 base::scoped_nsobject<WebStateListFastEnumerationHelper> 158 base::scoped_nsobject<WebStateListFastEnumerationHelper>
159 _fastEnumerationHelper; 159 _fastEnumerationHelper;
160 160
161 // Used to keep the Tabs alive while the corresponding WebStates are stored 161 // Used to keep the Tabs alive while the corresponding WebStates are stored
162 // in the WebStateList (as Tabs currently own their WebState). Remove once 162 // in the WebStateList (as Tabs currently own their WebState). Remove once
163 // WebState owns the associated Tab. 163 // WebState owns the associated Tab.
164 base::scoped_nsobject<NSMutableSet<Tab*>> _tabRetainer; 164 base::scoped_nsobject<NSMutableSet<Tab*>> _tabRetainer;
165 165
166 // WebStateListObserver bridges to react to modifications of the model (may 166 // WebStateListObservers reacting to modifications of the model (may send
167 // send notification, translate and forward events, update metrics, ...). 167 // notification, translate and forward events, update metrics, ...).
168 std::vector<std::unique_ptr<WebStateListObserver>> _observerBridges; 168 std::vector<std::unique_ptr<WebStateListObserver>> _webStateListObservers;
169 169
170 // The delegate for sync. 170 // The delegate for sync.
171 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate; 171 std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate;
172 172
173 // Counters for metrics. 173 // Counters for metrics.
174 WebStateListMetricsObserver* _webStateListMetricsObserver; 174 WebStateListMetricsObserver* _webStateListMetricsObserver;
175 175
176 // Backs up property with the same name. 176 // Backs up property with the same name.
177 std::unique_ptr<TabUsageRecorder> _tabUsageRecorder; 177 std::unique_ptr<TabUsageRecorder> _tabUsageRecorder;
178 // Backs up property with the same name. 178 // Backs up property with the same name.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 - (void)dealloc { 230 - (void)dealloc {
231 DCHECK([_observers empty]); 231 DCHECK([_observers empty]);
232 // browserStateDestroyed should always have been called before destruction. 232 // browserStateDestroyed should always have been called before destruction.
233 DCHECK(!_browserState); 233 DCHECK(!_browserState);
234 234
235 [[NSNotificationCenter defaultCenter] removeObserver:self]; 235 [[NSNotificationCenter defaultCenter] removeObserver:self];
236 236
237 // Clear weak pointer to WebStateListMetricsObserver before destroying it. 237 // Clear weak pointer to WebStateListMetricsObserver before destroying it.
238 _webStateListMetricsObserver = nullptr; 238 _webStateListMetricsObserver = nullptr;
239 239
240 // Unregister all listeners before closing all the tabs. 240 // Unregister all observers before closing all the tabs.
241 for (const auto& observerBridge : _observerBridges) 241 for (const auto& webStateListObserver : _webStateListObservers)
242 _webStateList->RemoveObserver(observerBridge.get()); 242 _webStateList->RemoveObserver(webStateListObserver.get());
243 _observerBridges.clear(); 243 _webStateListObservers.clear();
244 244
245 // Make sure the tabs do clean after themselves. It is important for 245 // Make sure the tabs do clean after themselves. It is important for
246 // removeObserver: to be called first otherwise a lot of unecessary work will 246 // removeObserver: to be called first otherwise a lot of unecessary work will
247 // happen on -closeAllTabs. 247 // happen on -closeAllTabs.
248 [self closeAllTabs]; 248 [self closeAllTabs];
249 249
250 _clearPoliciesTaskTracker.TryCancelAll(); 250 _clearPoliciesTaskTracker.TryCancelAll();
251 251
252 [super dealloc]; 252 [super dealloc];
253 } 253 }
(...skipping 25 matching lines...) Expand all
279 279
280 - (BOOL)isEmpty { 280 - (BOOL)isEmpty {
281 return _webStateList->empty(); 281 return _webStateList->empty();
282 } 282 }
283 283
284 - (NSUInteger)count { 284 - (NSUInteger)count {
285 DCHECK_GE(_webStateList->count(), 0); 285 DCHECK_GE(_webStateList->count(), 0);
286 return static_cast<NSUInteger>(_webStateList->count()); 286 return static_cast<NSUInteger>(_webStateList->count());
287 } 287 }
288 288
289 - (WebStateList*)webStateList {
290 return _webStateList.get();
291 }
292
289 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window 293 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window
290 sessionService:(SessionServiceIOS*)service 294 sessionService:(SessionServiceIOS*)service
291 browserState:(ios::ChromeBrowserState*)browserState { 295 browserState:(ios::ChromeBrowserState*)browserState {
292 if ((self = [super init])) { 296 if ((self = [super init])) {
293 _tabRetainer.reset([[NSMutableSet alloc] init]); 297 _tabRetainer.reset([[NSMutableSet alloc] init]);
294 _observers.reset([[TabModelObservers observers] retain]); 298 _observers.reset([[TabModelObservers observers] retain]);
295 299
296 _webStateListDelegate = 300 _webStateListDelegate =
297 base::MakeUnique<TabModelWebStateListDelegate>(self); 301 base::MakeUnique<TabModelWebStateListDelegate>(self);
298 _webStateList = base::MakeUnique<WebStateList>( 302 _webStateList = base::MakeUnique<WebStateList>(
(...skipping 13 matching lines...) Expand all
312 // Set up the usage recorder before tabs are created. 316 // Set up the usage recorder before tabs are created.
313 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self); 317 _tabUsageRecorder = base::MakeUnique<TabUsageRecorder>(self);
314 } 318 }
315 _syncedWindowDelegate = 319 _syncedWindowDelegate =
316 base::MakeUnique<TabModelSyncedWindowDelegate>(self); 320 base::MakeUnique<TabModelSyncedWindowDelegate>(self);
317 321
318 // There must be a valid session service defined to consume session windows. 322 // There must be a valid session service defined to consume session windows.
319 DCHECK(service); 323 DCHECK(service);
320 _sessionService.reset([service retain]); 324 _sessionService.reset([service retain]);
321 325
322 _observerBridges.push_back( 326 _webStateListObservers.push_back(
323 base::MakeUnique<SnapshotCacheWebStateListObserver>( 327 base::MakeUnique<SnapshotCacheWebStateListObserver>(
324 [SnapshotCache sharedInstance])); 328 [SnapshotCache sharedInstance]));
325 if (_tabUsageRecorder) { 329 if (_tabUsageRecorder) {
326 _observerBridges.push_back( 330 _webStateListObservers.push_back(
327 base::MakeUnique<TabUsageRecorderWebStateListObserver>( 331 base::MakeUnique<TabUsageRecorderWebStateListObserver>(
328 _tabUsageRecorder.get())); 332 _tabUsageRecorder.get()));
329 } 333 }
330 _observerBridges.push_back(base::MakeUnique<TabParentingObserver>()); 334 _webStateListObservers.push_back(base::MakeUnique<TabParentingObserver>());
331 _observerBridges.push_back(base::MakeUnique<WebStateListObserverBridge>( 335 _webStateListObservers.push_back(
332 [[TabModelSelectedTabObserver alloc] initWithTabModel:self])); 336 base::MakeUnique<WebStateListObserverBridge>(
333 _observerBridges.push_back(base::MakeUnique<WebStateListObserverBridge>( 337 [[TabModelSelectedTabObserver alloc] initWithTabModel:self]));
334 [[TabModelObserversBridge alloc] initWithTabModel:self 338 _webStateListObservers.push_back(
335 tabModelObservers:_observers.get()])); 339 base::MakeUnique<WebStateListObserverBridge>(
340 [[TabModelObserversBridge alloc]
341 initWithTabModel:self
342 tabModelObservers:_observers.get()]));
336 343
337 auto webStateListMetricsObserver = 344 auto webStateListMetricsObserver =
338 base::MakeUnique<WebStateListMetricsObserver>(); 345 base::MakeUnique<WebStateListMetricsObserver>();
339 _webStateListMetricsObserver = webStateListMetricsObserver.get(); 346 _webStateListMetricsObserver = webStateListMetricsObserver.get();
340 _observerBridges.push_back(std::move(webStateListMetricsObserver)); 347 _webStateListObservers.push_back(std::move(webStateListMetricsObserver));
341 348
342 for (const auto& observerBridge : _observerBridges) 349 for (const auto& webStateListObserver : _webStateListObservers)
343 _webStateList->AddObserver(observerBridge.get()); 350 _webStateList->AddObserver(webStateListObserver.get());
344 351
345 if (window) { 352 if (window) {
346 DCHECK([_observers empty]); 353 DCHECK([_observers empty]);
347 // Restore the session and reset the session metrics (as the event have 354 // Restore the session and reset the session metrics (as the event have
348 // not been generated by the user but by a cold start cycle). 355 // not been generated by the user but by a cold start cycle).
349 [self restoreSessionWindow:window persistState:NO]; 356 [self restoreSessionWindow:window persistState:NO];
350 [self resetSessionMetrics]; 357 [self resetSessionMetrics];
351 } 358 }
352 359
353 // Register for resign active notification. 360 // Register for resign active notification.
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 } 966 }
960 967
961 // Called when UIApplicationWillEnterForegroundNotification is received. 968 // Called when UIApplicationWillEnterForegroundNotification is received.
962 - (void)applicationWillEnterForeground:(NSNotification*)notify { 969 - (void)applicationWillEnterForeground:(NSNotification*)notify {
963 if (_tabUsageRecorder) { 970 if (_tabUsageRecorder) {
964 _tabUsageRecorder->AppWillEnterForeground(); 971 _tabUsageRecorder->AppWillEnterForeground();
965 } 972 }
966 } 973 }
967 974
968 @end 975 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698