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

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

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "content/public/common/password_form.h"
14 #include "net/base/escape.h" 15 #include "net/base/escape.h"
15 #include "sync/api/sync_error.h" 16 #include "sync/api/sync_error.h"
16 #include "sync/internal_api/public/read_node.h" 17 #include "sync/internal_api/public/read_node.h"
17 #include "sync/internal_api/public/read_transaction.h" 18 #include "sync/internal_api/public/read_transaction.h"
18 #include "sync/internal_api/public/write_node.h" 19 #include "sync/internal_api/public/write_node.h"
19 #include "sync/internal_api/public/write_transaction.h" 20 #include "sync/internal_api/public/write_transaction.h"
20 #include "sync/protocol/password_specifics.pb.h" 21 #include "sync/protocol/password_specifics.pb.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 19 matching lines...) Expand all
51 syncer::SyncError error; 51 syncer::SyncError error;
52 DCHECK(expected_loop_ == MessageLoop::current()); 52 DCHECK(expected_loop_ == MessageLoop::current());
53 { 53 {
54 base::AutoLock lock(abort_association_pending_lock_); 54 base::AutoLock lock(abort_association_pending_lock_);
55 abort_association_pending_ = false; 55 abort_association_pending_ = false;
56 } 56 }
57 57
58 // We must not be holding a transaction when we interact with the password 58 // We must not be holding a transaction when we interact with the password
59 // store, as it can post tasks to the UI thread which can itself be blocked 59 // store, as it can post tasks to the UI thread which can itself be blocked
60 // on our transaction, resulting in deadlock. (http://crbug.com/70658) 60 // on our transaction, resulting in deadlock. (http://crbug.com/70658)
61 std::vector<webkit::forms::PasswordForm*> passwords; 61 std::vector<content::PasswordForm*> passwords;
62 if (!password_store_->FillAutofillableLogins(&passwords) || 62 if (!password_store_->FillAutofillableLogins(&passwords) ||
63 !password_store_->FillBlacklistLogins(&passwords)) { 63 !password_store_->FillBlacklistLogins(&passwords)) {
64 STLDeleteElements(&passwords); 64 STLDeleteElements(&passwords);
65 return error_handler_->CreateAndUploadError( 65 return error_handler_->CreateAndUploadError(
66 FROM_HERE, 66 FROM_HERE,
67 "Could not get the password entries.", 67 "Could not get the password entries.",
68 model_type()); 68 model_type());
69 } 69 }
70 70
71 std::set<std::string> current_passwords; 71 std::set<std::string> current_passwords;
72 PasswordVector new_passwords; 72 PasswordVector new_passwords;
73 PasswordVector updated_passwords; 73 PasswordVector updated_passwords;
74 { 74 {
75 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 75 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
76 syncer::ReadNode password_root(&trans); 76 syncer::ReadNode password_root(&trans);
77 if (password_root.InitByTagLookup(kPasswordTag) != 77 if (password_root.InitByTagLookup(kPasswordTag) !=
78 syncer::BaseNode::INIT_OK) { 78 syncer::BaseNode::INIT_OK) {
79 return error_handler_->CreateAndUploadError( 79 return error_handler_->CreateAndUploadError(
80 FROM_HERE, 80 FROM_HERE,
81 "Server did not create the top-level password node. We " 81 "Server did not create the top-level password node. We "
82 "might be running against an out-of-date server.", 82 "might be running against an out-of-date server.",
83 model_type()); 83 model_type());
84 } 84 }
85 85
86 for (std::vector<webkit::forms::PasswordForm*>::iterator ix = 86 for (std::vector<content::PasswordForm*>::iterator ix =
87 passwords.begin(); 87 passwords.begin();
88 ix != passwords.end(); ++ix) { 88 ix != passwords.end(); ++ix) {
89 if (IsAbortPending()) { 89 if (IsAbortPending()) {
90 return syncer::SyncError(); 90 return syncer::SyncError();
91 } 91 }
92 std::string tag = MakeTag(**ix); 92 std::string tag = MakeTag(**ix);
93 93
94 syncer::ReadNode node(&trans); 94 syncer::ReadNode node(&trans);
95 if (node.InitByClientTagLookup(syncer::PASSWORDS, tag) == 95 if (node.InitByClientTagLookup(syncer::PASSWORDS, tag) ==
96 syncer::BaseNode::INIT_OK) { 96 syncer::BaseNode::INIT_OK) {
97 const sync_pb::PasswordSpecificsData& password = 97 const sync_pb::PasswordSpecificsData& password =
98 node.GetPasswordSpecifics(); 98 node.GetPasswordSpecifics();
99 DCHECK_EQ(tag, MakeTag(password)); 99 DCHECK_EQ(tag, MakeTag(password));
100 100
101 webkit::forms::PasswordForm new_password; 101 content::PasswordForm new_password;
102 102
103 if (MergePasswords(password, **ix, &new_password)) { 103 if (MergePasswords(password, **ix, &new_password)) {
104 syncer::WriteNode write_node(&trans); 104 syncer::WriteNode write_node(&trans);
105 if (write_node.InitByClientTagLookup(syncer::PASSWORDS, tag) != 105 if (write_node.InitByClientTagLookup(syncer::PASSWORDS, tag) !=
106 syncer::BaseNode::INIT_OK) { 106 syncer::BaseNode::INIT_OK) {
107 STLDeleteElements(&passwords); 107 STLDeleteElements(&passwords);
108 return error_handler_->CreateAndUploadError( 108 return error_handler_->CreateAndUploadError(
109 FROM_HERE, 109 FROM_HERE,
110 "Failed to edit password sync node.", 110 "Failed to edit password sync node.",
111 model_type()); 111 model_type());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 "Failed to fetch child node.", 147 "Failed to fetch child node.",
148 model_type()); 148 model_type());
149 } 149 }
150 const sync_pb::PasswordSpecificsData& password = 150 const sync_pb::PasswordSpecificsData& password =
151 sync_child_node.GetPasswordSpecifics(); 151 sync_child_node.GetPasswordSpecifics();
152 std::string tag = MakeTag(password); 152 std::string tag = MakeTag(password);
153 153
154 // The password only exists on the server. Add it to the local 154 // The password only exists on the server. Add it to the local
155 // model. 155 // model.
156 if (current_passwords.find(tag) == current_passwords.end()) { 156 if (current_passwords.find(tag) == current_passwords.end()) {
157 webkit::forms::PasswordForm new_password; 157 content::PasswordForm new_password;
158 158
159 CopyPassword(password, &new_password); 159 CopyPassword(password, &new_password);
160 Associate(&tag, sync_child_node.GetId()); 160 Associate(&tag, sync_child_node.GetId());
161 new_passwords.push_back(new_password); 161 new_passwords.push_back(new_password);
162 } 162 }
163 163
164 sync_child_id = sync_child_node.GetSuccessorId(); 164 sync_child_id = sync_child_node.GetSuccessorId();
165 } 165 }
166 } 166 }
167 167
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // We have to notify password store observers of the change by hand since 321 // We have to notify password store observers of the change by hand since
322 // we use internal password store interfaces to make changes synchronously. 322 // we use internal password store interfaces to make changes synchronously.
323 password_store_->PostNotifyLoginsChanged(); 323 password_store_->PostNotifyLoginsChanged();
324 } 324 }
325 return syncer::SyncError(); 325 return syncer::SyncError();
326 } 326 }
327 327
328 // static 328 // static
329 void PasswordModelAssociator::CopyPassword( 329 void PasswordModelAssociator::CopyPassword(
330 const sync_pb::PasswordSpecificsData& password, 330 const sync_pb::PasswordSpecificsData& password,
331 webkit::forms::PasswordForm* new_password) { 331 content::PasswordForm* new_password) {
332 new_password->scheme = 332 new_password->scheme =
333 static_cast<webkit::forms::PasswordForm::Scheme>(password.scheme()); 333 static_cast<content::PasswordForm::Scheme>(password.scheme());
334 new_password->signon_realm = password.signon_realm(); 334 new_password->signon_realm = password.signon_realm();
335 new_password->origin = GURL(password.origin()); 335 new_password->origin = GURL(password.origin());
336 new_password->action = GURL(password.action()); 336 new_password->action = GURL(password.action());
337 new_password->username_element = 337 new_password->username_element =
338 UTF8ToUTF16(password.username_element()); 338 UTF8ToUTF16(password.username_element());
339 new_password->password_element = 339 new_password->password_element =
340 UTF8ToUTF16(password.password_element()); 340 UTF8ToUTF16(password.password_element());
341 new_password->username_value = 341 new_password->username_value =
342 UTF8ToUTF16(password.username_value()); 342 UTF8ToUTF16(password.username_value());
343 new_password->password_value = 343 new_password->password_value =
344 UTF8ToUTF16(password.password_value()); 344 UTF8ToUTF16(password.password_value());
345 new_password->ssl_valid = password.ssl_valid(); 345 new_password->ssl_valid = password.ssl_valid();
346 new_password->preferred = password.preferred(); 346 new_password->preferred = password.preferred();
347 new_password->date_created = 347 new_password->date_created =
348 base::Time::FromInternalValue(password.date_created()); 348 base::Time::FromInternalValue(password.date_created());
349 new_password->blacklisted_by_user = 349 new_password->blacklisted_by_user =
350 password.blacklisted(); 350 password.blacklisted();
351 } 351 }
352 352
353 // static 353 // static
354 bool PasswordModelAssociator::MergePasswords( 354 bool PasswordModelAssociator::MergePasswords(
355 const sync_pb::PasswordSpecificsData& password, 355 const sync_pb::PasswordSpecificsData& password,
356 const webkit::forms::PasswordForm& password_form, 356 const content::PasswordForm& password_form,
357 webkit::forms::PasswordForm* new_password) { 357 content::PasswordForm* new_password) {
358 DCHECK(new_password); 358 DCHECK(new_password);
359 359
360 if (password.scheme() == password_form.scheme && 360 if (password.scheme() == password_form.scheme &&
361 password_form.signon_realm == password.signon_realm() && 361 password_form.signon_realm == password.signon_realm() &&
362 password_form.origin.spec() == password.origin() && 362 password_form.origin.spec() == password.origin() &&
363 password_form.action.spec() == password.action() && 363 password_form.action.spec() == password.action() &&
364 UTF16ToUTF8(password_form.username_element) == 364 UTF16ToUTF8(password_form.username_element) ==
365 password.username_element() && 365 password.username_element() &&
366 UTF16ToUTF8(password_form.password_element) == 366 UTF16ToUTF8(password_form.password_element) ==
367 password.password_element() && 367 password.password_element() &&
(...skipping 14 matching lines...) Expand all
382 *new_password = password_form; 382 *new_password = password_form;
383 } else { 383 } else {
384 CopyPassword(password, new_password); 384 CopyPassword(password, new_password);
385 } 385 }
386 386
387 return true; 387 return true;
388 } 388 }
389 389
390 // static 390 // static
391 void PasswordModelAssociator::WriteToSyncNode( 391 void PasswordModelAssociator::WriteToSyncNode(
392 const webkit::forms::PasswordForm& password_form, 392 const content::PasswordForm& password_form,
393 syncer::WriteNode* node) { 393 syncer::WriteNode* node) {
394 sync_pb::PasswordSpecificsData password; 394 sync_pb::PasswordSpecificsData password;
395 password.set_scheme(password_form.scheme); 395 password.set_scheme(password_form.scheme);
396 password.set_signon_realm(password_form.signon_realm); 396 password.set_signon_realm(password_form.signon_realm);
397 password.set_origin(password_form.origin.spec()); 397 password.set_origin(password_form.origin.spec());
398 password.set_action(password_form.action.spec()); 398 password.set_action(password_form.action.spec());
399 password.set_username_element(UTF16ToUTF8(password_form.username_element)); 399 password.set_username_element(UTF16ToUTF8(password_form.username_element));
400 password.set_password_element(UTF16ToUTF8(password_form.password_element)); 400 password.set_password_element(UTF16ToUTF8(password_form.password_element));
401 password.set_username_value(UTF16ToUTF8(password_form.username_value)); 401 password.set_username_value(UTF16ToUTF8(password_form.username_value));
402 password.set_password_value(UTF16ToUTF8(password_form.password_value)); 402 password.set_password_value(UTF16ToUTF8(password_form.password_value));
403 password.set_ssl_valid(password_form.ssl_valid); 403 password.set_ssl_valid(password_form.ssl_valid);
404 password.set_preferred(password_form.preferred); 404 password.set_preferred(password_form.preferred);
405 password.set_date_created(password_form.date_created.ToInternalValue()); 405 password.set_date_created(password_form.date_created.ToInternalValue());
406 password.set_blacklisted(password_form.blacklisted_by_user); 406 password.set_blacklisted(password_form.blacklisted_by_user);
407 407
408 node->SetPasswordSpecifics(password); 408 node->SetPasswordSpecifics(password);
409 } 409 }
410 410
411 // static 411 // static
412 std::string PasswordModelAssociator::MakeTag( 412 std::string PasswordModelAssociator::MakeTag(
413 const webkit::forms::PasswordForm& password) { 413 const content::PasswordForm& password) {
414 return MakeTag(password.origin.spec(), 414 return MakeTag(password.origin.spec(),
415 UTF16ToUTF8(password.username_element), 415 UTF16ToUTF8(password.username_element),
416 UTF16ToUTF8(password.username_value), 416 UTF16ToUTF8(password.username_value),
417 UTF16ToUTF8(password.password_element), 417 UTF16ToUTF8(password.password_element),
418 password.signon_realm); 418 password.signon_realm);
419 } 419 }
420 420
421 // static 421 // static
422 std::string PasswordModelAssociator::MakeTag( 422 std::string PasswordModelAssociator::MakeTag(
423 const sync_pb::PasswordSpecificsData& password) { 423 const sync_pb::PasswordSpecificsData& password) {
(...skipping 12 matching lines...) Expand all
436 const std::string& password_element, 436 const std::string& password_element,
437 const std::string& signon_realm) { 437 const std::string& signon_realm) {
438 return net::EscapePath(origin_url) + "|" + 438 return net::EscapePath(origin_url) + "|" +
439 net::EscapePath(username_element) + "|" + 439 net::EscapePath(username_element) + "|" +
440 net::EscapePath(username_value) + "|" + 440 net::EscapePath(username_value) + "|" +
441 net::EscapePath(password_element) + "|" + 441 net::EscapePath(password_element) + "|" +
442 net::EscapePath(signon_realm); 442 net::EscapePath(signon_realm);
443 } 443 }
444 444
445 } // namespace browser_sync 445 } // 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