OLD | NEW |
---|---|
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 } // namespace |
31 | |
32 views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( | |
vasilii
2016/01/13 15:23:46
The definition order should match the declaration
dvadym
2016/01/13 15:39:56
Done.
| |
30 const std::vector<const autofill::PasswordForm*>& forms, | 33 const std::vector<const autofill::PasswordForm*>& forms, |
31 const base::string16& best_matched_username) { | 34 const base::string16& best_matched_username) { |
32 std::vector<base::string16> usernames; | 35 std::vector<base::string16> usernames; |
33 size_t best_matched_username_index = forms.size(); | 36 size_t best_matched_username_index = forms.size(); |
34 size_t preferred_form_index = forms.size(); | 37 size_t preferred_form_index = forms.size(); |
35 for (size_t index = 0; index < forms.size(); ++index) { | 38 for (size_t index = 0; index < forms.size(); ++index) { |
36 usernames.push_back(forms[index]->username_value); | 39 usernames.push_back(forms[index]->username_value); |
37 if (forms[index]->username_value == best_matched_username) { | 40 if (forms[index]->username_value == best_matched_username) { |
38 best_matched_username_index = index; | 41 best_matched_username_index = index; |
39 } | 42 } |
40 if (forms[index]->preferred) { | 43 if (forms[index]->preferred) { |
41 preferred_form_index = index; | 44 preferred_form_index = index; |
42 } | 45 } |
43 } | 46 } |
44 | 47 |
45 views::Combobox* combobox = | 48 views::Combobox* combobox = |
46 new views::Combobox(new ui::SimpleComboboxModel(usernames)); | 49 new views::Combobox(new ui::SimpleComboboxModel(usernames)); |
47 | 50 |
51 default_index_ = 0; | |
52 is_default_best_match_ = false; | |
53 is_default_preferred_ = false; | |
54 | |
48 if (best_matched_username_index < forms.size()) { | 55 if (best_matched_username_index < forms.size()) { |
56 is_default_best_match_ = true; | |
57 default_index_ = best_matched_username_index; | |
49 combobox->SetSelectedIndex(best_matched_username_index); | 58 combobox->SetSelectedIndex(best_matched_username_index); |
50 } else if (preferred_form_index < forms.size()) { | 59 } else if (preferred_form_index < forms.size()) { |
60 is_default_preferred_ = true; | |
61 default_index_ = preferred_form_index; | |
51 combobox->SetSelectedIndex(preferred_form_index); | 62 combobox->SetSelectedIndex(preferred_form_index); |
52 } | 63 } |
53 return combobox; | 64 return combobox; |
54 } | 65 } |
55 | 66 |
56 } // namespace | |
57 | |
58 CredentialsSelectionView::CredentialsSelectionView( | 67 CredentialsSelectionView::CredentialsSelectionView( |
59 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | 68 ManagePasswordsBubbleModel* manage_passwords_bubble_model, |
60 const std::vector<const autofill::PasswordForm*>& password_forms, | 69 const std::vector<const autofill::PasswordForm*>& password_forms, |
61 const base::string16& best_matched_username) | 70 const base::string16& best_matched_username) |
62 : password_forms_(password_forms) { | 71 : password_forms_(password_forms), |
72 action_reported_(false) { | |
63 DCHECK(!password_forms.empty()); | 73 DCHECK(!password_forms.empty()); |
64 | 74 |
65 // Layout. | 75 // Layout. |
66 views::GridLayout* layout = new views::GridLayout(this); | 76 views::GridLayout* layout = new views::GridLayout(this); |
67 SetLayoutManager(layout); | 77 SetLayoutManager(layout); |
68 | 78 |
69 // ColumnSet. | 79 // ColumnSet. |
70 int column_set_id = 0; | 80 int column_set_id = 0; |
71 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 81 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
72 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 82 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
(...skipping 10 matching lines...) Expand all Loading... | |
83 manage_passwords_bubble_model->local_credentials().get(), | 93 manage_passwords_bubble_model->local_credentials().get(), |
84 best_matched_username); | 94 best_matched_username); |
85 layout->AddView(combobox_); | 95 layout->AddView(combobox_); |
86 views::Label* label = | 96 views::Label* label = |
87 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); | 97 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); |
88 layout->AddView(label); | 98 layout->AddView(label); |
89 | 99 |
90 GetLayoutManager()->Layout(this); | 100 GetLayoutManager()->Layout(this); |
91 } | 101 } |
92 | 102 |
103 CredentialsSelectionView::~CredentialsSelectionView() { | |
104 ReportUserActionOnce(true, -1); | |
105 } | |
106 | |
93 const autofill::PasswordForm* | 107 const autofill::PasswordForm* |
94 CredentialsSelectionView::GetSelectedCredentials() { | 108 CredentialsSelectionView::GetSelectedCredentials() { |
95 DCHECK_EQ(password_forms_.size(), | 109 DCHECK_EQ(password_forms_.size(), |
96 static_cast<size_t>(combobox_->model()->GetItemCount())); | 110 static_cast<size_t>(combobox_->model()->GetItemCount())); |
111 ReportUserActionOnce(false, combobox_->selected_index()); | |
97 return password_forms_[combobox_->selected_index()]; | 112 return password_forms_[combobox_->selected_index()]; |
98 } | 113 } |
114 | |
115 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected_, | |
116 int selected_index) { | |
vasilii
2016/01/13 15:23:46
indent
dvadym
2016/01/13 15:39:56
Done.
| |
117 if (action_reported_) | |
118 return; | |
119 password_manager::metrics_util::MultiAccountUpdateBubbleUserAction action; | |
120 if (was_update_rejected_) { | |
121 if (is_default_best_match_) { | |
122 action = password_manager::metrics_util:: | |
123 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_REJECTED_UPDATE; | |
124 } else if (is_default_preferred_) { | |
125 action = password_manager::metrics_util:: | |
126 DEFAULT_ACCOUNT_PREFERRED_USER_REJECTED_UPDATE; | |
127 } else { | |
128 action = password_manager::metrics_util:: | |
129 DEFAULT_ACCOUNT_FIRST_USER_REJECTED_UPDATE; | |
130 } | |
131 } else if (selected_index == default_index_) { | |
132 if (is_default_best_match_) { | |
133 action = password_manager::metrics_util:: | |
134 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_NOT_CHANGED; | |
135 } else if (is_default_preferred_) { | |
136 action = password_manager::metrics_util:: | |
137 DEFAULT_ACCOUNT_PREFERRED_USER_NOT_CHANGED; | |
138 } else { | |
139 action = password_manager::metrics_util:: | |
140 DEFAULT_ACCOUNT_FIRST_USER_NOT_CHANGED; | |
141 } | |
142 } else { | |
143 if (is_default_best_match_) { | |
144 action = password_manager::metrics_util:: | |
145 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_CHANGED; | |
146 } else if (is_default_preferred_) { | |
147 action = password_manager::metrics_util:: | |
148 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED; | |
149 } else { | |
150 action = | |
151 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED; | |
152 } | |
153 } | |
154 | |
155 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action); | |
156 action_reported_ = true; | |
157 } | |
OLD | NEW |