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

Side by Side Diff: chrome/browser/sync/glue/password_model_associator.cc

Issue 8680040: Group forms-related files in webkit/glue in a forms/ subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + another build fix Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/glue/password_model_associator.h" 5 #include "chrome/browser/sync/glue/password_model_associator.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/password_manager/password_store.h" 12 #include "chrome/browser/password_manager/password_store.h"
13 #include "chrome/browser/sync/api/sync_error.h" 13 #include "chrome/browser/sync/api/sync_error.h"
14 #include "chrome/browser/sync/internal_api/read_node.h" 14 #include "chrome/browser/sync/internal_api/read_node.h"
15 #include "chrome/browser/sync/internal_api/read_transaction.h" 15 #include "chrome/browser/sync/internal_api/read_transaction.h"
16 #include "chrome/browser/sync/internal_api/write_node.h" 16 #include "chrome/browser/sync/internal_api/write_node.h"
17 #include "chrome/browser/sync/internal_api/write_transaction.h" 17 #include "chrome/browser/sync/internal_api/write_transaction.h"
18 #include "chrome/browser/sync/profile_sync_service.h" 18 #include "chrome/browser/sync/profile_sync_service.h"
19 #include "chrome/browser/sync/protocol/password_specifics.pb.h" 19 #include "chrome/browser/sync/protocol/password_specifics.pb.h"
20 #include "net/base/escape.h" 20 #include "net/base/escape.h"
21 #include "webkit/glue/password_form.h" 21 #include "webkit/forms/password_form.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace browser_sync { 25 namespace browser_sync {
26 26
27 const char kPasswordTag[] = "google_chrome_passwords"; 27 const char kPasswordTag[] = "google_chrome_passwords";
28 28
29 PasswordModelAssociator::PasswordModelAssociator( 29 PasswordModelAssociator::PasswordModelAssociator(
30 ProfileSyncService* sync_service, 30 ProfileSyncService* sync_service,
31 PasswordStore* password_store) 31 PasswordStore* password_store)
(...skipping 16 matching lines...) Expand all
48 bool PasswordModelAssociator::AssociateModels(SyncError* error) { 48 bool PasswordModelAssociator::AssociateModels(SyncError* error) {
49 DCHECK(expected_loop_ == MessageLoop::current()); 49 DCHECK(expected_loop_ == MessageLoop::current());
50 { 50 {
51 base::AutoLock lock(abort_association_pending_lock_); 51 base::AutoLock lock(abort_association_pending_lock_);
52 abort_association_pending_ = false; 52 abort_association_pending_ = false;
53 } 53 }
54 54
55 // We must not be holding a transaction when we interact with the password 55 // We must not be holding a transaction when we interact with the password
56 // store, as it can post tasks to the UI thread which can itself be blocked 56 // store, as it can post tasks to the UI thread which can itself be blocked
57 // on our transaction, resulting in deadlock. (http://crbug.com/70658) 57 // on our transaction, resulting in deadlock. (http://crbug.com/70658)
58 std::vector<webkit_glue::PasswordForm*> passwords; 58 std::vector<webkit::forms::PasswordForm*> passwords;
59 if (!password_store_->FillAutofillableLogins(&passwords) || 59 if (!password_store_->FillAutofillableLogins(&passwords) ||
60 !password_store_->FillBlacklistLogins(&passwords)) { 60 !password_store_->FillBlacklistLogins(&passwords)) {
61 STLDeleteElements(&passwords); 61 STLDeleteElements(&passwords);
62 error->Reset(FROM_HERE, 62 error->Reset(FROM_HERE,
63 "Could not get the password entries.", 63 "Could not get the password entries.",
64 model_type()); 64 model_type());
65 return false; 65 return false;
66 } 66 }
67 67
68 std::set<std::string> current_passwords; 68 std::set<std::string> current_passwords;
69 PasswordVector new_passwords; 69 PasswordVector new_passwords;
70 PasswordVector updated_passwords; 70 PasswordVector updated_passwords;
71 { 71 {
72 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 72 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
73 sync_api::ReadNode password_root(&trans); 73 sync_api::ReadNode password_root(&trans);
74 if (!password_root.InitByTagLookup(kPasswordTag)) { 74 if (!password_root.InitByTagLookup(kPasswordTag)) {
75 error->Reset(FROM_HERE, 75 error->Reset(FROM_HERE,
76 "Server did not create the top-level password node. We " 76 "Server did not create the top-level password node. We "
77 "might be running against an out-of-date server.", 77 "might be running against an out-of-date server.",
78 model_type()); 78 model_type());
79 return false; 79 return false;
80 } 80 }
81 81
82 for (std::vector<webkit_glue::PasswordForm*>::iterator ix = 82 for (std::vector<webkit::forms::PasswordForm*>::iterator ix =
83 passwords.begin(); 83 passwords.begin();
84 ix != passwords.end(); ++ix) { 84 ix != passwords.end(); ++ix) {
85 if (IsAbortPending()) { 85 if (IsAbortPending()) {
86 error->Reset(FROM_HERE, "Abort pending", model_type()); 86 error->Reset(FROM_HERE, "Abort pending", model_type());
87 return false; 87 return false;
88 } 88 }
89 std::string tag = MakeTag(**ix); 89 std::string tag = MakeTag(**ix);
90 90
91 sync_api::ReadNode node(&trans); 91 sync_api::ReadNode node(&trans);
92 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { 92 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) {
93 const sync_pb::PasswordSpecificsData& password = 93 const sync_pb::PasswordSpecificsData& password =
94 node.GetPasswordSpecifics(); 94 node.GetPasswordSpecifics();
95 DCHECK_EQ(tag, MakeTag(password)); 95 DCHECK_EQ(tag, MakeTag(password));
96 96
97 webkit_glue::PasswordForm new_password; 97 webkit::forms::PasswordForm new_password;
98 98
99 if (MergePasswords(password, **ix, &new_password)) { 99 if (MergePasswords(password, **ix, &new_password)) {
100 sync_api::WriteNode write_node(&trans); 100 sync_api::WriteNode write_node(&trans);
101 if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { 101 if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) {
102 STLDeleteElements(&passwords); 102 STLDeleteElements(&passwords);
103 error->Reset(FROM_HERE, 103 error->Reset(FROM_HERE,
104 "Failed to edit password sync node.", 104 "Failed to edit password sync node.",
105 model_type()); 105 model_type());
106 return false; 106 return false;
107 } 107 }
(...skipping 30 matching lines...) Expand all
138 error->Reset(FROM_HERE, "Failed to fetch child node.", model_type()); 138 error->Reset(FROM_HERE, "Failed to fetch child node.", model_type());
139 return false; 139 return false;
140 } 140 }
141 const sync_pb::PasswordSpecificsData& password = 141 const sync_pb::PasswordSpecificsData& password =
142 sync_child_node.GetPasswordSpecifics(); 142 sync_child_node.GetPasswordSpecifics();
143 std::string tag = MakeTag(password); 143 std::string tag = MakeTag(password);
144 144
145 // The password only exists on the server. Add it to the local 145 // The password only exists on the server. Add it to the local
146 // model. 146 // model.
147 if (current_passwords.find(tag) == current_passwords.end()) { 147 if (current_passwords.find(tag) == current_passwords.end()) {
148 webkit_glue::PasswordForm new_password; 148 webkit::forms::PasswordForm new_password;
149 149
150 CopyPassword(password, &new_password); 150 CopyPassword(password, &new_password);
151 Associate(&tag, sync_child_node.GetId()); 151 Associate(&tag, sync_child_node.GetId());
152 new_passwords.push_back(new_password); 152 new_passwords.push_back(new_password);
153 } 153 }
154 154
155 sync_child_id = sync_child_node.GetSuccessorId(); 155 sync_child_id = sync_child_node.GetSuccessorId();
156 } 156 }
157 } 157 }
158 158
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // We have to notify password store observers of the change by hand since 308 // We have to notify password store observers of the change by hand since
309 // we use internal password store interfaces to make changes synchronously. 309 // we use internal password store interfaces to make changes synchronously.
310 password_store_->PostNotifyLoginsChanged(); 310 password_store_->PostNotifyLoginsChanged();
311 } 311 }
312 return true; 312 return true;
313 } 313 }
314 314
315 // static 315 // static
316 void PasswordModelAssociator::CopyPassword( 316 void PasswordModelAssociator::CopyPassword(
317 const sync_pb::PasswordSpecificsData& password, 317 const sync_pb::PasswordSpecificsData& password,
318 webkit_glue::PasswordForm* new_password) { 318 webkit::forms::PasswordForm* new_password) {
319 new_password->scheme = 319 new_password->scheme =
320 static_cast<webkit_glue::PasswordForm::Scheme>(password.scheme()); 320 static_cast<webkit::forms::PasswordForm::Scheme>(password.scheme());
321 new_password->signon_realm = password.signon_realm(); 321 new_password->signon_realm = password.signon_realm();
322 new_password->origin = GURL(password.origin()); 322 new_password->origin = GURL(password.origin());
323 new_password->action = GURL(password.action()); 323 new_password->action = GURL(password.action());
324 new_password->username_element = 324 new_password->username_element =
325 UTF8ToUTF16(password.username_element()); 325 UTF8ToUTF16(password.username_element());
326 new_password->password_element = 326 new_password->password_element =
327 UTF8ToUTF16(password.password_element()); 327 UTF8ToUTF16(password.password_element());
328 new_password->username_value = 328 new_password->username_value =
329 UTF8ToUTF16(password.username_value()); 329 UTF8ToUTF16(password.username_value());
330 new_password->password_value = 330 new_password->password_value =
331 UTF8ToUTF16(password.password_value()); 331 UTF8ToUTF16(password.password_value());
332 new_password->ssl_valid = password.ssl_valid(); 332 new_password->ssl_valid = password.ssl_valid();
333 new_password->preferred = password.preferred(); 333 new_password->preferred = password.preferred();
334 new_password->date_created = 334 new_password->date_created =
335 base::Time::FromInternalValue(password.date_created()); 335 base::Time::FromInternalValue(password.date_created());
336 new_password->blacklisted_by_user = 336 new_password->blacklisted_by_user =
337 password.blacklisted(); 337 password.blacklisted();
338 } 338 }
339 339
340 // static 340 // static
341 bool PasswordModelAssociator::MergePasswords( 341 bool PasswordModelAssociator::MergePasswords(
342 const sync_pb::PasswordSpecificsData& password, 342 const sync_pb::PasswordSpecificsData& password,
343 const webkit_glue::PasswordForm& password_form, 343 const webkit::forms::PasswordForm& password_form,
344 webkit_glue::PasswordForm* new_password) { 344 webkit::forms::PasswordForm* new_password) {
345 DCHECK(new_password); 345 DCHECK(new_password);
346 346
347 if (password.scheme() == password_form.scheme && 347 if (password.scheme() == password_form.scheme &&
348 password_form.signon_realm == password.signon_realm() && 348 password_form.signon_realm == password.signon_realm() &&
349 password_form.origin.spec() == password.origin() && 349 password_form.origin.spec() == password.origin() &&
350 password_form.action.spec() == password.action() && 350 password_form.action.spec() == password.action() &&
351 UTF16ToUTF8(password_form.username_element) == 351 UTF16ToUTF8(password_form.username_element) ==
352 password.username_element() && 352 password.username_element() &&
353 UTF16ToUTF8(password_form.password_element) == 353 UTF16ToUTF8(password_form.password_element) ==
354 password.password_element() && 354 password.password_element() &&
(...skipping 14 matching lines...) Expand all
369 *new_password = password_form; 369 *new_password = password_form;
370 } else { 370 } else {
371 CopyPassword(password, new_password); 371 CopyPassword(password, new_password);
372 } 372 }
373 373
374 return true; 374 return true;
375 } 375 }
376 376
377 // static 377 // static
378 void PasswordModelAssociator::WriteToSyncNode( 378 void PasswordModelAssociator::WriteToSyncNode(
379 const webkit_glue::PasswordForm& password_form, 379 const webkit::forms::PasswordForm& password_form,
380 sync_api::WriteNode* node) { 380 sync_api::WriteNode* node) {
381 sync_pb::PasswordSpecificsData password; 381 sync_pb::PasswordSpecificsData password;
382 password.set_scheme(password_form.scheme); 382 password.set_scheme(password_form.scheme);
383 password.set_signon_realm(password_form.signon_realm); 383 password.set_signon_realm(password_form.signon_realm);
384 password.set_origin(password_form.origin.spec()); 384 password.set_origin(password_form.origin.spec());
385 password.set_action(password_form.action.spec()); 385 password.set_action(password_form.action.spec());
386 password.set_username_element(UTF16ToUTF8(password_form.username_element)); 386 password.set_username_element(UTF16ToUTF8(password_form.username_element));
387 password.set_password_element(UTF16ToUTF8(password_form.password_element)); 387 password.set_password_element(UTF16ToUTF8(password_form.password_element));
388 password.set_username_value(UTF16ToUTF8(password_form.username_value)); 388 password.set_username_value(UTF16ToUTF8(password_form.username_value));
389 password.set_password_value(UTF16ToUTF8(password_form.password_value)); 389 password.set_password_value(UTF16ToUTF8(password_form.password_value));
390 password.set_ssl_valid(password_form.ssl_valid); 390 password.set_ssl_valid(password_form.ssl_valid);
391 password.set_preferred(password_form.preferred); 391 password.set_preferred(password_form.preferred);
392 password.set_date_created(password_form.date_created.ToInternalValue()); 392 password.set_date_created(password_form.date_created.ToInternalValue());
393 password.set_blacklisted(password_form.blacklisted_by_user); 393 password.set_blacklisted(password_form.blacklisted_by_user);
394 394
395 node->SetPasswordSpecifics(password); 395 node->SetPasswordSpecifics(password);
396 } 396 }
397 397
398 // static 398 // static
399 std::string PasswordModelAssociator::MakeTag( 399 std::string PasswordModelAssociator::MakeTag(
400 const webkit_glue::PasswordForm& password) { 400 const webkit::forms::PasswordForm& password) {
401 return MakeTag(password.origin.spec(), 401 return MakeTag(password.origin.spec(),
402 UTF16ToUTF8(password.username_element), 402 UTF16ToUTF8(password.username_element),
403 UTF16ToUTF8(password.username_value), 403 UTF16ToUTF8(password.username_value),
404 UTF16ToUTF8(password.password_element), 404 UTF16ToUTF8(password.password_element),
405 password.signon_realm); 405 password.signon_realm);
406 } 406 }
407 407
408 // static 408 // static
409 std::string PasswordModelAssociator::MakeTag( 409 std::string PasswordModelAssociator::MakeTag(
410 const sync_pb::PasswordSpecificsData& password) { 410 const sync_pb::PasswordSpecificsData& password) {
(...skipping 12 matching lines...) Expand all
423 const std::string& password_element, 423 const std::string& password_element,
424 const std::string& signon_realm) { 424 const std::string& signon_realm) {
425 return net::EscapePath(origin_url) + "|" + 425 return net::EscapePath(origin_url) + "|" +
426 net::EscapePath(username_element) + "|" + 426 net::EscapePath(username_element) + "|" +
427 net::EscapePath(username_value) + "|" + 427 net::EscapePath(username_value) + "|" +
428 net::EscapePath(password_element) + "|" + 428 net::EscapePath(password_element) + "|" +
429 net::EscapePath(signon_realm); 429 net::EscapePath(signon_realm);
430 } 430 }
431 431
432 } // namespace browser_sync 432 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_model_associator.h ('k') | chrome/browser/sync/profile_sync_service_password_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698