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

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

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Rebase. Created 5 years, 6 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/passwords/manage_passwords_state.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h"
6 6
7 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" 7 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h"
8 #include "components/password_manager/core/browser/password_form_manager.h" 8 #include "components/password_manager/core/browser/password_form_manager.h"
9 #include "components/password_manager/core/browser/password_manager_client.h" 9 #include "components/password_manager/core/browser/password_manager_client.h"
10 #include "components/password_manager/core/common/credential_manager_types.h" 10 #include "components/password_manager/core/common/credential_manager_types.h"
11 11
12 using password_manager::PasswordFormManager; 12 using password_manager::PasswordFormManager;
13 using autofill::PasswordFormMap; 13 using autofill::PasswordFormMap;
14 14
15 namespace { 15 namespace {
16 16
17 // Converts the map with pointers or const pointers to the vector of const 17 // Returns a vector containing the values of a map.
18 // pointers. 18 template <typename Map>
19 template <typename T> 19 std::vector<typename Map::mapped_type> MapToVector(const Map& map) {
20 std::vector<const T*> MapToVector( 20 std::vector<typename Map::mapped_type> ret;
21 const std::map<base::string16, T*>& map) {
22 std::vector<const autofill::PasswordForm*> ret;
23 ret.reserve(map.size()); 21 ret.reserve(map.size());
24 for (const auto& form_pair : map) 22 for (const auto& form_pair : map)
25 ret.push_back(form_pair.second); 23 ret.push_back(form_pair.second);
24 return ret;
25 }
26
27 // Takes a ScopedPtrMap. Returns a vector of non-owned pointers to the elements
28 // inside the scoped_ptrs.
29 template <typename Map>
30 std::vector<const typename Map::mapped_type::element_type*>
31 ScopedPtrMapToVector(const Map& map) {
32 std::vector<const typename Map::mapped_type::element_type*> ret;
33 ret.reserve(map.size());
34 for (const auto& form_pair : map)
35 ret.push_back(form_pair.second);
26 return ret; 36 return ret;
27 } 37 }
28 38
29 ScopedVector<const autofill::PasswordForm> DeepCopyMapToVector( 39 ScopedVector<const autofill::PasswordForm> DeepCopyMapToVector(
30 const PasswordFormMap& password_form_map) { 40 const PasswordFormMap& password_form_map) {
31 ScopedVector<const autofill::PasswordForm> ret; 41 ScopedVector<const autofill::PasswordForm> ret;
32 ret.reserve(password_form_map.size()); 42 ret.reserve(password_form_map.size());
33 for (const auto& form_pair : password_form_map) 43 for (const auto& form_pair : password_form_map)
34 ret.push_back(new autofill::PasswordForm(*form_pair.second)); 44 ret.push_back(new autofill::PasswordForm(*form_pair.second));
35 return ret.Pass(); 45 return ret.Pass();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 : state_(password_manager::ui::INACTIVE_STATE), 111 : state_(password_manager::ui::INACTIVE_STATE),
102 client_(nullptr) { 112 client_(nullptr) {
103 } 113 }
104 114
105 ManagePasswordsState::~ManagePasswordsState() {} 115 ManagePasswordsState::~ManagePasswordsState() {}
106 116
107 void ManagePasswordsState::OnPendingPassword( 117 void ManagePasswordsState::OnPendingPassword(
108 scoped_ptr<password_manager::PasswordFormManager> form_manager) { 118 scoped_ptr<password_manager::PasswordFormManager> form_manager) {
109 ClearData(); 119 ClearData();
110 form_manager_ = form_manager.Pass(); 120 form_manager_ = form_manager.Pass();
111 current_forms_weak_ = MapToVector(form_manager_->best_matches()); 121 current_forms_weak_ = ScopedPtrMapToVector(form_manager_->best_matches());
112 origin_ = form_manager_->pending_credentials().origin; 122 origin_ = form_manager_->pending_credentials().origin;
113 SetState(password_manager::ui::PENDING_PASSWORD_STATE); 123 SetState(password_manager::ui::PENDING_PASSWORD_STATE);
114 } 124 }
115 125
116 void ManagePasswordsState::OnRequestCredentials( 126 void ManagePasswordsState::OnRequestCredentials(
117 ScopedVector<autofill::PasswordForm> local_credentials, 127 ScopedVector<autofill::PasswordForm> local_credentials,
118 ScopedVector<autofill::PasswordForm> federated_credentials, 128 ScopedVector<autofill::PasswordForm> federated_credentials,
119 const GURL& origin) { 129 const GURL& origin) {
120 ClearData(); 130 ClearData();
121 local_credentials_forms_ = ConstifyVector(&local_credentials); 131 local_credentials_forms_ = ConstifyVector(&local_credentials);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 void ManagePasswordsState::SetState(password_manager::ui::State state) { 286 void ManagePasswordsState::SetState(password_manager::ui::State state) {
277 DCHECK(client_); 287 DCHECK(client_);
278 if (client_->IsLoggingActive()) { 288 if (client_->IsLoggingActive()) {
279 password_manager::BrowserSavePasswordProgressLogger logger(client_); 289 password_manager::BrowserSavePasswordProgressLogger logger(client_);
280 logger.LogNumber( 290 logger.LogNumber(
281 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, 291 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE,
282 state); 292 state);
283 } 293 }
284 state_ = state; 294 state_ = state;
285 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698