OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/passwords/manage_passwords_bubble_model.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
6 | 6 |
7 #include "chrome/browser/password_manager/password_store_factory.h" | 7 #include "chrome/browser/password_manager/password_store_factory.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
11 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | 11 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
13 #include "components/password_manager/core/browser/password_manager_url_collecti on_experiment.h" | |
13 #include "components/password_manager/core/browser/password_store.h" | 14 #include "components/password_manager/core/browser/password_store.h" |
14 #include "components/password_manager/core/common/password_manager_ui.h" | 15 #include "components/password_manager/core/common/password_manager_ui.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 | 18 |
18 using autofill::PasswordFormMap; | 19 using autofill::PasswordFormMap; |
19 using content::WebContents; | 20 using content::WebContents; |
20 namespace metrics_util = password_manager::metrics_util; | 21 namespace metrics_util = password_manager::metrics_util; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; | 25 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; |
25 | 26 |
26 const int kUsernameFieldSize = 30; | 27 const int kUsernameFieldSize = 30; |
27 const int kPasswordFieldSize = 22; | 28 const int kPasswordFieldSize = 22; |
28 | 29 |
29 // Returns the width of |type| field. | 30 // Returns the width of |type| field. |
30 int GetFieldWidth(FieldType type) { | 31 int GetFieldWidth(FieldType type) { |
31 return ui::ResourceBundle::GetSharedInstance() | 32 return ui::ResourceBundle::GetSharedInstance() |
32 .GetFontList(ui::ResourceBundle::SmallFont) | 33 .GetFontList(ui::ResourceBundle::SmallFont) |
33 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize | 34 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize |
34 : kPasswordFieldSize); | 35 : kPasswordFieldSize); |
35 } | 36 } |
36 | 37 |
38 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { | |
39 if (!web_contents) | |
40 return nullptr; | |
41 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
42 } | |
43 | |
37 void RecordExperimentStatistics(content::WebContents* web_contents, | 44 void RecordExperimentStatistics(content::WebContents* web_contents, |
38 metrics_util::UIDismissalReason reason) { | 45 metrics_util::UIDismissalReason reason) { |
39 if (!web_contents) | 46 Profile* profile = GetProfileFromWebContents(web_contents); |
47 if (!profile) | |
40 return; | 48 return; |
41 Profile* profile = | |
42 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
43 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); | 49 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); |
44 } | 50 } |
45 | 51 |
46 base::string16 PendingStateTitleBasedOnSavePasswordPref( | 52 base::string16 PendingStateTitleBasedOnSavePasswordPref( |
47 bool never_save_passwords) { | 53 bool never_save_passwords) { |
48 return l10n_util::GetStringUTF16( | 54 return l10n_util::GetStringUTF16( |
49 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE | 55 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE |
50 : IDS_SAVE_PASSWORD); | 56 : IDS_SAVE_PASSWORD); |
51 } | 57 } |
52 | 58 |
59 void RecordURLSCollectionExperimentStatistics( | |
battre
2014/12/09 11:02:16
nit: RecordURLsCollectionExperimentStatistics
| |
60 content::WebContents* web_contents) { | |
battre
2014/12/09 11:02:16
Does this fit into one line?
melandory
2014/12/09 23:52:35
67 symbols
| |
61 Profile* profile = GetProfileFromWebContents(web_contents); | |
62 if (!profile) | |
63 return; | |
64 password_manager::urls_collection_experiment::RecordBubbleClosed( | |
65 profile->GetPrefs()); | |
66 } | |
67 | |
53 } // namespace | 68 } // namespace |
54 | 69 |
55 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 70 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
56 content::WebContents* web_contents) | 71 content::WebContents* web_contents) |
57 : content::WebContentsObserver(web_contents), | 72 : content::WebContentsObserver(web_contents), |
58 never_save_passwords_(false), | 73 never_save_passwords_(false), |
59 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 74 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
60 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 75 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
61 ManagePasswordsUIController* controller = | 76 ManagePasswordsUIController* controller = |
62 ManagePasswordsUIController::FromWebContents(web_contents); | 77 ManagePasswordsUIController::FromWebContents(web_contents); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 ManagePasswordsUIController::FromWebContents(web_contents()); | 156 ManagePasswordsUIController::FromWebContents(web_contents()); |
142 manage_passwords_ui_controller->ChooseCredential(false, | 157 manage_passwords_ui_controller->ChooseCredential(false, |
143 autofill::PasswordForm()); | 158 autofill::PasswordForm()); |
144 state_ = password_manager::ui::INACTIVE_STATE; | 159 state_ = password_manager::ui::INACTIVE_STATE; |
145 } | 160 } |
146 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 161 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
147 return; | 162 return; |
148 | 163 |
149 if (password_manager::ui::IsAskSubmitURLState(state_)) { | 164 if (password_manager::ui::IsAskSubmitURLState(state_)) { |
150 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; | 165 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; |
166 RecordURLSCollectionExperimentStatistics(web_contents()); | |
151 } | 167 } |
152 metrics_util::LogUIDismissalReason(dismissal_reason_); | 168 metrics_util::LogUIDismissalReason(dismissal_reason_); |
153 // Other use cases have been reported in the callbacks like OnSaveClicked(). | 169 // Other use cases have been reported in the callbacks like OnSaveClicked(). |
154 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) | 170 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) |
155 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 171 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
156 } | 172 } |
157 | 173 |
158 void ManagePasswordsBubbleModel::OnCollectURLClicked() { | 174 void ManagePasswordsBubbleModel::OnCollectURLClicked() { |
159 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL; | 175 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL; |
160 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 176 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 275 |
260 // static | 276 // static |
261 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 277 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
262 return GetFieldWidth(USERNAME_FIELD); | 278 return GetFieldWidth(USERNAME_FIELD); |
263 } | 279 } |
264 | 280 |
265 // static | 281 // static |
266 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 282 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
267 return GetFieldWidth(PASSWORD_FIELD); | 283 return GetFieldWidth(PASSWORD_FIELD); |
268 } | 284 } |
OLD | NEW |