| Index: ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.mm
|
| diff --git a/ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.mm b/ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.mm
|
| index e08207600277c0f8c59b857d18d827b516893058..dfc05121b7939309b9bd5043c5580b8cd50cea54 100644
|
| --- a/ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.mm
|
| +++ b/ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.mm
|
| @@ -5,7 +5,10 @@
|
| #import "ios/clean/chrome/browser/ui/toolbar/toolbar_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/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
|
| #import "ios/clean/chrome/browser/ui/toolbar/toolbar_consumer.h"
|
| #import "ios/web/public/navigation_manager.h"
|
| #include "ios/web/public/web_state/web_state.h"
|
| @@ -15,19 +18,29 @@
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| -@interface ToolbarMediator ()<CRWWebStateObserver>
|
| +@interface ToolbarMediator ()<CRWWebStateObserver, WebStateListObserving>
|
| @end
|
|
|
| @implementation ToolbarMediator {
|
| std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
|
| + std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
|
| + std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserverBridge>>
|
| + _scopedWebStateListObserver;
|
| }
|
|
|
| @synthesize consumer = _consumer;
|
| @synthesize webState = _webState;
|
| +@synthesize webStateList = _webStateList;
|
|
|
| - (void)dealloc {
|
| + [self disconnect];
|
| +}
|
| +
|
| +#pragma mark - Public
|
| +
|
| +- (void)disconnect {
|
| + self.webStateList = nullptr;
|
| _webStateObserver.reset();
|
| - _webState = nullptr;
|
| }
|
|
|
| #pragma mark - CRWWebStateObserver
|
| @@ -58,6 +71,20 @@
|
| [self.consumer setTabStripVisible:visible];
|
| }
|
|
|
| +#pragma mark - WebStateListObserver
|
| +
|
| +- (void)webStateList:(WebStateList*)webStateList
|
| + didInsertWebState:(web::WebState*)webState
|
| + atIndex:(int)index {
|
| + [self.consumer setTabCount:_webStateList->count()];
|
| +}
|
| +
|
| +- (void)webStateList:(WebStateList*)webStateList
|
| + didDetachWebState:(web::WebState*)webState
|
| + atIndex:(int)index {
|
| + [self.consumer setTabCount:_webStateList->count()];
|
| +}
|
| +
|
| #pragma mark - Setters
|
|
|
| - (void)setWebState:(web::WebState*)webState {
|
| @@ -74,6 +101,24 @@
|
| if (self.webState) {
|
| [self updateConsumer];
|
| }
|
| + if (self.webStateList) {
|
| + [self.consumer setTabCount:_webStateList->count()];
|
| + }
|
| +}
|
| +
|
| +- (void)setWebStateList:(WebStateList*)webStateList {
|
| + // TODO(crbug.com/727427):Add support for DCHECK(webStateList).
|
| + _webStateList = webStateList;
|
| + _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self);
|
| + _scopedWebStateListObserver = base::MakeUnique<
|
| + ScopedObserver<WebStateList, WebStateListObserverBridge>>(
|
| + _webStateListObserver.get());
|
| + if (_webStateList) {
|
| + _scopedWebStateListObserver->Add(_webStateList);
|
| + if (self.consumer) {
|
| + [self.consumer setTabCount:_webStateList->count()];
|
| + }
|
| + }
|
| }
|
|
|
| #pragma mark - Helper methods
|
|
|