Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model.cc

Issue 777423004: Skeleton code for experiment setup, which will determine should "Allow to collect URL?" bubble be s… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/ui/passwords/password_manager_url_collection_experiment .h"
12 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.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);
40 return;
41 Profile* profile =
42 Profile::FromBrowserContext(web_contents->GetBrowserContext());
43 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); 47 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason);
44 } 48 }
45 49
46 base::string16 PendingStateTitleBasedOnSavePasswordPref( 50 base::string16 PendingStateTitleBasedOnSavePasswordPref(
47 bool never_save_passwords) { 51 bool never_save_passwords) {
48 return l10n_util::GetStringUTF16( 52 return l10n_util::GetStringUTF16(
49 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE 53 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE
50 : IDS_SAVE_PASSWORD); 54 : IDS_SAVE_PASSWORD);
51 } 55 }
52 56
57 void RecordURLSCollectionExperimentStatistics(
58 content::WebContents* web_contents) {
59 Profile* profile = GetProfileFromWebContents(web_contents);
60 password_manager::urls_collection_experiment::RecordBubbleClosed(
61 profile->GetPrefs());
62 }
63
53 } // namespace 64 } // namespace
54 65
55 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( 66 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
56 content::WebContents* web_contents) 67 content::WebContents* web_contents)
57 : content::WebContentsObserver(web_contents), 68 : content::WebContentsObserver(web_contents),
58 never_save_passwords_(false), 69 never_save_passwords_(false),
59 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), 70 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING),
60 dismissal_reason_(metrics_util::NOT_DISPLAYED) { 71 dismissal_reason_(metrics_util::NOT_DISPLAYED) {
61 ManagePasswordsUIController* controller = 72 ManagePasswordsUIController* controller =
62 ManagePasswordsUIController::FromWebContents(web_contents); 73 ManagePasswordsUIController::FromWebContents(web_contents);
(...skipping 10 matching lines...) Expand all
73 if (password_manager::ui::IsPendingState(state_)) { 84 if (password_manager::ui::IsPendingState(state_)) {
74 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); 85 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_);
75 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { 86 } else if (state_ == password_manager::ui::BLACKLIST_STATE) {
76 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); 87 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE);
77 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { 88 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) {
78 title_ = 89 title_ =
79 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); 90 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE);
80 } else if (password_manager::ui::IsCredentialsState(state_)) { 91 } else if (password_manager::ui::IsCredentialsState(state_)) {
81 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); 92 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE);
82 } else if (password_manager::ui::IsAskSubmitURLState(state_)) { 93 } else if (password_manager::ui::IsAskSubmitURLState(state_)) {
94 RecordURLSCollectionExperimentStatistics(web_contents);
83 title_ = 95 title_ =
84 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE); 96 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE);
85 } else { 97 } else {
86 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); 98 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE);
87 } 99 }
88 100
89 base::string16 save_confirmation_link = 101 base::string16 save_confirmation_link =
90 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); 102 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK);
91 size_t offset; 103 size_t offset;
92 save_confirmation_text_ = 104 save_confirmation_text_ =
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) 166 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION)
155 RecordExperimentStatistics(web_contents(), dismissal_reason_); 167 RecordExperimentStatistics(web_contents(), dismissal_reason_);
156 } 168 }
157 169
158 void ManagePasswordsBubbleModel::OnCollectURLClicked() { 170 void ManagePasswordsBubbleModel::OnCollectURLClicked() {
159 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL; 171 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL;
160 RecordExperimentStatistics(web_contents(), dismissal_reason_); 172 RecordExperimentStatistics(web_contents(), dismissal_reason_);
161 // User interaction with bubble has happened, do not need to show bubble 173 // User interaction with bubble has happened, do not need to show bubble
162 // in case it was before transition to another page. 174 // in case it was before transition to another page.
163 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; 175 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE;
176 ManagePasswordsUIController* manage_passwords_ui_controller =
177 ManagePasswordsUIController::FromWebContents(web_contents());
178 manage_passwords_ui_controller->SendURLFeedback();
164 } 179 }
165 180
166 void ManagePasswordsBubbleModel::OnDoNotCollectURLClicked() { 181 void ManagePasswordsBubbleModel::OnDoNotCollectURLClicked() {
167 dismissal_reason_ = metrics_util::CLICKED_DO_NOT_COLLECT_URL; 182 dismissal_reason_ = metrics_util::CLICKED_DO_NOT_COLLECT_URL;
168 RecordExperimentStatistics(web_contents(), dismissal_reason_); 183 RecordExperimentStatistics(web_contents(), dismissal_reason_);
169 // User interaction with bubble has happened, do not need to show bubble 184 // User interaction with bubble has happened, do not need to show bubble
170 // in case it was before transition to another page. 185 // in case it was before transition to another page.
171 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; 186 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE;
172 } 187 }
173 188
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 274
260 // static 275 // static
261 int ManagePasswordsBubbleModel::UsernameFieldWidth() { 276 int ManagePasswordsBubbleModel::UsernameFieldWidth() {
262 return GetFieldWidth(USERNAME_FIELD); 277 return GetFieldWidth(USERNAME_FIELD);
263 } 278 }
264 279
265 // static 280 // static
266 int ManagePasswordsBubbleModel::PasswordFieldWidth() { 281 int ManagePasswordsBubbleModel::PasswordFieldWidth() {
267 return GetFieldWidth(PASSWORD_FIELD); 282 return GetFieldWidth(PASSWORD_FIELD);
268 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698