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

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: feedback. 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,
113 const GURL& origin);
114
115 void AddOrigin(const GURL& origin);
116
117 // PasswordStoreConsumer implementation.
118 void OnGetPasswordStoreResults(
119 const std::vector<autofill::PasswordForm*>& results) override;
120
121 private:
122 // Backlink to the CredentialManagerDispatcher that owns this object.
123 CredentialManagerDispatcher* const dispatcher_;
124 std::set<std::string> origins_;
125
126 DISALLOW_COPY_AND_ASSIGN(PendingSignedOutTask);
127 };
128
129 CredentialManagerDispatcher::PendingSignedOutTask::PendingSignedOutTask(
130 CredentialManagerDispatcher* const dispatcher,
131 const GURL& origin)
132 : dispatcher_(dispatcher) {
133 origins_.insert(origin.spec());
134 }
135
136 void CredentialManagerDispatcher::PendingSignedOutTask::AddOrigin(
137 const GURL& origin) {
138 origins_.insert(origin.spec());
139 }
140
141 void CredentialManagerDispatcher::PendingSignedOutTask::
142 OnGetPasswordStoreResults(
143 const std::vector<autofill::PasswordForm*>& results) {
144 PasswordStore* store = dispatcher_->GetPasswordStore();
145 for (autofill::PasswordForm* form : results) {
146 if (origins_.count(form->origin.spec())) {
147 form->skip_zero_click = true;
148 store->UpdateLogin(*form);
149 }
150 // We own the PasswordForms, so we need to dispose of them. This is safe to
151 // do, as ::UpdateLogin ends up copying the form while posting a task to
152 // update the PasswordStore.
153 delete form;
154 }
155
156 dispatcher_->DoneSigningOut();
vabr (Chromium) 2015/02/06 08:32:32 optional: Maybe add a note like "Destroys |this|"
157 }
158
159 // CredentialManagerDispatcher -------------------------------------------------
160
105 CredentialManagerDispatcher::CredentialManagerDispatcher( 161 CredentialManagerDispatcher::CredentialManagerDispatcher(
106 content::WebContents* web_contents, 162 content::WebContents* web_contents,
107 PasswordManagerClient* client) 163 PasswordManagerClient* client)
108 : WebContentsObserver(web_contents), client_(client) { 164 : WebContentsObserver(web_contents), client_(client) {
109 DCHECK(web_contents); 165 DCHECK(web_contents);
110 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin, 166 auto_signin_enabled_.Init(prefs::kPasswordManagerAutoSignin,
111 client_->GetPrefs()); 167 client_->GetPrefs());
112 } 168 }
113 169
114 CredentialManagerDispatcher::~CredentialManagerDispatcher() { 170 CredentialManagerDispatcher::~CredentialManagerDispatcher() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK(request_id); 202 DCHECK(request_id);
147 web_contents()->GetRenderViewHost()->Send( 203 web_contents()->GetRenderViewHost()->Send(
148 new CredentialManagerMsg_AcknowledgeSignedIn( 204 new CredentialManagerMsg_AcknowledgeSignedIn(
149 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); 205 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
150 206
151 if (!IsSavingEnabledForCurrentPage()) 207 if (!IsSavingEnabledForCurrentPage())
152 return; 208 return;
153 209
154 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo( 210 scoped_ptr<autofill::PasswordForm> form(CreatePasswordFormFromCredentialInfo(
155 credential, web_contents()->GetLastCommittedURL().GetOrigin())); 211 credential, web_contents()->GetLastCommittedURL().GetOrigin()));
212 form->skip_zero_click = !IsZeroClickAllowed();
156 213
157 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to 214 // TODO(mkwst): This is a stub; we should be checking the PasswordStore to
158 // determine whether or not the credential exists, and calling UpdateLogin 215 // determine whether or not the credential exists, and calling UpdateLogin
159 // accordingly. 216 // accordingly.
160 form_manager_.reset(new CredentialManagerPasswordFormManager( 217 form_manager_.reset(new CredentialManagerPasswordFormManager(
161 client_, GetDriver(), *form, this)); 218 client_, GetDriver(), *form, this));
162 } 219 }
163 220
164 void CredentialManagerDispatcher::OnProvisionalSaveComplete() { 221 void CredentialManagerDispatcher::OnProvisionalSaveComplete() {
165 DCHECK(form_manager_); 222 DCHECK(form_manager_);
166 client_->PromptUserToSavePassword(form_manager_.Pass()); 223 client_->PromptUserToSavePassword(form_manager_.Pass());
167 } 224 }
168 225
169 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) { 226 void CredentialManagerDispatcher::OnNotifySignedOut(int request_id) {
170 DCHECK(request_id); 227 DCHECK(request_id);
171 // TODO(mkwst): This is a stub. 228
229 PasswordStore* store = GetPasswordStore();
230 if (store) {
231 if (!pending_sign_out_) {
232 pending_sign_out_.reset(new PendingSignedOutTask(
233 this, web_contents()->GetLastCommittedURL().GetOrigin()));
234
235 // This will result in a callback to
236 // PendingSignedOutTask::OnGetPasswordStoreResults().
237 store->GetAutofillableLogins(pending_sign_out_.get());
238 } else {
239 pending_sign_out_->AddOrigin(
vabr (Chromium) 2015/02/06 08:32:32 I'm just explicitly acknowledging that although th
240 web_contents()->GetLastCommittedURL().GetOrigin());
241 }
242 }
243
172 web_contents()->GetRenderViewHost()->Send( 244 web_contents()->GetRenderViewHost()->Send(
173 new CredentialManagerMsg_AcknowledgeSignedOut( 245 new CredentialManagerMsg_AcknowledgeSignedOut(
174 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id)); 246 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
175 } 247 }
176 248
177 void CredentialManagerDispatcher::OnRequestCredential( 249 void CredentialManagerDispatcher::OnRequestCredential(
178 int request_id, 250 int request_id,
179 bool zero_click_only, 251 bool zero_click_only,
180 const std::vector<GURL>& federations) { 252 const std::vector<GURL>& federations) {
181 DCHECK(request_id); 253 DCHECK(request_id);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DCHECK(driver_factory); 299 DCHECK(driver_factory);
228 PasswordManagerDriver* driver = 300 PasswordManagerDriver* driver =
229 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); 301 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame());
230 return driver->AsWeakPtr(); 302 return driver->AsWeakPtr();
231 } 303 }
232 304
233 void CredentialManagerDispatcher::SendCredential(int request_id, 305 void CredentialManagerDispatcher::SendCredential(int request_id,
234 const CredentialInfo& info) { 306 const CredentialInfo& info) {
235 DCHECK(pending_request_); 307 DCHECK(pending_request_);
236 DCHECK_EQ(pending_request_->id(), request_id); 308 DCHECK_EQ(pending_request_->id(), request_id);
309 // TODO(mkwst): We need to update the underlying PasswordForm if the user
310 // has enabled zeroclick globally, and clicks through a non-zeroclick form
311 // for an origin.
237 web_contents()->GetRenderViewHost()->Send( 312 web_contents()->GetRenderViewHost()->Send(
238 new CredentialManagerMsg_SendCredential( 313 new CredentialManagerMsg_SendCredential(
239 web_contents()->GetRenderViewHost()->GetRoutingID(), 314 web_contents()->GetRenderViewHost()->GetRoutingID(),
240 pending_request_->id(), info)); 315 pending_request_->id(), info));
241 pending_request_.reset(); 316 pending_request_.reset();
242 } 317 }
243 318
319 void CredentialManagerDispatcher::DoneSigningOut() {
320 DCHECK(pending_sign_out_);
321 pending_sign_out_.reset();
322 }
323
244 } // namespace password_manager 324 } // 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