| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/main/browser_view_wrangler.h" | 5 #import "ios/chrome/browser/ui/main/browser_view_wrangler.h" | 
| 6 | 6 | 
| 7 #include "base/mac/objc_property_releaser.h" | 7 #include "base/mac/objc_property_releaser.h" | 
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" | 
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" | 
| 10 #include "ios/chrome/browser/application_context.h" | 10 #include "ios/chrome/browser/application_context.h" | 
| 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 
| 12 #import "ios/chrome/browser/browsing_data/browsing_data_removal_controller.h" | 12 #import "ios/chrome/browser/browsing_data/browsing_data_removal_controller.h" | 
| 13 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" | 13 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" | 
| 14 #include "ios/chrome/browser/crash_report/crash_report_helper.h" | 14 #include "ios/chrome/browser/crash_report/crash_report_helper.h" | 
| 15 #import "ios/chrome/browser/device_sharing/device_sharing_manager.h" | 15 #import "ios/chrome/browser/device_sharing/device_sharing_manager.h" | 
| 16 #import "ios/chrome/browser/physical_web/start_physical_web_discovery.h" | 16 #import "ios/chrome/browser/physical_web/start_physical_web_discovery.h" | 
| 17 #import "ios/chrome/browser/sessions/session_ios.h" | 17 #import "ios/chrome/browser/sessions/session_ios.h" | 
| 18 #import "ios/chrome/browser/sessions/session_service_ios.h" | 18 #import "ios/chrome/browser/sessions/session_service_ios.h" | 
| 19 #import "ios/chrome/browser/sessions/session_window_ios.h" | 19 #import "ios/chrome/browser/sessions/session_window_ios.h" | 
| 20 #import "ios/chrome/browser/tabs/tab.h" | 20 #import "ios/chrome/browser/tabs/tab.h" | 
| 21 #import "ios/chrome/browser/tabs/tab_model.h" | 21 #import "ios/chrome/browser/tabs/tab_model.h" | 
| 22 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 22 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 
| 23 #import "ios/chrome/browser/ui/browser_view_controller.h" | 23 #import "ios/chrome/browser/ui/browser_view_controller.h" | 
| 24 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h" | 24 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h" | 
| 25 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 25 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 
| 26 | 26 | 
| 27 @interface BrowserViewWrangler ()<TabModelObserver> { | 27 @interface BrowserViewWrangler ()<TabModelObserver> { | 
| 28   ios::ChromeBrowserState* _browserState; | 28   ios::ChromeBrowserState* _browserState; | 
| 29   __unsafe_unretained id<TabModelObserver> _tabModelObserver; | 29   __unsafe_unretained id<TabModelObserver> _tabModelObserver; | 
| 30   BOOL _isShutdown; |  | 
| 31 | 30 | 
| 32   base::mac::ObjCPropertyReleaser _propertyReleaser_BrowserViewWrangler; | 31   base::mac::ObjCPropertyReleaser _propertyReleaser_BrowserViewWrangler; | 
| 33 } | 32 } | 
| 34 | 33 | 
| 35 // Responsible for maintaining all state related to sharing to other devices. | 34 // Responsible for maintaining all state related to sharing to other devices. | 
| 36 // Redeclared readwrite from the readonly declaration in the Testing interface. | 35 // Redeclared readwrite from the readonly declaration in the Testing interface. | 
| 37 @property(nonatomic, retain, readwrite) | 36 @property(nonatomic, retain, readwrite) | 
| 38     DeviceSharingManager* deviceSharingManager; | 37     DeviceSharingManager* deviceSharingManager; | 
| 39 | 38 | 
| 40 // Creates a new autoreleased tab model for |browserState|; if |empty| is NO, | 39 // Creates a new autoreleased tab model for |browserState|; if |empty| is NO, | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 76   } | 75   } | 
| 77   return self; | 76   return self; | 
| 78 } | 77 } | 
| 79 | 78 | 
| 80 - (instancetype)init { | 79 - (instancetype)init { | 
| 81   NOTREACHED(); | 80   NOTREACHED(); | 
| 82   return nil; | 81   return nil; | 
| 83 } | 82 } | 
| 84 | 83 | 
| 85 - (void)dealloc { | 84 - (void)dealloc { | 
| 86   DCHECK(_isShutdown) << "-shutdown must be called before -dealloc"; | 85   if (_tabModelObserver) { | 
|  | 86     [_mainTabModel removeObserver:_tabModelObserver]; | 
|  | 87     [_otrTabModel removeObserver:_tabModelObserver]; | 
|  | 88   } | 
|  | 89   [_mainTabModel removeObserver:self]; | 
|  | 90   [_otrTabModel removeObserver:self]; | 
|  | 91 | 
|  | 92   // Stop URL monitoring of the main tab model. | 
|  | 93   ios_internal::breakpad::StopMonitoringURLsForTabModel(_mainTabModel); | 
|  | 94 | 
|  | 95   // Stop Breakpad state monitoring of both tab models (if necessary). | 
|  | 96   ios_internal::breakpad::StopMonitoringTabStateForTabModel(_mainTabModel); | 
|  | 97   ios_internal::breakpad::StopMonitoringTabStateForTabModel(_otrTabModel); | 
|  | 98 | 
|  | 99   // Normally other objects will take care of unhooking the tab models from | 
|  | 100   // the browser state, but this code should ensure that it happens regardless. | 
|  | 101   [_mainTabModel browserStateDestroyed]; | 
|  | 102   [_otrTabModel browserStateDestroyed]; | 
|  | 103 | 
| 87   [super dealloc]; | 104   [super dealloc]; | 
| 88 } | 105 } | 
| 89 | 106 | 
| 90 #pragma mark - BrowserViewInformation property implementations | 107 #pragma mark - BrowserViewInformation property implementations | 
| 91 | 108 | 
| 92 - (BrowserViewController*)mainBVC { | 109 - (BrowserViewController*)mainBVC { | 
| 93   if (!_mainBVC) { | 110   if (!_mainBVC) { | 
| 94     // |_browserState| should always be set before trying to create | 111     // |_browserState| should always be set before trying to create | 
| 95     // |_mainBVC|. | 112     // |_mainBVC|. | 
| 96     DCHECK(_browserState); | 113     DCHECK(_browserState); | 
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 259   // be immediately deleted. | 276   // be immediately deleted. | 
| 260   self.otrTabModel = [self buildOtrTabModel:YES]; | 277   self.otrTabModel = [self buildOtrTabModel:YES]; | 
| 261   DCHECK(![self.otrTabModel count]); | 278   DCHECK(![self.otrTabModel count]); | 
| 262   DCHECK(_browserState->HasOffTheRecordChromeBrowserState()); | 279   DCHECK(_browserState->HasOffTheRecordChromeBrowserState()); | 
| 263 | 280 | 
| 264   if (otrBVCIsCurrent) { | 281   if (otrBVCIsCurrent) { | 
| 265     _currentBVC = self.otrBVC; | 282     _currentBVC = self.otrBVC; | 
| 266   } | 283   } | 
| 267 } | 284 } | 
| 268 | 285 | 
| 269 - (void)shutdown { |  | 
| 270   DCHECK(!_isShutdown); |  | 
| 271   _isShutdown = YES; |  | 
| 272 |  | 
| 273   if (_tabModelObserver) { |  | 
| 274     [_mainTabModel removeObserver:_tabModelObserver]; |  | 
| 275     [_otrTabModel removeObserver:_tabModelObserver]; |  | 
| 276     _tabModelObserver = nil; |  | 
| 277   } |  | 
| 278 |  | 
| 279   [_mainTabModel removeObserver:self]; |  | 
| 280   [_otrTabModel removeObserver:self]; |  | 
| 281 |  | 
| 282   // Stop URL monitoring of the main tab model. |  | 
| 283   ios_internal::breakpad::StopMonitoringURLsForTabModel(_mainTabModel); |  | 
| 284 |  | 
| 285   // Stop Breakpad state monitoring of both tab models (if necessary). |  | 
| 286   ios_internal::breakpad::StopMonitoringTabStateForTabModel(_mainTabModel); |  | 
| 287   ios_internal::breakpad::StopMonitoringTabStateForTabModel(_otrTabModel); |  | 
| 288 |  | 
| 289   // Normally other objects will take care of unhooking the tab models from |  | 
| 290   // the browser state, but this code should ensure that it happens regardless. |  | 
| 291   [_mainTabModel browserStateDestroyed]; |  | 
| 292   [_otrTabModel browserStateDestroyed]; |  | 
| 293 |  | 
| 294   [_mainBVC shutdown]; |  | 
| 295   [_otrBVC shutdown]; |  | 
| 296   self.mainBVC = nil; |  | 
| 297   self.otrBVC = nil; |  | 
| 298 |  | 
| 299   _browserState = nullptr; |  | 
| 300 } |  | 
| 301 |  | 
| 302 #pragma mark - Internal methods | 286 #pragma mark - Internal methods | 
| 303 | 287 | 
| 304 - (TabModel*)buildOtrTabModel:(BOOL)empty { | 288 - (TabModel*)buildOtrTabModel:(BOOL)empty { | 
| 305   DCHECK(_browserState); | 289   DCHECK(_browserState); | 
| 306   // Ensure that the OTR ChromeBrowserState is created. | 290   // Ensure that the OTR ChromeBrowserState is created. | 
| 307   ios::ChromeBrowserState* otrBrowserState = | 291   ios::ChromeBrowserState* otrBrowserState = | 
| 308       _browserState->GetOffTheRecordChromeBrowserState(); | 292       _browserState->GetOffTheRecordChromeBrowserState(); | 
| 309   DCHECK(otrBrowserState); | 293   DCHECK(otrBrowserState); | 
| 310   return [self tabModelForBrowserState:otrBrowserState empty:empty]; | 294   return [self tabModelForBrowserState:otrBrowserState empty:empty]; | 
| 311 } | 295 } | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 345                                     tabModel:(TabModel*)tabModel { | 329                                     tabModel:(TabModel*)tabModel { | 
| 346   base::scoped_nsobject<BrowserViewControllerDependencyFactory> factory( | 330   base::scoped_nsobject<BrowserViewControllerDependencyFactory> factory( | 
| 347       [[BrowserViewControllerDependencyFactory alloc] | 331       [[BrowserViewControllerDependencyFactory alloc] | 
| 348           initWithBrowserState:browserState]); | 332           initWithBrowserState:browserState]); | 
| 349   return [[[BrowserViewController alloc] initWithTabModel:tabModel | 333   return [[[BrowserViewController alloc] initWithTabModel:tabModel | 
| 350                                              browserState:browserState | 334                                              browserState:browserState | 
| 351                                         dependencyFactory:factory] autorelease]; | 335                                         dependencyFactory:factory] autorelease]; | 
| 352 } | 336 } | 
| 353 | 337 | 
| 354 @end | 338 @end | 
| OLD | NEW | 
|---|