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

Unified Diff: ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm

Issue 2820493002: Use a scoped WebStateListObserverBridge. (Closed)
Patch Set: Feedback Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm
diff --git a/ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm b/ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm
index 447209e8403d8516ebfb566dd7d8412824536214..54db5f3a2b67e40be66f4c5451a44fc809784a2a 100644
--- a/ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm
+++ b/ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.mm
@@ -5,6 +5,7 @@
#import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h"
#include "base/memory/ptr_util.h"
+#include "base/scoped_observer.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
@@ -23,10 +24,23 @@
@implementation WebContentsMediator {
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
+ std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserverBridge>>
+ _scopedWebStateListObserver;
}
@synthesize webStateList = _webStateList;
@synthesize consumer = _consumer;
+- (instancetype)init {
+ self = [super init];
+ if (self) {
+ _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self);
+ _scopedWebStateListObserver = base::MakeUnique<
+ ScopedObserver<WebStateList, WebStateListObserverBridge>>(
+ _webStateListObserver.get());
+ }
+ return self;
+}
+
- (void)dealloc {
[self disconnect];
}
@@ -44,16 +58,12 @@
#pragma mark - Properties
- (void)setWebStateList:(WebStateList*)webStateList {
- if (_webStateList) {
- _webStateList->RemoveObserver(_webStateListObserver.get());
- _webStateListObserver.reset();
- }
+ _scopedWebStateListObserver->RemoveAll();
_webStateList = webStateList;
if (!_webStateList) {
return;
}
- _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self);
- _webStateList->AddObserver(_webStateListObserver.get());
+ _scopedWebStateListObserver->Add(_webStateList);
if (_webStateList->GetActiveWebState()) {
[self updateConsumerWithWebState:_webStateList->GetActiveWebState()];
}
« no previous file with comments | « ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698