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

Side by Side Diff: chrome/browser/ui/views/passwords/credentials_selection_view.cc

Issue 1586613003: UMA histogram of user action on multi-account password update bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small fix Created 4 years, 11 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/passwords/credentials_selection_view.h" 5 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
10 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
10 #include "ui/base/models/simple_combobox_model.h" 11 #include "ui/base/models/simple_combobox_model.h"
11 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/combobox/combobox.h" 14 #include "ui/views/controls/combobox/combobox.h"
14 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
15 #include "ui/views/layout/grid_layout.h" 16 #include "ui/views/layout/grid_layout.h"
16 #include "ui/views/layout/layout_constants.h" 17 #include "ui/views/layout/layout_constants.h"
17 18
18 namespace { 19 namespace {
19 20
20 views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) { 21 views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) {
21 views::Label* label = new views::Label(form.password_value); 22 views::Label* label = new views::Label(form.password_value);
22 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 23 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
23 ui::ResourceBundle::SmallFont)); 24 ui::ResourceBundle::SmallFont));
24 label->SetHorizontalAlignment(gfx::ALIGN_CENTER); 25 label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
25 label->SetObscured(true); 26 label->SetObscured(true);
26 return label; 27 return label;
27 } 28 }
28 29
29 views::Combobox* GenerateUsernameCombobox( 30 views::Combobox* GenerateUsernameCombobox(
30 const std::vector<const autofill::PasswordForm*>& forms, 31 const std::vector<const autofill::PasswordForm*>& forms,
31 const base::string16& best_matched_username) { 32 const base::string16& best_matched_username,
33 int& default_index,
34 bool& is_default_best_match,
35 bool& is_default_preferred) {
vasilii 2016/01/13 13:54:25 Move the function to the class.
dvadym 2016/01/13 14:55:37 Thanks, it makes sense
32 std::vector<base::string16> usernames; 36 std::vector<base::string16> usernames;
33 size_t best_matched_username_index = forms.size(); 37 size_t best_matched_username_index = forms.size();
34 size_t preferred_form_index = forms.size(); 38 size_t preferred_form_index = forms.size();
35 for (size_t index = 0; index < forms.size(); ++index) { 39 for (size_t index = 0; index < forms.size(); ++index) {
36 usernames.push_back(forms[index]->username_value); 40 usernames.push_back(forms[index]->username_value);
37 if (forms[index]->username_value == best_matched_username) { 41 if (forms[index]->username_value == best_matched_username) {
38 best_matched_username_index = index; 42 best_matched_username_index = index;
39 } 43 }
40 if (forms[index]->preferred) { 44 if (forms[index]->preferred) {
41 preferred_form_index = index; 45 preferred_form_index = index;
42 } 46 }
43 } 47 }
44 48
45 views::Combobox* combobox = 49 views::Combobox* combobox =
46 new views::Combobox(new ui::SimpleComboboxModel(usernames)); 50 new views::Combobox(new ui::SimpleComboboxModel(usernames));
47 51
52 default_index = 0;
53 is_default_best_match = false;
54 is_default_preferred = false;
55
48 if (best_matched_username_index < forms.size()) { 56 if (best_matched_username_index < forms.size()) {
57 is_default_best_match = true;
58 default_index = best_matched_username_index;
49 combobox->SetSelectedIndex(best_matched_username_index); 59 combobox->SetSelectedIndex(best_matched_username_index);
50 } else if (preferred_form_index < forms.size()) { 60 } else if (preferred_form_index < forms.size()) {
61 is_default_preferred = true;
62 default_index = preferred_form_index;
51 combobox->SetSelectedIndex(preferred_form_index); 63 combobox->SetSelectedIndex(preferred_form_index);
52 } 64 }
53 return combobox; 65 return combobox;
54 } 66 }
55 67
56 } // namespace 68 } // namespace
57 69
58 CredentialsSelectionView::CredentialsSelectionView( 70 CredentialsSelectionView::CredentialsSelectionView(
59 ManagePasswordsBubbleModel* manage_passwords_bubble_model, 71 ManagePasswordsBubbleModel* manage_passwords_bubble_model,
60 const std::vector<const autofill::PasswordForm*>& password_forms, 72 const std::vector<const autofill::PasswordForm*>& password_forms,
61 const base::string16& best_matched_username) 73 const base::string16& best_matched_username)
62 : password_forms_(password_forms) { 74 : password_forms_(password_forms), action_reported(false) {
vasilii 2016/01/13 13:54:25 line break.
dvadym 2016/01/13 14:55:37 Done.
63 DCHECK(!password_forms.empty()); 75 DCHECK(!password_forms.empty());
64 76
65 // Layout. 77 // Layout.
66 views::GridLayout* layout = new views::GridLayout(this); 78 views::GridLayout* layout = new views::GridLayout(this);
67 SetLayoutManager(layout); 79 SetLayoutManager(layout);
68 80
69 // ColumnSet. 81 // ColumnSet.
70 int column_set_id = 0; 82 int column_set_id = 0;
71 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 83 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
72 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 84 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
73 views::GridLayout::FIXED, 0, 0); 85 views::GridLayout::FIXED, 0, 0);
74 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 86 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
75 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 87 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
76 views::GridLayout::FIXED, 0, 0); 88 views::GridLayout::FIXED, 0, 0);
77 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 89 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
78 90
79 // The username combobox and password label. 91 // The username combobox and password label.
80 layout->StartRowWithPadding(0, column_set_id, 0, 92 layout->StartRowWithPadding(0, column_set_id, 0,
81 views::kRelatedControlVerticalSpacing); 93 views::kRelatedControlVerticalSpacing);
82 combobox_ = GenerateUsernameCombobox( 94 combobox_ = GenerateUsernameCombobox(
83 manage_passwords_bubble_model->local_credentials().get(), 95 manage_passwords_bubble_model->local_credentials().get(),
84 best_matched_username); 96 best_matched_username, default_index, is_default_best_match,
97 is_default_preferred);
85 layout->AddView(combobox_); 98 layout->AddView(combobox_);
86 views::Label* label = 99 views::Label* label =
87 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); 100 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password());
88 layout->AddView(label); 101 layout->AddView(label);
89 102
90 GetLayoutManager()->Layout(this); 103 GetLayoutManager()->Layout(this);
91 } 104 }
92 105
106 CredentialsSelectionView::~CredentialsSelectionView() {
107 ReportUserAction(true, -1);
108 }
109
93 const autofill::PasswordForm* 110 const autofill::PasswordForm*
94 CredentialsSelectionView::GetSelectedCredentials() { 111 CredentialsSelectionView::GetSelectedCredentials() {
95 DCHECK_EQ(password_forms_.size(), 112 DCHECK_EQ(password_forms_.size(),
96 static_cast<size_t>(combobox_->model()->GetItemCount())); 113 static_cast<size_t>(combobox_->model()->GetItemCount()));
114 ReportUserAction(false, combobox_->selected_index());
97 return password_forms_[combobox_->selected_index()]; 115 return password_forms_[combobox_->selected_index()];
98 } 116 }
117
118 void CredentialsSelectionView::ReportUserAction(bool was_update_rejected,
119 int selected_index) {
120 if (action_reported)
121 return;
122 bool did_user_change_selection = selected_index != default_index;
123 password_manager::metrics_util::MultiAccountUpdateBubbleUserAction action;
124 if (was_update_rejected) {
125 if (is_default_best_match)
126 action = password_manager::metrics_util::
vasilii 2016/01/13 13:54:25 if the block is 2-lines then you need {}
dvadym 2016/01/13 14:55:37 Done.
127 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_REJECTED_UPDATE;
vasilii 2016/01/13 13:54:25 the account is matched by username not by password
dvadym 2016/01/13 14:55:37 Maybe name |best_matched_username| is a little bit
128 else if (is_default_preferred)
129 action = password_manager::metrics_util::
130 DEFAULT_ACCOUNT_PREFERRED_USER_REJECTED_UPDATE;
131 else
132 action = password_manager::metrics_util::
133 DEFAULT_ACCOUNT_FIRST_USER_REJECTED_UPDATE;
134 } else if (did_user_change_selection) {
vasilii 2016/01/13 13:54:25 I'd inline did_user_change_selection here.
dvadym 2016/01/13 14:55:37 Done.
135 if (is_default_best_match)
136 action = password_manager::metrics_util::
137 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_CHANGED;
138 else if (is_default_preferred)
139 action = password_manager::metrics_util::
140 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED;
141 else
142 action =
143 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED;
144 } else {
145 if (is_default_best_match)
146 action = password_manager::metrics_util::
147 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_NOT_CHANGED;
148 else if (is_default_preferred)
149 action = password_manager::metrics_util::
150 DEFAULT_ACCOUNT_PREFERRED_USER_NOT_CHANGED;
151 else
152 action = password_manager::metrics_util::
153 DEFAULT_ACCOUNT_FIRST_USER_NOT_CHANGED;
154 }
155 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action);
156 action_reported = true;
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698