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

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher.cc

Issue 866983003: GetLoginsRequest: Use ScopedVector to express ownership of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@324291_scopedvector
Patch Set: Rebased Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/password_manager/content/browser/credential_manager_dispatc her.h" 5 #include "components/password_manager/content/browser/credential_manager_dispatc her.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/common/password_form.h" 11 #include "components/autofill/core/common/password_form.h"
12 #include "components/password_manager/content/browser/content_password_manager_d river.h" 12 #include "components/password_manager/content/browser/content_password_manager_d river.h"
13 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" 13 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h"
14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h"
15 #include "components/password_manager/content/common/credential_manager_messages .h" 15 #include "components/password_manager/content/common/credential_manager_messages .h"
16 #include "components/password_manager/content/common/credential_manager_types.h" 16 #include "components/password_manager/content/common/credential_manager_types.h"
17 #include "components/password_manager/core/browser/password_manager_client.h" 17 #include "components/password_manager/core/browser/password_manager_client.h"
18 #include "components/password_manager/core/browser/password_store.h" 18 #include "components/password_manager/core/browser/password_store.h"
19 #include "components/password_manager/core/common/password_manager_pref_names.h" 19 #include "components/password_manager/core/common/password_manager_pref_names.h"
20 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "ipc/ipc_message_macros.h" 22 #include "ipc/ipc_message_macros.h"
23 23
24 namespace password_manager { 24 namespace password_manager {
25 25
26 class CredentialManagerDispatcher::PendingRequestTask 26 class CredentialManagerDispatcher::PendingRequestTask
27 : public PasswordStoreConsumer { 27 : public PasswordStoreConsumer {
28 public: 28 public:
29 // TODO(mkwst): De-inline the methods in this class. http://goo.gl/RmFwKd
29 PendingRequestTask(CredentialManagerDispatcher* const dispatcher, 30 PendingRequestTask(CredentialManagerDispatcher* const dispatcher,
30 int request_id, 31 int request_id,
31 bool request_zero_click_only, 32 bool request_zero_click_only,
32 const GURL& request_origin, 33 const GURL& request_origin,
33 const std::vector<GURL>& request_federations) 34 const std::vector<GURL>& request_federations)
34 : dispatcher_(dispatcher), 35 : dispatcher_(dispatcher),
35 id_(request_id), 36 id_(request_id),
36 zero_click_only_(request_zero_click_only), 37 zero_click_only_(request_zero_click_only),
37 origin_(request_origin) { 38 origin_(request_origin) {
38 for (const GURL& origin : request_federations) 39 for (const GURL& origin : request_federations)
39 federations_.insert(origin.spec()); 40 federations_.insert(origin.spec());
40 } 41 }
41 42
42 int id() const { return id_; } 43 int id() const { return id_; }
43 44
44 // PasswordStoreConsumer implementation. 45 // PasswordStoreConsumer implementation.
45 void OnGetPasswordStoreResults( 46 void OnGetPasswordStoreResults() override {
46 const std::vector<autofill::PasswordForm*>& results) override {
47 // We own the PasswordForm instances, so we're responsible for cleaning 47 // We own the PasswordForm instances, so we're responsible for cleaning
48 // up the instances we don't add to |local_results| or |federated_results|. 48 // up the instances we don't add to |local_results| or |federated_results|.
49 // 49 ScopedVector<autofill::PasswordForm> local_results;
50 // TODO(mkwst): Switch this and PromptUserToChooseCredentials() to use 50 ScopedVector<autofill::PasswordForm> federated_results;
51 // ScopedVector. 51 for (auto& form : *results()) {
52 std::vector<autofill::PasswordForm*> local_results; 52 if (form->origin == origin_) {
53 std::vector<autofill::PasswordForm*> federated_results;
54 for (autofill::PasswordForm* form : results) {
55 if (form->origin == origin_)
56 local_results.push_back(form); 53 local_results.push_back(form);
57 else if (federations_.count(form->origin.spec())) 54 form = nullptr;
55 } else if (federations_.count(form->origin.spec())) {
58 federated_results.push_back(form); 56 federated_results.push_back(form);
59 else 57 form = nullptr;
60 delete form; 58 }
61 } 59 }
62 60
63 if ((local_results.empty() && federated_results.empty()) || 61 if ((local_results.empty() && federated_results.empty()) ||
64 dispatcher_->web_contents()->GetLastCommittedURL().GetOrigin() != 62 dispatcher_->web_contents()->GetLastCommittedURL().GetOrigin() !=
65 origin_) { 63 origin_) {
66 dispatcher_->SendCredential(id_, CredentialInfo()); 64 dispatcher_->SendCredential(id_, CredentialInfo());
67 return; 65 return;
68 } 66 }
69 if (local_results.size() == 1 && dispatcher_->IsZeroClickAllowed()) { 67 if (local_results.size() == 1 && dispatcher_->IsZeroClickAllowed()) {
70 // TODO(mkwst): Use the `one_time_disable_zero_click` flag on the result 68 // TODO(mkwst): Use the `one_time_disable_zero_click` flag on the result
71 // to prevent auto-sign-in, once that flag is implemented. 69 // to prevent auto-sign-in, once that flag is implemented.
72 CredentialInfo info(*local_results[0], 70 CredentialInfo info(*local_results[0],
73 local_results[0]->federation_url.is_empty() 71 local_results[0]->federation_url.is_empty()
74 ? CredentialType::CREDENTIAL_TYPE_LOCAL 72 ? CredentialType::CREDENTIAL_TYPE_LOCAL
75 : CredentialType::CREDENTIAL_TYPE_FEDERATED); 73 : CredentialType::CREDENTIAL_TYPE_FEDERATED);
76 STLDeleteElements(&local_results);
77 STLDeleteElements(&federated_results);
78 dispatcher_->SendCredential(id_, info); 74 dispatcher_->SendCredential(id_, info);
79 return; 75 return;
80 } 76 }
81 77
82 if (zero_click_only_ || 78 if (zero_click_only_ ||
83 !dispatcher_->client()->PromptUserToChooseCredentials( 79 !dispatcher_->client()->PromptUserToChooseCredentials(
84 local_results, federated_results, 80 local_results.Pass(), federated_results.Pass(),
85 base::Bind(&CredentialManagerDispatcher::SendCredential, 81 base::Bind(&CredentialManagerDispatcher::SendCredential,
86 base::Unretained(dispatcher_), id_))) { 82 base::Unretained(dispatcher_), id_))) {
87 STLDeleteElements(&local_results);
88 STLDeleteElements(&federated_results);
89 dispatcher_->SendCredential(id_, CredentialInfo()); 83 dispatcher_->SendCredential(id_, CredentialInfo());
90 } 84 }
91 } 85 }
92 86
93 private: 87 private:
94 // Backlink to the CredentialManagerDispatcher that owns this object. 88 // Backlink to the CredentialManagerDispatcher that owns this object.
95 CredentialManagerDispatcher* const dispatcher_; 89 CredentialManagerDispatcher* const dispatcher_;
96 90
97 const int id_; 91 const int id_;
98 const bool zero_click_only_; 92 const bool zero_click_only_;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 DCHECK(pending_request_); 229 DCHECK(pending_request_);
236 DCHECK_EQ(pending_request_->id(), request_id); 230 DCHECK_EQ(pending_request_->id(), request_id);
237 web_contents()->GetRenderViewHost()->Send( 231 web_contents()->GetRenderViewHost()->Send(
238 new CredentialManagerMsg_SendCredential( 232 new CredentialManagerMsg_SendCredential(
239 web_contents()->GetRenderViewHost()->GetRoutingID(), 233 web_contents()->GetRenderViewHost()->GetRoutingID(),
240 pending_request_->id(), info)); 234 pending_request_->id(), info));
241 pending_request_.reset(); 235 pending_request_.reset();
242 } 236 }
243 237
244 } // namespace password_manager 238 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698