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

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

Issue 10152003: sync: Make BaseNode lookup-related Init functions return specific failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 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 | Annotate | Revision Log
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"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 75 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
76 sync_api::ReadNode password_root(&trans); 76 sync_api::ReadNode password_root(&trans);
77 if (!password_root.InitByTagLookup(kPasswordTag)) { 77 if (password_root.InitByTagLookup(kPasswordTag) !=
78 sync_api::BaseNode::INIT_OK) {
78 return error_handler_->CreateAndUploadError( 79 return error_handler_->CreateAndUploadError(
79 FROM_HERE, 80 FROM_HERE,
80 "Server did not create the top-level password node. We " 81 "Server did not create the top-level password node. We "
81 "might be running against an out-of-date server.", 82 "might be running against an out-of-date server.",
82 model_type()); 83 model_type());
83 } 84 }
84 85
85 for (std::vector<webkit::forms::PasswordForm*>::iterator ix = 86 for (std::vector<webkit::forms::PasswordForm*>::iterator ix =
86 passwords.begin(); 87 passwords.begin();
87 ix != passwords.end(); ++ix) { 88 ix != passwords.end(); ++ix) {
88 if (IsAbortPending()) { 89 if (IsAbortPending()) {
89 return SyncError(); 90 return SyncError();
90 } 91 }
91 std::string tag = MakeTag(**ix); 92 std::string tag = MakeTag(**ix);
92 93
93 sync_api::ReadNode node(&trans); 94 sync_api::ReadNode node(&trans);
94 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { 95 if (node.InitByClientTagLookup(syncable::PASSWORDS, tag) ==
96 sync_api::BaseNode::INIT_OK) {
95 const sync_pb::PasswordSpecificsData& password = 97 const sync_pb::PasswordSpecificsData& password =
96 node.GetPasswordSpecifics(); 98 node.GetPasswordSpecifics();
97 DCHECK_EQ(tag, MakeTag(password)); 99 DCHECK_EQ(tag, MakeTag(password));
98 100
99 webkit::forms::PasswordForm new_password; 101 webkit::forms::PasswordForm new_password;
100 102
101 if (MergePasswords(password, **ix, &new_password)) { 103 if (MergePasswords(password, **ix, &new_password)) {
102 sync_api::WriteNode write_node(&trans); 104 sync_api::WriteNode write_node(&trans);
103 if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { 105 if (write_node.InitByClientTagLookup(syncable::PASSWORDS, tag) !=
106 sync_api::BaseNode::INIT_OK) {
104 STLDeleteElements(&passwords); 107 STLDeleteElements(&passwords);
105 return error_handler_->CreateAndUploadError( 108 return error_handler_->CreateAndUploadError(
106 FROM_HERE, 109 FROM_HERE,
107 "Failed to edit password sync node.", 110 "Failed to edit password sync node.",
108 model_type()); 111 model_type());
109 } 112 }
110 WriteToSyncNode(new_password, &write_node); 113 WriteToSyncNode(new_password, &write_node);
111 updated_passwords.push_back(new_password); 114 updated_passwords.push_back(new_password);
112 } 115 }
113 116
(...skipping 15 matching lines...) Expand all
129 } 132 }
130 133
131 current_passwords.insert(tag); 134 current_passwords.insert(tag);
132 } 135 }
133 136
134 STLDeleteElements(&passwords); 137 STLDeleteElements(&passwords);
135 138
136 int64 sync_child_id = password_root.GetFirstChildId(); 139 int64 sync_child_id = password_root.GetFirstChildId();
137 while (sync_child_id != sync_api::kInvalidId) { 140 while (sync_child_id != sync_api::kInvalidId) {
138 sync_api::ReadNode sync_child_node(&trans); 141 sync_api::ReadNode sync_child_node(&trans);
139 if (!sync_child_node.InitByIdLookup(sync_child_id)) { 142 if (sync_child_node.InitByIdLookup(sync_child_id) !=
143 sync_api::BaseNode::INIT_OK) {
140 return error_handler_->CreateAndUploadError( 144 return error_handler_->CreateAndUploadError(
141 FROM_HERE, 145 FROM_HERE,
142 "Failed to fetch child node.", 146 "Failed to fetch child node.",
143 model_type()); 147 model_type());
144 } 148 }
145 const sync_pb::PasswordSpecificsData& password = 149 const sync_pb::PasswordSpecificsData& password =
146 sync_child_node.GetPasswordSpecifics(); 150 sync_child_node.GetPasswordSpecifics();
147 std::string tag = MakeTag(password); 151 std::string tag = MakeTag(password);
148 152
149 // The password only exists on the server. Add it to the local 153 // The password only exists on the server. Add it to the local
(...skipping 22 matching lines...) Expand all
172 176
173 return error; 177 return error;
174 } 178 }
175 179
176 bool PasswordModelAssociator::DeleteAllNodes( 180 bool PasswordModelAssociator::DeleteAllNodes(
177 sync_api::WriteTransaction* trans) { 181 sync_api::WriteTransaction* trans) {
178 DCHECK(expected_loop_ == MessageLoop::current()); 182 DCHECK(expected_loop_ == MessageLoop::current());
179 for (PasswordToSyncIdMap::iterator node_id = id_map_.begin(); 183 for (PasswordToSyncIdMap::iterator node_id = id_map_.begin();
180 node_id != id_map_.end(); ++node_id) { 184 node_id != id_map_.end(); ++node_id) {
181 sync_api::WriteNode sync_node(trans); 185 sync_api::WriteNode sync_node(trans);
182 if (!sync_node.InitByIdLookup(node_id->second)) { 186 if (sync_node.InitByIdLookup(node_id->second) !=
187 sync_api::BaseNode::INIT_OK) {
183 LOG(ERROR) << "Typed url node lookup failed."; 188 LOG(ERROR) << "Typed url node lookup failed.";
184 return false; 189 return false;
185 } 190 }
186 sync_node.Remove(); 191 sync_node.Remove();
187 } 192 }
188 193
189 id_map_.clear(); 194 id_map_.clear();
190 id_map_inverse_.clear(); 195 id_map_inverse_.clear();
191 return true; 196 return true;
192 } 197 }
193 198
194 SyncError PasswordModelAssociator::DisassociateModels() { 199 SyncError PasswordModelAssociator::DisassociateModels() {
195 id_map_.clear(); 200 id_map_.clear();
196 id_map_inverse_.clear(); 201 id_map_inverse_.clear();
197 return SyncError(); 202 return SyncError();
198 } 203 }
199 204
200 bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { 205 bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
201 DCHECK(has_nodes); 206 DCHECK(has_nodes);
202 *has_nodes = false; 207 *has_nodes = false;
203 int64 password_sync_id; 208 int64 password_sync_id;
204 if (!GetSyncIdForTaggedNode(kPasswordTag, &password_sync_id)) { 209 if (!GetSyncIdForTaggedNode(kPasswordTag, &password_sync_id)) {
205 LOG(ERROR) << "Server did not create the top-level password node. We " 210 LOG(ERROR) << "Server did not create the top-level password node. We "
206 << "might be running against an out-of-date server."; 211 << "might be running against an out-of-date server.";
207 return false; 212 return false;
208 } 213 }
209 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 214 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
210 215
211 sync_api::ReadNode password_node(&trans); 216 sync_api::ReadNode password_node(&trans);
212 if (!password_node.InitByIdLookup(password_sync_id)) { 217 if (password_node.InitByIdLookup(password_sync_id) !=
218 sync_api::BaseNode::INIT_OK) {
213 LOG(ERROR) << "Server did not create the top-level password node. We " 219 LOG(ERROR) << "Server did not create the top-level password node. We "
214 << "might be running against an out-of-date server."; 220 << "might be running against an out-of-date server.";
215 return false; 221 return false;
216 } 222 }
217 223
218 // The sync model has user created nodes if the password folder has any 224 // The sync model has user created nodes if the password folder has any
219 // children. 225 // children.
220 *has_nodes = password_node.HasChildren(); 226 *has_nodes = password_node.HasChildren();
221 return true; 227 return true;
222 } 228 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (iter == id_map_inverse_.end()) 278 if (iter == id_map_inverse_.end())
273 return; 279 return;
274 CHECK(id_map_.erase(iter->second)); 280 CHECK(id_map_.erase(iter->second));
275 id_map_inverse_.erase(iter); 281 id_map_inverse_.erase(iter);
276 } 282 }
277 283
278 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, 284 bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
279 int64* sync_id) { 285 int64* sync_id) {
280 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 286 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
281 sync_api::ReadNode sync_node(&trans); 287 sync_api::ReadNode sync_node(&trans);
282 if (!sync_node.InitByTagLookup(tag.c_str())) 288 if (sync_node.InitByTagLookup(tag.c_str()) != sync_api::BaseNode::INIT_OK)
283 return false; 289 return false;
284 *sync_id = sync_node.GetId(); 290 *sync_id = sync_node.GetId();
285 return true; 291 return true;
286 } 292 }
287 293
288 SyncError PasswordModelAssociator::WriteToPasswordStore( 294 SyncError PasswordModelAssociator::WriteToPasswordStore(
289 const PasswordVector* new_passwords, 295 const PasswordVector* new_passwords,
290 const PasswordVector* updated_passwords, 296 const PasswordVector* updated_passwords,
291 const PasswordVector* deleted_passwords) { 297 const PasswordVector* deleted_passwords) {
292 if (new_passwords) { 298 if (new_passwords) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 const std::string& password_element, 435 const std::string& password_element,
430 const std::string& signon_realm) { 436 const std::string& signon_realm) {
431 return net::EscapePath(origin_url) + "|" + 437 return net::EscapePath(origin_url) + "|" +
432 net::EscapePath(username_element) + "|" + 438 net::EscapePath(username_element) + "|" +
433 net::EscapePath(username_value) + "|" + 439 net::EscapePath(username_value) + "|" +
434 net::EscapePath(password_element) + "|" + 440 net::EscapePath(password_element) + "|" +
435 net::EscapePath(signon_realm); 441 net::EscapePath(signon_realm);
436 } 442 }
437 443
438 } // namespace browser_sync 444 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_change_processor.cc ('k') | chrome/browser/sync/glue/session_change_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698