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

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
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | components/password_manager/core/browser/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "components/feedback/feedback_data.h" 13 #include "components/feedback/feedback_data.h"
14 #include "components/feedback/feedback_util.h" 14 #include "components/feedback/feedback_util.h"
15 #include "components/password_manager/core/browser/password_manager_url_collecti on_experiment.h"
15 #include "components/password_manager/core/browser/password_store.h" 16 #include "components/password_manager/core/browser/password_store.h"
16 #include "components/password_manager/core/common/password_manager_ui.h" 17 #include "components/password_manager/core/common/password_manager_ui.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 21
21 using autofill::PasswordFormMap; 22 using autofill::PasswordFormMap;
22 using feedback::FeedbackData; 23 using feedback::FeedbackData;
23 using content::WebContents; 24 using content::WebContents;
24 namespace metrics_util = password_manager::metrics_util; 25 namespace metrics_util = password_manager::metrics_util;
25 26
26 namespace { 27 namespace {
27 28
28 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; 29 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD };
29 30
30 const int kUsernameFieldSize = 30; 31 const int kUsernameFieldSize = 30;
31 const int kPasswordFieldSize = 22; 32 const int kPasswordFieldSize = 22;
32 33
33 // Returns the width of |type| field. 34 // Returns the width of |type| field.
34 int GetFieldWidth(FieldType type) { 35 int GetFieldWidth(FieldType type) {
35 return ui::ResourceBundle::GetSharedInstance() 36 return ui::ResourceBundle::GetSharedInstance()
36 .GetFontList(ui::ResourceBundle::SmallFont) 37 .GetFontList(ui::ResourceBundle::SmallFont)
37 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize 38 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize
38 : kPasswordFieldSize); 39 : kPasswordFieldSize);
39 } 40 }
40 41
42 Profile* GetProfileFromWebContents(content::WebContents* web_contents) {
43 if (!web_contents)
44 return nullptr;
45 return Profile::FromBrowserContext(web_contents->GetBrowserContext());
46 }
47
41 void RecordExperimentStatistics(content::WebContents* web_contents, 48 void RecordExperimentStatistics(content::WebContents* web_contents,
42 metrics_util::UIDismissalReason reason) { 49 metrics_util::UIDismissalReason reason) {
43 if (!web_contents) 50 Profile* profile = GetProfileFromWebContents(web_contents);
51 if (!profile)
44 return; 52 return;
45 Profile* profile =
46 Profile::FromBrowserContext(web_contents->GetBrowserContext());
47 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); 53 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason);
48 } 54 }
49 55
50 base::string16 PendingStateTitleBasedOnSavePasswordPref( 56 base::string16 PendingStateTitleBasedOnSavePasswordPref(
51 bool never_save_passwords) { 57 bool never_save_passwords) {
52 return l10n_util::GetStringUTF16( 58 return l10n_util::GetStringUTF16(
53 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE 59 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE
54 : IDS_SAVE_PASSWORD); 60 : IDS_SAVE_PASSWORD);
55 } 61 }
56 62
(...skipping 27 matching lines...) Expand all
84 feedback_data->set_description(""); 90 feedback_data->set_description("");
85 91
86 feedback_data->set_image(make_scoped_ptr(new std::string)); 92 feedback_data->set_image(make_scoped_ptr(new std::string));
87 93
88 feedback_data->set_page_url(url_); 94 feedback_data->set_page_url(url_);
89 feedback_data->set_user_email(""); 95 feedback_data->set_user_email("");
90 feedback_data->set_context(context_); 96 feedback_data->set_context(context_);
91 feedback_util::SendReport(feedback_data); 97 feedback_util::SendReport(feedback_data);
92 } 98 }
93 99
100 void RecordURLsCollectionExperimentStatistics(
101 content::WebContents* web_contents) {
102 Profile* profile = GetProfileFromWebContents(web_contents);
103 if (!profile)
104 return;
105 password_manager::urls_collection_experiment::RecordBubbleClosed(
106 profile->GetPrefs());
107 }
108
94 } // namespace 109 } // namespace
95 110
96 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( 111 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
97 content::WebContents* web_contents) 112 content::WebContents* web_contents)
98 : content::WebContentsObserver(web_contents), 113 : content::WebContentsObserver(web_contents),
99 never_save_passwords_(false), 114 never_save_passwords_(false),
100 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), 115 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING),
101 dismissal_reason_(metrics_util::NOT_DISPLAYED) { 116 dismissal_reason_(metrics_util::NOT_DISPLAYED) {
102 ManagePasswordsUIController* controller = 117 ManagePasswordsUIController* controller =
103 ManagePasswordsUIController::FromWebContents(web_contents); 118 ManagePasswordsUIController::FromWebContents(web_contents);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ManagePasswordsUIController::FromWebContents(web_contents()); 197 ManagePasswordsUIController::FromWebContents(web_contents());
183 manage_passwords_ui_controller->ChooseCredential(false, 198 manage_passwords_ui_controller->ChooseCredential(false,
184 autofill::PasswordForm()); 199 autofill::PasswordForm());
185 state_ = password_manager::ui::INACTIVE_STATE; 200 state_ = password_manager::ui::INACTIVE_STATE;
186 } 201 }
187 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) 202 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED)
188 return; 203 return;
189 204
190 if (password_manager::ui::IsAskSubmitURLState(state_)) { 205 if (password_manager::ui::IsAskSubmitURLState(state_)) {
191 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; 206 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE;
207 RecordURLsCollectionExperimentStatistics(web_contents());
192 } 208 }
193 metrics_util::LogUIDismissalReason(dismissal_reason_); 209 metrics_util::LogUIDismissalReason(dismissal_reason_);
194 // Other use cases have been reported in the callbacks like OnSaveClicked(). 210 // Other use cases have been reported in the callbacks like OnSaveClicked().
195 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) 211 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION)
196 RecordExperimentStatistics(web_contents(), dismissal_reason_); 212 RecordExperimentStatistics(web_contents(), dismissal_reason_);
197 } 213 }
198 214
199 void ManagePasswordsBubbleModel::OnCollectURLClicked(const std::string& url) { 215 void ManagePasswordsBubbleModel::OnCollectURLClicked(const std::string& url) {
200 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL; 216 dismissal_reason_ = metrics_util::CLICKED_COLLECT_URL;
201 RecordExperimentStatistics(web_contents(), dismissal_reason_); 217 RecordExperimentStatistics(web_contents(), dismissal_reason_);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 321
306 // static 322 // static
307 int ManagePasswordsBubbleModel::UsernameFieldWidth() { 323 int ManagePasswordsBubbleModel::UsernameFieldWidth() {
308 return GetFieldWidth(USERNAME_FIELD); 324 return GetFieldWidth(USERNAME_FIELD);
309 } 325 }
310 326
311 // static 327 // static
312 int ManagePasswordsBubbleModel::PasswordFieldWidth() { 328 int ManagePasswordsBubbleModel::PasswordFieldWidth() {
313 return GetFieldWidth(PASSWORD_FIELD); 329 return GetFieldWidth(PASSWORD_FIELD);
314 } 330 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/browser_prefs.cc ('k') | components/password_manager/core/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698