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