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

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

Issue 2691323002: Fixed memory leak in Password Manager UI. (Closed)
Patch Set: Addressing reviewer's comments Created 3 years, 10 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
« no previous file with comments | « chrome/browser/ui/views/passwords/credentials_selection_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/password_manager/core/browser/password_manager_metrics_util .h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 48 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
49 views::GridLayout::FIXED, 0, 0); 49 views::GridLayout::FIXED, 0, 0);
50 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 50 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
51 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 51 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
52 views::GridLayout::FIXED, 0, 0); 52 views::GridLayout::FIXED, 0, 0);
53 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 53 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
54 54
55 // The username combobox and password label. 55 // The username combobox and password label.
56 layout->StartRowWithPadding(0, column_set_id, 0, 56 layout->StartRowWithPadding(0, column_set_id, 0,
57 views::kRelatedControlVerticalSpacing); 57 views::kRelatedControlVerticalSpacing);
58 combobox_ = GenerateUsernameCombobox( 58 GenerateUsernameCombobox(
59 manage_passwords_bubble_model->pending_password().username_value); 59 manage_passwords_bubble_model->pending_password().username_value);
60 layout->AddView(combobox_); 60 layout->AddView(combobox_.get());
61 views::Label* label = 61 views::Label* label =
62 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); 62 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password());
63 layout->AddView(label); 63 layout->AddView(label);
64 64
65 GetLayoutManager()->Layout(this); 65 GetLayoutManager()->Layout(this);
66 } 66 }
67 67
68 CredentialsSelectionView::~CredentialsSelectionView() { 68 CredentialsSelectionView::~CredentialsSelectionView() {
69 ReportUserActionOnce(true, -1); 69 ReportUserActionOnce(true, -1);
70 // |combobox_| has a pointer to |combobox_model_|, so |combobox_| should be
71 // deleted before deleting of |combobox_model_|. To ensure this, let's delete
72 // it now.
73 combobox_.reset();
Mathieu 2017/02/15 13:46:57 you could also have combobox_model_ be above combo
dvadym 2017/02/15 13:57:13 Yeah, sure. In other places it was done this way.
70 } 74 }
71 75
72 const autofill::PasswordForm* 76 const autofill::PasswordForm*
73 CredentialsSelectionView::GetSelectedCredentials() { 77 CredentialsSelectionView::GetSelectedCredentials() {
74 DCHECK_EQ(password_forms_->size(), 78 DCHECK_EQ(password_forms_->size(),
75 static_cast<size_t>(combobox_->model()->GetItemCount())); 79 static_cast<size_t>(combobox_->model()->GetItemCount()));
76 ReportUserActionOnce(false, combobox_->selected_index()); 80 ReportUserActionOnce(false, combobox_->selected_index());
77 return &password_forms_->at(combobox_->selected_index()); 81 return &password_forms_->at(combobox_->selected_index());
78 } 82 }
79 83
80 views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( 84 void CredentialsSelectionView::GenerateUsernameCombobox(
81 const base::string16& best_matched_username) { 85 const base::string16& best_matched_username) {
82 std::vector<base::string16> usernames; 86 std::vector<base::string16> usernames;
83 size_t best_matched_username_index = password_forms_->size(); 87 size_t best_matched_username_index = password_forms_->size();
84 size_t preferred_form_index = password_forms_->size(); 88 size_t preferred_form_index = password_forms_->size();
85 for (size_t index = 0; index < password_forms_->size(); ++index) { 89 for (size_t index = 0; index < password_forms_->size(); ++index) {
86 usernames.push_back(password_forms_->at(index).username_value); 90 usernames.push_back(password_forms_->at(index).username_value);
87 if (password_forms_->at(index).username_value == best_matched_username) { 91 if (password_forms_->at(index).username_value == best_matched_username) {
88 best_matched_username_index = index; 92 best_matched_username_index = index;
89 } 93 }
90 if (password_forms_->at(index).preferred) { 94 if (password_forms_->at(index).preferred) {
91 preferred_form_index = index; 95 preferred_form_index = index;
92 } 96 }
93 } 97 }
94 98
95 views::Combobox* combobox = 99 combobox_model_.reset(new ui::SimpleComboboxModel(usernames));
96 new views::Combobox(new ui::SimpleComboboxModel(usernames)); 100 combobox_.reset(new views::Combobox(combobox_model_.get()));
97 101
98 if (best_matched_username_index < password_forms_->size()) { 102 if (best_matched_username_index < password_forms_->size()) {
99 is_default_best_match_ = true; 103 is_default_best_match_ = true;
100 default_index_ = best_matched_username_index; 104 default_index_ = best_matched_username_index;
101 combobox->SetSelectedIndex(best_matched_username_index); 105 combobox_->SetSelectedIndex(best_matched_username_index);
102 } else if (preferred_form_index < password_forms_->size()) { 106 } else if (preferred_form_index < password_forms_->size()) {
103 is_default_preferred_ = true; 107 is_default_preferred_ = true;
104 default_index_ = preferred_form_index; 108 default_index_ = preferred_form_index;
105 combobox->SetSelectedIndex(preferred_form_index); 109 combobox_->SetSelectedIndex(preferred_form_index);
106 } 110 }
107 return combobox;
108 } 111 }
109 112
110 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected, 113 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected,
111 int selected_index) { 114 int selected_index) {
112 if (action_reported_) 115 if (action_reported_)
113 return; 116 return;
114 password_manager::metrics_util::MultiAccountUpdateBubbleUserAction action; 117 password_manager::metrics_util::MultiAccountUpdateBubbleUserAction action;
115 if (was_update_rejected) { 118 if (was_update_rejected) {
116 if (is_default_best_match_) { 119 if (is_default_best_match_) {
117 action = password_manager::metrics_util:: 120 action = password_manager::metrics_util::
(...skipping 25 matching lines...) Expand all
143 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED; 146 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED;
144 } else { 147 } else {
145 action = 148 action =
146 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED; 149 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED;
147 } 150 }
148 } 151 }
149 152
150 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action); 153 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action);
151 action_reported_ = true; 154 action_reported_ = true;
152 } 155 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/passwords/credentials_selection_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698