Commit 29e7df00 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Deletes Create() static method for SavePasswordInfobarDelegate

This is being done for three reasons mainly:
- The delegate shouldn't be responsibly of manipulating the InfobarManager
and creating the Infobars its being a delegate of.
- This prevents dependency cycles since now InfobarCoordinator can include
IOSChromeSavePasswordInfoBarDelegate.
- While trying to test IOSChromeSavePasswordInfoBarDelegate having its
default constructor private was making everything more complicated since there
was more setup needed.

Bug: 945478
Change-Id: I223d6ada2b939d9037bf030728a588051e28c115
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585379
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654500}
parent d78c025d
......@@ -17,8 +17,6 @@ source_set("passwords") {
"ios_chrome_password_manager_driver.mm",
"ios_chrome_password_store_factory.cc",
"ios_chrome_password_store_factory.h",
"ios_chrome_save_password_infobar_delegate.h",
"ios_chrome_save_password_infobar_delegate.mm",
"ios_chrome_update_password_infobar_delegate.h",
"ios_chrome_update_password_infobar_delegate.mm",
"ios_password_infobar_controller.h",
......@@ -42,7 +40,7 @@ source_set("passwords") {
"update_password_infobar_controller.mm",
]
deps = [
":public",
":infobar_delegates",
"//base",
"//base:i18n",
"//components/autofill/core/browser",
......@@ -101,18 +99,22 @@ source_set("passwords") {
allow_circular_includes_from = [ ":passwords_generation_utils" ]
}
source_set("public") {
source_set("infobar_delegates") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"ios_chrome_password_manager_infobar_delegate.h",
"ios_chrome_password_manager_infobar_delegate.mm",
"ios_chrome_save_password_infobar_delegate.h",
"ios_chrome_save_password_infobar_delegate.mm",
]
deps = [
"//base",
"//components/infobars/core",
"//components/password_manager/core/browser",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/app/theme",
"//ios/chrome/browser/ui/infobars:feature_flags",
"//ui/base",
]
}
......
......@@ -43,6 +43,9 @@ class IOSChromePasswordManagerInfoBarDelegate : public ConfirmInfoBarDelegate {
// The title for the InfobarModal being presented.
virtual NSString* GetInfobarModalTitleText() const;
// Sets the dispatcher for this delegate.
void set_dispatcher(id<ApplicationCommands> dispatcher);
protected:
IOSChromePasswordManagerInfoBarDelegate(
bool is_sync_user,
......@@ -63,10 +66,6 @@ class IOSChromePasswordManagerInfoBarDelegate : public ConfirmInfoBarDelegate {
return infobar_response_;
}
void set_dispatcher(id<ApplicationCommands> dispatcher) {
dispatcher_ = dispatcher;
}
private:
// ConfirmInfoBarDelegate implementation.
int GetIconId() const override;
......
......@@ -66,6 +66,11 @@ NSString* IOSChromePasswordManagerInfoBarDelegate::GetInfobarModalTitleText()
return @"";
}
void IOSChromePasswordManagerInfoBarDelegate::set_dispatcher(
id<ApplicationCommands> dispatcher) {
dispatcher_ = dispatcher;
}
int IOSChromePasswordManagerInfoBarDelegate::GetIconId() const {
return IDR_IOS_INFOBAR_SAVE_PASSWORD;
}
......@@ -16,10 +16,6 @@ namespace password_manager {
class PasswordFormManagerForUI;
}
namespace infobars {
class InfoBarManager;
}
// After a successful *new* login attempt, Chrome passes the current
// password_manager::PasswordFormManager and move it to a
// IOSChromeSavePasswordInfoBarDelegate while the user makes up their mind
......@@ -27,23 +23,15 @@ class InfoBarManager;
class IOSChromeSavePasswordInfoBarDelegate
: public IOSChromePasswordManagerInfoBarDelegate {
public:
// Creates the infobar for |form_to_save| and adds it to |infobar_manager|.
// |is_sync_user| controls the footer string. |dispatcher| is not retained.
static void Create(
IOSChromeSavePasswordInfoBarDelegate(
bool is_sync_user,
infobars::InfoBarManager* infobar_manager,
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
id<ApplicationCommands> dispatcher);
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save);
~IOSChromeSavePasswordInfoBarDelegate() override;
bool ShouldExpire(const NavigationDetails& details) const override;
private:
IOSChromeSavePasswordInfoBarDelegate(
bool is_sync_user,
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save);
// ConfirmInfoBarDelegate implementation.
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
base::string16 GetMessageText() const override;
......
......@@ -13,9 +13,6 @@
#include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/infobars/infobar.h"
#import "ios/chrome/browser/passwords/ios_password_infobar_controller.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -27,38 +24,6 @@
using password_manager::PasswordFormManagerForUI;
// static
void IOSChromeSavePasswordInfoBarDelegate::Create(
bool is_sync_user,
infobars::InfoBarManager* infobar_manager,
std::unique_ptr<PasswordFormManagerForUI> form_to_save,
id<ApplicationCommands> dispatcher) {
DCHECK(infobar_manager);
auto delegate = base::WrapUnique(new IOSChromeSavePasswordInfoBarDelegate(
is_sync_user, std::move(form_to_save)));
delegate->set_dispatcher(dispatcher);
if (IsInfobarUIRebootEnabled()) {
InfobarPasswordCoordinator* coordinator =
[[InfobarPasswordCoordinator alloc]
initWithInfoBarDelegate:delegate.get()];
infobar_manager->AddInfoBar(
std::make_unique<InfoBarIOS>(coordinator, std::move(delegate)));
} else {
IOSPasswordInfoBarController* controller =
[[IOSPasswordInfoBarController alloc]
initWithInfoBarDelegate:delegate.get()];
infobar_manager->AddInfoBar(
std::make_unique<InfoBarIOS>(controller, std::move(delegate)));
}
}
IOSChromeSavePasswordInfoBarDelegate::~IOSChromeSavePasswordInfoBarDelegate() {
password_manager::metrics_util::LogSaveUIDismissalReason(infobar_response());
form_to_save()->GetMetricsRecorder()->RecordUIDismissalReason(
infobar_response());
}
IOSChromeSavePasswordInfoBarDelegate::IOSChromeSavePasswordInfoBarDelegate(
bool is_sync_user,
std::unique_ptr<PasswordFormManagerForUI> form_manager)
......@@ -69,6 +34,12 @@ IOSChromeSavePasswordInfoBarDelegate::IOSChromeSavePasswordInfoBarDelegate(
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING);
}
IOSChromeSavePasswordInfoBarDelegate::~IOSChromeSavePasswordInfoBarDelegate() {
password_manager::metrics_util::LogSaveUIDismissalReason(infobar_response());
form_to_save()->GetMetricsRecorder()->RecordUIDismissalReason(
infobar_response());
}
infobars::InfoBarDelegate::InfoBarIdentifier
IOSChromeSavePasswordInfoBarDelegate::GetIdentifier() const {
return SAVE_PASSWORD_INFOBAR_DELEGATE_MOBILE;
......
......@@ -42,17 +42,21 @@
#include "components/strings/grit/components_strings.h"
#include "components/sync/driver/sync_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/infobars/infobar.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/metrics/ukm_url_recorder.h"
#include "ios/chrome/browser/passwords/credential_manager.h"
#import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h"
#import "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h"
#import "ios/chrome/browser/passwords/ios_password_infobar_controller.h"
#import "ios/chrome/browser/passwords/notify_auto_signin_view_controller.h"
#import "ios/chrome/browser/passwords/password_form_filler.h"
#include "ios/chrome/browser/passwords/password_manager_features.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/browser/web/tab_id_tab_helper.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -674,11 +678,26 @@ void LogSuggestionShown(PasswordSuggestionType type) {
InfoBarManagerImpl::FromWebState(_webState);
switch (type) {
case PasswordInfoBarType::SAVE:
IOSChromeSavePasswordInfoBarDelegate::Create(
isSyncUser, infoBarManager, std::move(form), self.dispatcher);
case PasswordInfoBarType::SAVE: {
auto delegate = std::make_unique<IOSChromeSavePasswordInfoBarDelegate>(
isSyncUser, std::move(form));
delegate->set_dispatcher(self.dispatcher);
if (IsInfobarUIRebootEnabled()) {
InfobarPasswordCoordinator* coordinator =
[[InfobarPasswordCoordinator alloc]
initWithInfoBarDelegate:delegate.get()];
infoBarManager->AddInfoBar(
std::make_unique<InfoBarIOS>(coordinator, std::move(delegate)));
} else {
IOSPasswordInfoBarController* controller =
[[IOSPasswordInfoBarController alloc]
initWithInfoBarDelegate:delegate.get()];
infoBarManager->AddInfoBar(
std::make_unique<InfoBarIOS>(controller, std::move(delegate)));
}
break;
}
case PasswordInfoBarType::UPDATE:
IOSChromeUpdatePasswordInfoBarDelegate::Create(
isSyncUser, infoBarManager, std::move(form), self.baseViewController,
......
......@@ -17,7 +17,7 @@ source_set("coordinators") {
"//base",
"//components/infobars/core",
"//ios/chrome/browser/infobars:public",
"//ios/chrome/browser/passwords:public",
"//ios/chrome/browser/passwords:infobar_delegates",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/fullscreen",
......
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