| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 PasswordVector updated_passwords; | 66 PasswordVector updated_passwords; |
| 67 | 67 |
| 68 for (std::vector<webkit_glue::PasswordForm*>::iterator ix = passwords.begin(); | 68 for (std::vector<webkit_glue::PasswordForm*>::iterator ix = passwords.begin(); |
| 69 ix != passwords.end(); ++ix) { | 69 ix != passwords.end(); ++ix) { |
| 70 if (IsAbortPending()) | 70 if (IsAbortPending()) |
| 71 return false; | 71 return false; |
| 72 std::string tag = MakeTag(**ix); | 72 std::string tag = MakeTag(**ix); |
| 73 | 73 |
| 74 sync_api::ReadNode node(&trans); | 74 sync_api::ReadNode node(&trans); |
| 75 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { | 75 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { |
| 76 sync_pb::PasswordSpecificsData password; | 76 const sync_pb::PasswordSpecificsData& password = |
| 77 if (!node.GetPasswordSpecifics(&password)) { | 77 node.GetPasswordSpecifics(); |
| 78 STLDeleteElements(&passwords); | |
| 79 LOG(ERROR) << "Failed to get password specifics from sync node."; | |
| 80 return false; | |
| 81 } | |
| 82 DCHECK_EQ(tag, MakeTag(password)); | 78 DCHECK_EQ(tag, MakeTag(password)); |
| 83 | 79 |
| 84 webkit_glue::PasswordForm new_password; | 80 webkit_glue::PasswordForm new_password; |
| 85 | 81 |
| 86 if (MergePasswords(password, **ix, &new_password)) { | 82 if (MergePasswords(password, **ix, &new_password)) { |
| 87 sync_api::WriteNode write_node(&trans); | 83 sync_api::WriteNode write_node(&trans); |
| 88 if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { | 84 if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { |
| 89 STLDeleteElements(&passwords); | 85 STLDeleteElements(&passwords); |
| 90 LOG(ERROR) << "Failed to edit password sync node."; | 86 LOG(ERROR) << "Failed to edit password sync node."; |
| 91 return false; | 87 return false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 | 110 |
| 115 STLDeleteElements(&passwords); | 111 STLDeleteElements(&passwords); |
| 116 | 112 |
| 117 int64 sync_child_id = password_root.GetFirstChildId(); | 113 int64 sync_child_id = password_root.GetFirstChildId(); |
| 118 while (sync_child_id != sync_api::kInvalidId) { | 114 while (sync_child_id != sync_api::kInvalidId) { |
| 119 sync_api::ReadNode sync_child_node(&trans); | 115 sync_api::ReadNode sync_child_node(&trans); |
| 120 if (!sync_child_node.InitByIdLookup(sync_child_id)) { | 116 if (!sync_child_node.InitByIdLookup(sync_child_id)) { |
| 121 LOG(ERROR) << "Failed to fetch child node."; | 117 LOG(ERROR) << "Failed to fetch child node."; |
| 122 return false; | 118 return false; |
| 123 } | 119 } |
| 124 sync_pb::PasswordSpecificsData password; | 120 const sync_pb::PasswordSpecificsData& password = |
| 125 if (!sync_child_node.GetPasswordSpecifics(&password)) { | 121 sync_child_node.GetPasswordSpecifics(); |
| 126 LOG(ERROR) << "Failed to get specifics from password node."; | |
| 127 return false; | |
| 128 } | |
| 129 std::string tag = MakeTag(password); | 122 std::string tag = MakeTag(password); |
| 130 | 123 |
| 131 // The password only exists on the server. Add it to the local | 124 // The password only exists on the server. Add it to the local |
| 132 // model. | 125 // model. |
| 133 if (current_passwords.find(tag) == current_passwords.end()) { | 126 if (current_passwords.find(tag) == current_passwords.end()) { |
| 134 webkit_glue::PasswordForm new_password; | 127 webkit_glue::PasswordForm new_password; |
| 135 | 128 |
| 136 CopyPassword(password, &new_password); | 129 CopyPassword(password, &new_password); |
| 137 Associate(&tag, sync_child_node.GetId()); | 130 Associate(&tag, sync_child_node.GetId()); |
| 138 new_passwords.push_back(new_password); | 131 new_passwords.push_back(new_password); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 const std::string& password_element, | 391 const std::string& password_element, |
| 399 const std::string& signon_realm) { | 392 const std::string& signon_realm) { |
| 400 return EscapePath(origin_url) + "|" + | 393 return EscapePath(origin_url) + "|" + |
| 401 EscapePath(username_element) + "|" + | 394 EscapePath(username_element) + "|" + |
| 402 EscapePath(username_value) + "|" + | 395 EscapePath(username_value) + "|" + |
| 403 EscapePath(password_element) + "|" + | 396 EscapePath(password_element) + "|" + |
| 404 EscapePath(signon_realm); | 397 EscapePath(signon_realm); |
| 405 } | 398 } |
| 406 | 399 |
| 407 } // namespace browser_sync | 400 } // namespace browser_sync |
| OLD | NEW |