Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm |
| diff --git a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm |
| index dcf98cfadba86dd395bae0f67cedaeeabbb9d66a..3ca3b7af4295698d82fafc2472a5af3990d8d919 100644 |
| --- a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm |
| +++ b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm |
| @@ -5,6 +5,7 @@ |
| #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/scoped_observer.h" |
| #include "base/strings/sys_string_conversions.h" |
| #import "ios/chrome/browser/web_state_list/web_state_list.h" |
| #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_consumer.h" |
| @@ -16,6 +17,8 @@ |
| @implementation TabCollectionMediator { |
| std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; |
| + std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserverBridge>> |
| + _scopedWebStateListObserver; |
| } |
| @synthesize webStateList = _webStateList; |
| @@ -34,16 +37,17 @@ |
| #pragma mark - Properties |
| - (void)setWebStateList:(WebStateList*)webStateList { |
| - if (_webStateList) { |
| - _webStateList->RemoveObserver(_webStateListObserver.get()); |
| - _webStateListObserver.reset(); |
| - } |
| + _scopedWebStateListObserver.reset(); |
|
sdefresne
2017/04/20 10:02:07
You can use RemoveAll/Add to avoid destroying the
lpromero
2017/04/20 16:25:13
Done, although could we imagine a time when Remove
|
| + _webStateListObserver.reset(); |
| _webStateList = webStateList; |
| if (!_webStateList) { |
| return; |
| } |
| _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self); |
| - _webStateList->AddObserver(_webStateListObserver.get()); |
| + _scopedWebStateListObserver = base::MakeUnique< |
| + ScopedObserver<WebStateList, WebStateListObserverBridge>>( |
| + _webStateListObserver.get()); |
| + _scopedWebStateListObserver->Add(_webStateList); |
| } |
| #pragma mark - TabCollectionDataSource |