Commit 2bd4fe13 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize Activity Service Legacy Coordinator.

This CL modernizes the ActivityServiceLegacyCoordinator
 - to use the superclass -initWithBaseViewController:browser:
initializer, instead of -initWithBaseViewController:.
 - to remove the public property for dispatcher, webstatelist,
browserstate and tabmodel.

Bug: 1029346
Change-Id: Ieba5a4df18470a91de783ca1703414e0df34c0f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033153
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737328}
parent e353759b
......@@ -66,6 +66,7 @@ source_set("coordinator") {
"//base",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/activity_services/requirements",
......
......@@ -9,28 +9,25 @@
@protocol ActivityServicePositioner;
@protocol ActivityServicePresentation;
class ChromeBrowserState;
@class CommandDispatcher;
@class TabModel;
// ActivityServiceLegacyCoordinator provides a public interface for the share
// menu feature.
@interface ActivityServiceLegacyCoordinator : ChromeCoordinator
// Models.
@property(nonatomic, readwrite, assign) ChromeBrowserState* browserState;
@property(nonatomic, readwrite, weak) CommandDispatcher* dispatcher;
@property(nonatomic, readwrite, weak) TabModel* tabModel;
// Providers.
@property(nonatomic, readwrite, weak) id<ActivityServicePositioner>
positionProvider;
@property(nonatomic, readwrite, weak) id<ActivityServicePresentation>
presentationProvider;
// Removes references to any weak objects that this coordinator holds pointers
// to.
- (void)disconnect;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
// Cancels any in-progress share activities and dismisses the corresponding UI.
- (void)cancelShare;
......
......@@ -7,8 +7,8 @@
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/passwords/password_tab_helper.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/activity_services/activity_service_controller.h"
#import "ios/chrome/browser/ui/activity_services/canonical_url_retriever.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_password.h"
......@@ -44,10 +44,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
@implementation ActivityServiceLegacyCoordinator
@synthesize browserState = _browserState;
@synthesize dispatcher = _dispatcher;
@synthesize tabModel = _tabModel;
@synthesize positionProvider = _positionProvider;
@synthesize presentationProvider = _presentationProvider;
......@@ -55,9 +51,14 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
#pragma mark - Public methods
- (void)disconnect {
self.browserState = nil;
self.dispatcher = nil;
- (void)start {
[self.browser->GetCommandDispatcher()
startDispatchingToTarget:self
forSelector:@selector(sharePage)];
}
- (void)stop {
[self.browser->GetCommandDispatcher() stopDispatchingToTarget:self];
}
- (void)cancelShare {
......@@ -65,28 +66,13 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
[controller cancelShareAnimated:NO];
}
#pragma mark - Properties
- (void)setDispatcher:(CommandDispatcher*)dispatcher {
if (dispatcher == self.dispatcher) {
return;
}
if (self.dispatcher) {
[self.dispatcher stopDispatchingToTarget:self];
}
[dispatcher startDispatchingToTarget:self forSelector:@selector(sharePage)];
_dispatcher = dispatcher;
}
#pragma mark - Command handlers
- (void)sharePage {
self.sharePageStartTime = base::TimeTicks::Now();
__weak ActivityServiceLegacyCoordinator* weakSelf = self;
activity_services::RetrieveCanonicalUrl(
self.tabModel.webStateList->GetActiveWebState(), ^(const GURL& url) {
self.browser->GetWebStateList()->GetActiveWebState(), ^(const GURL& url) {
[weakSelf sharePageWithCanonicalURL:url];
});
}
......@@ -94,7 +80,8 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
#pragma mark - Providers
- (id<PasswordFormFiller>)currentPasswordFormFiller {
web::WebState* webState = self.tabModel.webStateList->GetActiveWebState();
web::WebState* webState =
self.browser->GetWebStateList()->GetActiveWebState();
return webState ? PasswordTabHelper::FromWebState(webState)
->GetPasswordFormFiller()
: nil;
......@@ -104,7 +91,7 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
- (void)sharePageWithCanonicalURL:(const GURL&)canonicalURL {
ShareToData* data = activity_services::ShareToDataForWebState(
self.tabModel.webStateList->GetActiveWebState(), canonicalURL);
self.browser->GetWebStateList()->GetActiveWebState(), canonicalURL);
if (!data)
return;
......@@ -118,10 +105,12 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
self.sharePageStartTime = base::TimeTicks();
}
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up.
[controller shareWithData:data
browserState:self.browserState
browserState:self.browser->GetBrowserState()
dispatcher:static_cast<id<BrowserCommands, SnackbarCommands>>(
self.dispatcher)
self.browser->GetCommandDispatcher())
passwordProvider:self
positionProvider:self.positionProvider
presentationProvider:self.presentationProvider];
......
......@@ -1371,7 +1371,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[self uninstallDelegatesForWebState:webStateList->GetWebStateAt(index)];
// Disconnect child coordinators.
[_activityServiceCoordinator disconnect];
[_activityServiceCoordinator stop];
[self.popupMenuCoordinator stop];
[self.tabStripCoordinator stop];
self.tabStripCoordinator = nil;
......@@ -2166,13 +2166,12 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Create child coordinators.
_activityServiceCoordinator = [[ActivityServiceLegacyCoordinator alloc]
initWithBaseViewController:self];
_activityServiceCoordinator.dispatcher = self.commandDispatcher;
_activityServiceCoordinator.tabModel = self.tabModel;
_activityServiceCoordinator.browserState = self.browserState;
initWithBaseViewController:self
browser:self.browser];
_activityServiceCoordinator.positionProvider =
[self.primaryToolbarCoordinator activityServicePositioner];
_activityServiceCoordinator.presentationProvider = self;
[_activityServiceCoordinator start];
// TODO(crbug.com/1024288): Remove these lines along the legacy code removal.
if (!IsDownloadInfobarMessagesUIEnabled()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment