summaryrefslogtreecommitdiffstats
path: root/chrome/browser/password_manager
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 02:03:50 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-08 02:03:50 +0000
commit0be0993cca7083adc764540ed17ba7611c23aa5a (patch)
tree2c7337c84594d00957b6d961afa5ee62a12ff6c5 /chrome/browser/password_manager
parentd52f52f478d5aa0830cd2b621e464178d2fbaa1f (diff)
downloadchromium_src-0be0993cca7083adc764540ed17ba7611c23aa5a.zip
chromium_src-0be0993cca7083adc764540ed17ba7611c23aa5a.tar.gz
chromium_src-0be0993cca7083adc764540ed17ba7611c23aa5a.tar.bz2
Change infobar creation to use a public static Create() method on the infobar delegate classes. Make constructors as private as possible.
This has several purposes: * By preventing direct instantiation, it prevents callers from leaking if they create an infobar and don't add it to an InfoBarService. * By moving decision-making about when to show infobars into these Create() functions, there's a pattern for where such code should go, and caller code becomes simpler and easier to read. * The two bullets above together mean that for infobars which should only be displayed in certain circumstances, code can't accidentally bypass the decision logic. * It enables us to eliminate a common InfoBarService* temp on the caller side since the caller no longer needs to both pass the pointer to the infobar _and_ call AddInfoBar() on the pointer. This was also a somewhat redundant-looking pattern. * It makes it easier to change the ownership model for infobars in the future by limiting the affected callsites to only the Create() functions. Note that right now, this still feels pretty redundant since we pass all the same args to Create() functions as constructors most times. In the new ownership model constructors will no longer need to take InfoBarService*s, which will make this better. Additionally, this makes AddInfoBar()/ReplaceInfoBar() take scoped_ptr<>s to indicate they're receiving ownership. This sort of change is easy to make since we only need change the create functions. This change also has a functional effect: it eliminates some cases where we tried to only show infobars when no other infobars were already showing (discussed and approved by Glen). BUG=none TEST=none Review URL: https://codereview.chromium.org/11644059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175467 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager')
-rw-r--r--chrome/browser/password_manager/password_manager_delegate_impl.cc55
1 files changed, 33 insertions, 22 deletions
diff --git a/chrome/browser/password_manager/password_manager_delegate_impl.cc b/chrome/browser/password_manager/password_manager_delegate_impl.cc
index 029879d..fc9c55e 100644
--- a/chrome/browser/password_manager/password_manager_delegate_impl.cc
+++ b/chrome/browser/password_manager/password_manager_delegate_impl.cc
@@ -38,8 +38,10 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(PasswordManagerDelegateImpl);
// forms never end up in an infobar.
class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- SavePasswordInfoBarDelegate(InfoBarService* infobar_service,
- PasswordFormManager* form_to_save);
+ // If we won't be showing the one-click signin infobar, creates a save
+ // password delegate and adds it to the InfoBarService for |web_contents|.
+ static void Create(content::WebContents* web_contents,
+ PasswordFormManager* form_to_save);
private:
enum ResponseType {
@@ -49,6 +51,8 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
NUM_RESPONSE_TYPES,
};
+ SavePasswordInfoBarDelegate(InfoBarService* infobar_service,
+ PasswordFormManager* form_to_save);
virtual ~SavePasswordInfoBarDelegate();
// ConfirmInfoBarDelegate
@@ -71,6 +75,32 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
};
+// static
+void SavePasswordInfoBarDelegate::Create(content::WebContents* web_contents,
+ PasswordFormManager* form_to_save) {
+#if defined(ENABLE_ONE_CLICK_SIGNIN)
+ // Don't show the password manager infobar if this form is for a google
+ // account and we are going to show the one-click singin infobar.
+ // For now, one-click signin is fully implemented only on windows.
+ GURL realm(form_to_save->realm());
+ // TODO(mathp): Checking only against associated_username() causes a bug
+ // referenced here: crbug.com/133275
+ if ((realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm()) ||
+ realm == GURL("https://www.google.com/")) &&
+ OneClickSigninHelper::CanOffer(
+ web_contents,
+ OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
+ UTF16ToUTF8(form_to_save->associated_username()), NULL)) {
+ return;
+ }
+#endif
+
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(web_contents);
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new SavePasswordInfoBarDelegate(infobar_service, form_to_save)));
+}
+
SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
InfoBarService* infobar_service,
PasswordFormManager* form_to_save)
@@ -147,26 +177,7 @@ void PasswordManagerDelegateImpl::FillPasswordForm(
void PasswordManagerDelegateImpl::AddSavePasswordInfoBarIfPermitted(
PasswordFormManager* form_to_save) {
- // Don't show the password manager infobar if this form is for a google
- // account and we are going to show the one-click singin infobar.
- // For now, one-click signin is fully implemented only on windows.
-#if defined(ENABLE_ONE_CLICK_SIGNIN)
- GURL realm(form_to_save->realm());
- // TODO(mathp): Checking only against associated_username() causes a bug
- // referenced here: crbug.com/133275
- if ((realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm()) ||
- realm == GURL("https://www.google.com/")) &&
- OneClickSigninHelper::CanOffer(web_contents_,
- OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY,
- UTF16ToUTF8(form_to_save->associated_username()), NULL)) {
- return;
- }
-#endif
-
- InfoBarService* infobar_service =
- InfoBarService::FromWebContents(web_contents_);
- infobar_service->AddInfoBar(
- new SavePasswordInfoBarDelegate(infobar_service, form_to_save));
+ SavePasswordInfoBarDelegate::Create(web_contents_, form_to_save);
}
Profile* PasswordManagerDelegateImpl::GetProfile() {