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

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

Issue 902843002: Credential Manager: Wire `notifySignedOut` to the PasswordStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASAN. 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
« no previous file with comments | « components/password_manager/content/browser/credential_manager_dispatcher.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 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 // CredentialManagerDispatcher::PendingRequestTask -----------------------------
27
26 class CredentialManagerDispatcher::PendingRequestTask 28 class CredentialManagerDispatcher::PendingRequestTask
27 : public PasswordStoreConsumer { 29 : public PasswordStoreConsumer {
28 public: 30 public:
29 PendingRequestTask(CredentialManagerDispatcher* const dispatcher, 31 PendingRequestTask(CredentialManagerDispatcher* const dispatcher,
30 int request_id, 32 int request_id,
31 bool request_zero_click_only, 33 bool request_zero_click_only,
32 const GURL& request_origin, 34 const GURL& request_origin,
33 const std::vector<GURL>& request_federations) 35 const std::vector<GURL>& request_federations)
34 : dispatcher_(dispatcher), 36 : dispatcher_(dispatcher),
35 id_(request_id), 37 id_(request_id),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 CredentialManagerDispatcher* const dispatcher_; 97 CredentialManagerDispatcher* const dispatcher_;
96 98
97 const int id_; 99 const int id_;
98 const bool zero_click_only_; 100 const bool zero_click_only_;
99 const GURL origin_; 101 const GURL origin_;
100 std::set<std::string> federations_; 102 std::set<std::string> federations_;
101 103
102 DISALLOW_COPY_AND_ASSIGN(PendingRequestTask); 104 DISALLOW_COPY_AND_ASSIGN(PendingRequestTask);
103 }; 105 };
104 106
107 // CredentialManagerDispatcher::PendingSignedOutTask ---------------------------
108
109 class CredentialManagerDispatcher::PendingSignedOutTask
110 : public PasswordStoreConsumer {
111 public:
112 PendingSignedOutTask(CredentialManagerDispatcher* const dispatcher,
vasilii 2015/02/05 14:49:31 'const' doesn't make a lot of sense here.
113 int request_id,
114 const GURL& origin);
115
116 // PasswordStoreConsumer implementation.
117 void OnGetPasswordStoreResults(
118 const std::vector<autofill::PasswordForm*>& results) override;
119
120 private:
121 // Backlink to the CredentialManagerDispatcher that owns this object.
122 CredentialManagerDispatcher* const dispatcher_;
123
124 const int id_;
125 const GURL origin_;
126
127 DISALLOW_COPY_AND_ASSIGN(PendingSignedOutTask);
128 };
129
130 CredentialManagerDispatcher::PendingSignedOutTask::PendingSignedOutTask(
131 CredentialManagerDispatcher* const dispatcher,
132 int request_id,
133 const GURL& origin)
134 : dispatcher_(dispatcher), id_(request_id), origin_(origin) {
135 }
136
137 void CredentialManagerDispatcher::PendingSignedOutTask::
138 OnGetPasswordStoreResults(
139 const std::vector<autofill::PasswordForm*>& results) {
140 // We own the PasswordForm instances, so we're responsible for cleaning
141 // up the instances we don't add to |updating| (which will delete itself).
142 PasswordStore* store = dispatcher_->GetPasswordStore();
143 ScopedVector<autofill::PasswordForm> updating;
144 for (autofill::PasswordForm* form : results) {
145 if (form->origin == origin_) {
146 form->skip_zero_click = true;
147 store->UpdateLogin(*form);
148 updating.push_back(form);
149 } else {
150 delete form;
vabr (Chromium) 2015/02/05 14:08:40 Why not just delete them all directly? UpdateLogin
vasilii 2015/02/05 14:49:31 Acknowledged.
151 }
152 }
153 }
154
155 // CredentialManagerDispatcher -------------------------------------------------
156
105 CredentialManagerDispatcher::CredentialManagerDispatcher( 157 CredentialManagerDispatcher::CredentialManagerDispatcher(
106 content::WebContents* web_contents, 158 content::WebContents* web_contents,
107 PasswordManagerClient* client) 159 PasswordManagerClient* client)
108 : WebContentsObserver(web_contents), client_(client) { 160 : WebContentsObserver(web_contents), client_(client) {
109 DCHECK(web_contents); 161 DCHECK(web_contents);
110 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, 162 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin,
111 client_->GetPrefs()); 163 client_->GetPrefs());
112 } 164 }
113 165
114 CredentialManagerDispatcher::~CredentialManagerDispatcher() { 166 CredentialManagerDispatcher::~CredentialManagerDispatcher() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK(request_id); 198 DCHECK(request_id);
147 web_contents()->GetRenderViewHost()->Send( 199 web_contents()->GetRenderViewHost()->Send(
148 new CredentialManagerMsg_AcknowledgeSignedIn( 200 new CredentialManagerMsg_AcknowledgeSignedIn(
149 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); 201 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
150 202
151 if (!IsSavingEnabledForCurrentPage()) 203 if (!IsSavingEnabledForCurrentPage())
152 return; 204 return;
153 205
154 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( 206 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo(
155 credential, web_contents()->GetLastCommittedURL().GetOrigin())); 207 credential, web_contents()->GetLastCommittedURL().GetOrigin()));
208 form->skip_zero_click = !IsZeroClickAllowed();
156 209
157 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to 210 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to
158 // determine whether or not the credential exists, and calling UpdateLogin 211 // determine whether or not the credential exists, and calling UpdateLogin
159 // accordingly. 212 // accordingly.
160 form_manager_.reset(new CredentialManagerPasswordFormManager( 213 form_manager_.reset(new CredentialManagerPasswordFormManager(
161 client_, GetDriver(), *form, this)); 214 client_, GetDriver(), *form, this));
162 } 215 }
163 216
164 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { 217 void CredentialManagerDispatcher::OnProvisionalSaveComplete() {
165 DCHECK(form_manager_); 218 DCHECK(form_manager_);
166 client_->PromptUserToSavePassword(form_manager_.Pass()); 219 client_->PromptUserToSavePassword(form_manager_.Pass());
167 } 220 }
168 221
169 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { 222 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) {
170 DCHECK(request_id); 223 DCHECK(request_id);
171 // TODO(mkwst): This is a stub. 224
225 PasswordStore* store = GetPasswordStore();
226 if (!pending_sign_out_ && store) {
vasilii 2015/02/05 14:49:31 I don't see the place where pending_sign_out_ actu
227 pending_sign_out_.reset(new PendingSignedOutTask(
228 this, request_id, web_contents()->GetLastCommittedURL().GetOrigin()));
229
230 // This will result in a callback to
231 // PendingSignedOutTask::OnGetPasswordStoreResults().
232 store->GetAutofillableLogins(pending_sign_out_.get());
233 }
234
172 web_contents()->GetRenderViewHost()->Send( 235 web_contents()->GetRenderViewHost()->Send(
173 new CredentialManagerMsg_AcknowledgeSignedOut( 236 new CredentialManagerMsg_AcknowledgeSignedOut(
174 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); 237 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
175 } 238 }
176 239
177 void CredentialManagerDispatcher::OnRequestCredential( 240 void CredentialManagerDispatcher::OnRequestCredential(
178 int request_id, 241 int request_id,
179 bool zero_click_only, 242 bool zero_click_only,
180 const std::vector<GURL>& federations) { 243 const std::vector<GURL>& federations) {
181 DCHECK(request_id); 244 DCHECK(request_id);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DCHECK(driver_factory); 290 DCHECK(driver_factory);
228 PasswordManagerDriver* driver = 291 PasswordManagerDriver* driver =
229 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); 292 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame());
230 return driver->AsWeakPtr(); 293 return driver->AsWeakPtr();
231 } 294 }
232 295
233 void CredentialManagerDispatcher::SendCredential(int request_id, 296 void CredentialManagerDispatcher::SendCredential(int request_id,
234 const CredentialInfo& info) { 297 const CredentialInfo& info) {
235 DCHECK(pending_request_); 298 DCHECK(pending_request_);
236 DCHECK_EQ(pending_request_->id(), request_id); 299 DCHECK_EQ(pending_request_->id(), request_id);
300 // TODO(mkwst): We need to update the underlying PasswordForm if the user
301 // has enabled zeroclick globally, and clicks through a non-zeroclick form
302 // for an origin.
237 web_contents()->GetRenderViewHost()->Send( 303 web_contents()->GetRenderViewHost()->Send(
238 new CredentialManagerMsg_SendCredential( 304 new CredentialManagerMsg_SendCredential(
239 web_contents()->GetRenderViewHost()->GetRoutingID(), 305 web_contents()->GetRenderViewHost()->GetRoutingID(),
240 pending_request_->id(), info)); 306 pending_request_->id(), info));
241 pending_request_.reset(); 307 pending_request_.reset();
242 } 308 }
243 309
244 } // namespace password_manager 310 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/content/browser/credential_manager_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698