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") { ...@@ -66,6 +66,7 @@ source_set("coordinator") {
"//base", "//base",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/activity_services/requirements", "//ios/chrome/browser/ui/activity_services/requirements",
......
...@@ -9,28 +9,25 @@ ...@@ -9,28 +9,25 @@
@protocol ActivityServicePositioner; @protocol ActivityServicePositioner;
@protocol ActivityServicePresentation; @protocol ActivityServicePresentation;
class ChromeBrowserState;
@class CommandDispatcher;
@class TabModel;
// ActivityServiceLegacyCoordinator provides a public interface for the share // ActivityServiceLegacyCoordinator provides a public interface for the share
// menu feature. // menu feature.
@interface ActivityServiceLegacyCoordinator : ChromeCoordinator @interface ActivityServiceLegacyCoordinator : ChromeCoordinator
// Models.
@property(nonatomic, readwrite, assign) ChromeBrowserState* browserState;
@property(nonatomic, readwrite, weak) CommandDispatcher* dispatcher;
@property(nonatomic, readwrite, weak) TabModel* tabModel;
// Providers. // Providers.
@property(nonatomic, readwrite, weak) id<ActivityServicePositioner> @property(nonatomic, readwrite, weak) id<ActivityServicePositioner>
positionProvider; positionProvider;
@property(nonatomic, readwrite, weak) id<ActivityServicePresentation> @property(nonatomic, readwrite, weak) id<ActivityServicePresentation>
presentationProvider; presentationProvider;
// Removes references to any weak objects that this coordinator holds pointers // Unavailable, use -initWithBaseViewController:browser:.
// to. - (instancetype)initWithBaseViewController:(UIViewController*)viewController
- (void)disconnect; 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. // Cancels any in-progress share activities and dismisses the corresponding UI.
- (void)cancelShare; - (void)cancelShare;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.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/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/activity_service_controller.h"
#import "ios/chrome/browser/ui/activity_services/canonical_url_retriever.h" #import "ios/chrome/browser/ui/activity_services/canonical_url_retriever.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_password.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_password.h"
...@@ -44,10 +44,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -44,10 +44,6 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
@implementation ActivityServiceLegacyCoordinator @implementation ActivityServiceLegacyCoordinator
@synthesize browserState = _browserState;
@synthesize dispatcher = _dispatcher;
@synthesize tabModel = _tabModel;
@synthesize positionProvider = _positionProvider; @synthesize positionProvider = _positionProvider;
@synthesize presentationProvider = _presentationProvider; @synthesize presentationProvider = _presentationProvider;
...@@ -55,9 +51,14 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -55,9 +51,14 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
#pragma mark - Public methods #pragma mark - Public methods
- (void)disconnect { - (void)start {
self.browserState = nil; [self.browser->GetCommandDispatcher()
self.dispatcher = nil; startDispatchingToTarget:self
forSelector:@selector(sharePage)];
}
- (void)stop {
[self.browser->GetCommandDispatcher() stopDispatchingToTarget:self];
} }
- (void)cancelShare { - (void)cancelShare {
...@@ -65,28 +66,13 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -65,28 +66,13 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
[controller cancelShareAnimated:NO]; [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 #pragma mark - Command handlers
- (void)sharePage { - (void)sharePage {
self.sharePageStartTime = base::TimeTicks::Now(); self.sharePageStartTime = base::TimeTicks::Now();
__weak ActivityServiceLegacyCoordinator* weakSelf = self; __weak ActivityServiceLegacyCoordinator* weakSelf = self;
activity_services::RetrieveCanonicalUrl( activity_services::RetrieveCanonicalUrl(
self.tabModel.webStateList->GetActiveWebState(), ^(const GURL& url) { self.browser->GetWebStateList()->GetActiveWebState(), ^(const GURL& url) {
[weakSelf sharePageWithCanonicalURL:url]; [weakSelf sharePageWithCanonicalURL:url];
}); });
} }
...@@ -94,7 +80,8 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -94,7 +80,8 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
#pragma mark - Providers #pragma mark - Providers
- (id<PasswordFormFiller>)currentPasswordFormFiller { - (id<PasswordFormFiller>)currentPasswordFormFiller {
web::WebState* webState = self.tabModel.webStateList->GetActiveWebState(); web::WebState* webState =
self.browser->GetWebStateList()->GetActiveWebState();
return webState ? PasswordTabHelper::FromWebState(webState) return webState ? PasswordTabHelper::FromWebState(webState)
->GetPasswordFormFiller() ->GetPasswordFormFiller()
: nil; : nil;
...@@ -104,7 +91,7 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -104,7 +91,7 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
- (void)sharePageWithCanonicalURL:(const GURL&)canonicalURL { - (void)sharePageWithCanonicalURL:(const GURL&)canonicalURL {
ShareToData* data = activity_services::ShareToDataForWebState( ShareToData* data = activity_services::ShareToDataForWebState(
self.tabModel.webStateList->GetActiveWebState(), canonicalURL); self.browser->GetWebStateList()->GetActiveWebState(), canonicalURL);
if (!data) if (!data)
return; return;
...@@ -118,10 +105,12 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency"; ...@@ -118,10 +105,12 @@ const char kSharePageLatencyHistogram[] = "IOS.SharePageLatency";
self.sharePageStartTime = base::TimeTicks(); self.sharePageStartTime = base::TimeTicks();
} }
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up.
[controller shareWithData:data [controller shareWithData:data
browserState:self.browserState browserState:self.browser->GetBrowserState()
dispatcher:static_cast<id<BrowserCommands, SnackbarCommands>>( dispatcher:static_cast<id<BrowserCommands, SnackbarCommands>>(
self.dispatcher) self.browser->GetCommandDispatcher())
passwordProvider:self passwordProvider:self
positionProvider:self.positionProvider positionProvider:self.positionProvider
presentationProvider:self.presentationProvider]; presentationProvider:self.presentationProvider];
......
...@@ -1371,7 +1371,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1371,7 +1371,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[self uninstallDelegatesForWebState:webStateList->GetWebStateAt(index)]; [self uninstallDelegatesForWebState:webStateList->GetWebStateAt(index)];
// Disconnect child coordinators. // Disconnect child coordinators.
[_activityServiceCoordinator disconnect]; [_activityServiceCoordinator stop];
[self.popupMenuCoordinator stop]; [self.popupMenuCoordinator stop];
[self.tabStripCoordinator stop]; [self.tabStripCoordinator stop];
self.tabStripCoordinator = nil; self.tabStripCoordinator = nil;
...@@ -2166,13 +2166,12 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2166,13 +2166,12 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Create child coordinators. // Create child coordinators.
_activityServiceCoordinator = [[ActivityServiceLegacyCoordinator alloc] _activityServiceCoordinator = [[ActivityServiceLegacyCoordinator alloc]
initWithBaseViewController:self]; initWithBaseViewController:self
_activityServiceCoordinator.dispatcher = self.commandDispatcher; browser:self.browser];
_activityServiceCoordinator.tabModel = self.tabModel;
_activityServiceCoordinator.browserState = self.browserState;
_activityServiceCoordinator.positionProvider = _activityServiceCoordinator.positionProvider =
[self.primaryToolbarCoordinator activityServicePositioner]; [self.primaryToolbarCoordinator activityServicePositioner];
_activityServiceCoordinator.presentationProvider = self; _activityServiceCoordinator.presentationProvider = self;
[_activityServiceCoordinator start];
// TODO(crbug.com/1024288): Remove these lines along the legacy code removal. // TODO(crbug.com/1024288): Remove these lines along the legacy code removal.
if (!IsDownloadInfobarMessagesUIEnabled()) { 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