| OLD | NEW |
| 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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 for (std::vector<webkit::forms::PasswordForm*>::iterator ix = | 86 for (std::vector<webkit::forms::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(syncable::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 webkit::forms::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(syncable::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()); |
| 112 } | 112 } |
| 113 WriteToSyncNode(new_password, &write_node); | 113 WriteToSyncNode(new_password, &write_node); |
| 114 updated_passwords.push_back(new_password); | 114 updated_passwords.push_back(new_password); |
| 115 } | 115 } |
| 116 | 116 |
| 117 Associate(&tag, node.GetId()); | 117 Associate(&tag, node.GetId()); |
| 118 } else { | 118 } else { |
| 119 syncer::WriteNode node(&trans); | 119 syncer::WriteNode node(&trans); |
| 120 syncer::WriteNode::InitUniqueByCreationResult result = | 120 syncer::WriteNode::InitUniqueByCreationResult result = |
| 121 node.InitUniqueByCreation(syncable::PASSWORDS, password_root, tag); | 121 node.InitUniqueByCreation(syncer::PASSWORDS, password_root, tag); |
| 122 if (result != syncer::WriteNode::INIT_SUCCESS) { | 122 if (result != syncer::WriteNode::INIT_SUCCESS) { |
| 123 STLDeleteElements(&passwords); | 123 STLDeleteElements(&passwords); |
| 124 return error_handler_->CreateAndUploadError( | 124 return error_handler_->CreateAndUploadError( |
| 125 FROM_HERE, | 125 FROM_HERE, |
| 126 "Failed to create password sync node.", | 126 "Failed to create password sync node.", |
| 127 model_type()); | 127 model_type()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 WriteToSyncNode(**ix, &node); | 130 WriteToSyncNode(**ix, &node); |
| 131 | 131 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |