Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" | 5 #include "chrome/browser/password_manager/password_manager_delegate_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_number_conversions.h" | |
|
vabr (Chromium)
2013/09/12 13:40:02
No longer needed?
jdomingos
2013/09/12 16:33:52
Done.
| |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/perftimer.h" | |
| 10 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/password_manager/password_form_manager.h" | 14 #include "chrome/browser/password_manager/password_form_manager.h" |
| 13 #include "chrome/browser/password_manager/password_manager.h" | 15 #include "chrome/browser/password_manager/password_manager.h" |
| 16 #include "chrome/browser/password_manager/password_manager_metrics_util.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 18 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 16 #include "components/autofill/content/browser/autofill_driver_impl.h" | 19 #include "components/autofill/content/browser/autofill_driver_impl.h" |
| 17 #include "components/autofill/core/browser/autofill_manager.h" | 20 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/common/autofill_messages.h" | 21 #include "components/autofill/core/common/autofill_messages.h" |
| 19 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
| 20 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/ssl_status.h" | 26 #include "content/public/common/ssl_status.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 46 PasswordFormManager* form_to_save); | 49 PasswordFormManager* form_to_save); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 enum ResponseType { | 52 enum ResponseType { |
| 50 NO_RESPONSE = 0, | 53 NO_RESPONSE = 0, |
| 51 REMEMBER_PASSWORD, | 54 REMEMBER_PASSWORD, |
| 52 DONT_REMEMBER_PASSWORD, | 55 DONT_REMEMBER_PASSWORD, |
| 53 NUM_RESPONSE_TYPES, | 56 NUM_RESPONSE_TYPES, |
| 54 }; | 57 }; |
| 55 | 58 |
| 59 enum SavePasswordPromptDisplayedEnum { | |
| 60 SAVE_PASSWORD_PROMPT_DISPLAYED, | |
| 61 BOUNDARY_VALUE, | |
|
vabr (Chromium)
2013/09/12 13:40:02
I wonder what are the naming conventions. Should t
| |
| 62 }; | |
| 63 | |
| 56 SavePasswordInfoBarDelegate(InfoBarService* infobar_service, | 64 SavePasswordInfoBarDelegate(InfoBarService* infobar_service, |
| 57 PasswordFormManager* form_to_save); | 65 PasswordFormManager* form_to_save); |
| 58 virtual ~SavePasswordInfoBarDelegate(); | 66 virtual ~SavePasswordInfoBarDelegate(); |
| 59 | 67 |
| 60 // ConfirmInfoBarDelegate | 68 // ConfirmInfoBarDelegate |
| 61 virtual int GetIconID() const OVERRIDE; | 69 virtual int GetIconID() const OVERRIDE; |
| 62 virtual Type GetInfoBarType() const OVERRIDE; | 70 virtual Type GetInfoBarType() const OVERRIDE; |
| 63 virtual string16 GetMessageText() const OVERRIDE; | 71 virtual string16 GetMessageText() const OVERRIDE; |
| 64 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 72 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 65 virtual bool Accept() OVERRIDE; | 73 virtual bool Accept() OVERRIDE; |
| 66 virtual bool Cancel() OVERRIDE; | 74 virtual bool Cancel() OVERRIDE; |
| 67 | 75 |
| 68 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; | 76 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; |
| 69 | 77 |
| 70 // The PasswordFormManager managing the form we're asking the user about, | 78 // The PasswordFormManager managing the form we're asking the user about, |
| 71 // and should update as per her decision. | 79 // and should update as per her decision. |
| 72 scoped_ptr<PasswordFormManager> form_to_save_; | 80 scoped_ptr<PasswordFormManager> form_to_save_; |
| 73 | 81 |
| 74 // Used to track the results we get from the info bar. | 82 // Used to track the results we get from the info bar. |
| 75 ResponseType infobar_response_; | 83 ResponseType infobar_response_; |
| 76 | 84 |
| 85 // Save password prompt lifetime needed for a UMA signal. | |
| 86 PerfTimer timer_; | |
| 87 | |
| 88 // The group name corresponding to the domain name of |form_to_save_| if the | |
| 89 // form is on a monitored domain. Otherwise, an empty string. | |
| 90 const std::string uma_histogram_suffix_; | |
| 91 | |
| 77 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); | 92 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); |
| 78 }; | 93 }; |
| 79 | 94 |
| 80 // static | 95 // static |
| 81 void SavePasswordInfoBarDelegate::Create(content::WebContents* web_contents, | 96 void SavePasswordInfoBarDelegate::Create(content::WebContents* web_contents, |
| 82 PasswordFormManager* form_to_save) { | 97 PasswordFormManager* form_to_save) { |
| 83 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 98 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 84 // Don't show the password manager infobar if this form is for a google | 99 // Don't show the password manager infobar if this form is for a google |
| 85 // account and we are going to show the one-click signin infobar. | 100 // account and we are going to show the one-click signin infobar. |
| 86 GURL realm(form_to_save->realm()); | 101 GURL realm(form_to_save->realm()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 98 InfoBarService::FromWebContents(web_contents); | 113 InfoBarService::FromWebContents(web_contents); |
| 99 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 114 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 100 new SavePasswordInfoBarDelegate(infobar_service, form_to_save))); | 115 new SavePasswordInfoBarDelegate(infobar_service, form_to_save))); |
| 101 } | 116 } |
| 102 | 117 |
| 103 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 118 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
| 104 InfoBarService* infobar_service, | 119 InfoBarService* infobar_service, |
| 105 PasswordFormManager* form_to_save) | 120 PasswordFormManager* form_to_save) |
| 106 : ConfirmInfoBarDelegate(infobar_service), | 121 : ConfirmInfoBarDelegate(infobar_service), |
| 107 form_to_save_(form_to_save), | 122 form_to_save_(form_to_save), |
| 108 infobar_response_(NO_RESPONSE) { | 123 infobar_response_(NO_RESPONSE), |
| 124 uma_histogram_suffix_(password_manager_metrics_util::GroupIdToString( | |
| 125 password_manager_metrics_util::MonitoredDomainGroupId( | |
| 126 form_to_save->realm()))) { | |
| 127 if (!uma_histogram_suffix_.empty()) { | |
| 128 password_manager_metrics_util::LogUMAHistogramEnumeration( | |
| 129 "PasswordManager.SavePasswordPromptDisplayed" + uma_histogram_suffix_, | |
| 130 SAVE_PASSWORD_PROMPT_DISPLAYED, | |
| 131 BOUNDARY_VALUE); | |
| 132 } | |
| 109 } | 133 } |
| 110 | 134 |
| 111 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { | 135 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
| 112 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", | 136 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
| 113 infobar_response_, NUM_RESPONSE_TYPES); | 137 infobar_response_, NUM_RESPONSE_TYPES); |
| 138 | |
| 139 // The shortest period (in ms) for which the prompt needs to | |
| 140 // live, so that we don't consider it killed prematurely, as might | |
| 141 // happen, e.g., if a pre-rendered page gets swapped in (and the | |
| 142 // current WebContents is destroyed). | |
| 143 const base::TimeDelta kMinimumPromptDisplayTimeMs = | |
|
vabr (Chromium)
2013/09/12 13:40:02
Now that this is a TimeDelta, you don't need the "
jdomingos
2013/09/12 16:33:52
Done.
| |
| 144 base::TimeDelta::FromInternalValue(1000); | |
| 145 | |
| 146 if (!uma_histogram_suffix_.empty()) { | |
| 147 password_manager_metrics_util::LogUMAHistogramEnumeration( | |
| 148 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, | |
| 149 infobar_response_, NUM_RESPONSE_TYPES); | |
| 150 password_manager_metrics_util::LogUMAHistogramBoolean( | |
| 151 "PasswordManager.SavePasswordPromptDisappearedQuickly" + | |
| 152 uma_histogram_suffix_, | |
| 153 timer_.Elapsed() < kMinimumPromptDisplayTimeMs); | |
| 154 } | |
| 114 } | 155 } |
| 115 | 156 |
| 116 int SavePasswordInfoBarDelegate::GetIconID() const { | 157 int SavePasswordInfoBarDelegate::GetIconID() const { |
| 117 return IDR_INFOBAR_SAVE_PASSWORD; | 158 return IDR_INFOBAR_SAVE_PASSWORD; |
| 118 } | 159 } |
| 119 | 160 |
| 120 InfoBarDelegate::Type SavePasswordInfoBarDelegate::GetInfoBarType() const { | 161 InfoBarDelegate::Type SavePasswordInfoBarDelegate::GetInfoBarType() const { |
| 121 return PAGE_ACTION_TYPE; | 162 return PAGE_ACTION_TYPE; |
| 122 } | 163 } |
| 123 | 164 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { | 224 bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { |
| 184 content::NavigationEntry* entry = | 225 content::NavigationEntry* entry = |
| 185 web_contents_->GetController().GetActiveEntry(); | 226 web_contents_->GetController().GetActiveEntry(); |
| 186 if (!entry) { | 227 if (!entry) { |
| 187 NOTREACHED(); | 228 NOTREACHED(); |
| 188 return false; | 229 return false; |
| 189 } | 230 } |
| 190 | 231 |
| 191 return net::IsCertStatusError(entry->GetSSL().cert_status); | 232 return net::IsCertStatusError(entry->GetSSL().cert_status); |
| 192 } | 233 } |
| OLD | NEW |