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