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/internal_api/write_node.h" | 5 #include "chrome/browser/sync/internal_api/write_node.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/sync/internal_api/syncapi_internal.h" | 9 #include "chrome/browser/sync/internal_api/syncapi_internal.h" |
10 #include "chrome/browser/sync/internal_api/base_transaction.h" | 10 #include "chrome/browser/sync/internal_api/base_transaction.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 : entry_(NULL), transaction_(transaction) { | 258 : entry_(NULL), transaction_(transaction) { |
259 DCHECK(transaction); | 259 DCHECK(transaction); |
260 } | 260 } |
261 | 261 |
262 WriteNode::~WriteNode() { | 262 WriteNode::~WriteNode() { |
263 delete entry_; | 263 delete entry_; |
264 } | 264 } |
265 | 265 |
266 // Find an existing node matching the ID |id|, and bind this WriteNode to it. | 266 // Find an existing node matching the ID |id|, and bind this WriteNode to it. |
267 // Return true on success. | 267 // Return true on success. |
268 bool WriteNode::InitByIdLookup(int64 id) { | 268 BaseNode::InitByLookupResult WriteNode::InitByIdLookup(int64 id) { |
269 DCHECK(!entry_) << "Init called twice"; | 269 DCHECK(!entry_) << "Init called twice"; |
270 DCHECK_NE(id, kInvalidId); | 270 DCHECK_NE(id, kInvalidId); |
271 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 271 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
272 syncable::GET_BY_HANDLE, id); | 272 syncable::GET_BY_HANDLE, id); |
273 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && | 273 if (!entry_->good()) |
274 DecryptIfNecessary()); | 274 return INIT_FAILED_ENTRY_NOT_GOOD; |
| 275 if (entry_->Get(syncable::IS_DEL)) |
| 276 return INIT_FAILED_ENTRY_IS_DEL; |
| 277 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; |
275 } | 278 } |
276 | 279 |
277 // Find a node by client tag, and bind this WriteNode to it. | 280 // Find a node by client tag, and bind this WriteNode to it. |
278 // Return true if the write node was found, and was not deleted. | 281 // Return true if the write node was found, and was not deleted. |
279 // Undeleting a deleted node is possible by ClientTag. | 282 // Undeleting a deleted node is possible by ClientTag. |
280 bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type, | 283 BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup( |
281 const std::string& tag) { | 284 syncable::ModelType model_type, |
| 285 const std::string& tag) { |
282 DCHECK(!entry_) << "Init called twice"; | 286 DCHECK(!entry_) << "Init called twice"; |
283 if (tag.empty()) | 287 if (tag.empty()) |
284 return false; | 288 return INIT_FAILED_PRECONDITION; |
285 | 289 |
286 const std::string hash = GenerateSyncableHash(model_type, tag); | 290 const std::string hash = GenerateSyncableHash(model_type, tag); |
287 | 291 |
288 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 292 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
289 syncable::GET_BY_CLIENT_TAG, hash); | 293 syncable::GET_BY_CLIENT_TAG, hash); |
290 return (entry_->good() && !entry_->Get(syncable::IS_DEL) && | 294 if (!entry_->good()) |
291 DecryptIfNecessary()); | 295 return INIT_FAILED_ENTRY_NOT_GOOD; |
| 296 if (entry_->Get(syncable::IS_DEL)) |
| 297 return INIT_FAILED_ENTRY_IS_DEL; |
| 298 return DecryptIfNecessary() ? INIT_OK : INIT_FAILED_DECRYPT_IF_NECESSARY; |
292 } | 299 } |
293 | 300 |
294 bool WriteNode::InitByTagLookup(const std::string& tag) { | 301 BaseNode::InitByLookupResult WriteNode::InitByTagLookup( |
| 302 const std::string& tag) { |
295 DCHECK(!entry_) << "Init called twice"; | 303 DCHECK(!entry_) << "Init called twice"; |
296 if (tag.empty()) | 304 if (tag.empty()) |
297 return false; | 305 return INIT_FAILED_PRECONDITION; |
298 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 306 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
299 syncable::GET_BY_SERVER_TAG, tag); | 307 syncable::GET_BY_SERVER_TAG, tag); |
300 if (!entry_->good()) | 308 if (!entry_->good()) |
301 return false; | 309 return INIT_FAILED_ENTRY_NOT_GOOD; |
302 if (entry_->Get(syncable::IS_DEL)) | 310 if (entry_->Get(syncable::IS_DEL)) |
303 return false; | 311 return INIT_FAILED_ENTRY_IS_DEL; |
304 syncable::ModelType model_type = GetModelType(); | 312 syncable::ModelType model_type = GetModelType(); |
305 DCHECK_EQ(syncable::NIGORI, model_type); | 313 DCHECK_EQ(syncable::NIGORI, model_type); |
306 return true; | 314 return INIT_OK; |
307 } | 315 } |
308 | 316 |
309 void WriteNode::PutModelType(syncable::ModelType model_type) { | 317 void WriteNode::PutModelType(syncable::ModelType model_type) { |
310 // Set an empty specifics of the appropriate datatype. The presence | 318 // Set an empty specifics of the appropriate datatype. The presence |
311 // of the specific field will identify the model type. | 319 // of the specific field will identify the model type. |
312 DCHECK(GetModelType() == model_type || | 320 DCHECK(GetModelType() == model_type || |
313 GetModelType() == syncable::UNSPECIFIED); // Immutable once set. | 321 GetModelType() == syncable::UNSPECIFIED); // Immutable once set. |
314 | 322 |
315 sync_pb::EntitySpecifics specifics; | 323 sync_pb::EntitySpecifics specifics; |
316 syncable::AddDefaultFieldValue(model_type, &specifics); | 324 syncable::AddDefaultFieldValue(model_type, &specifics); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 494 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
487 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 495 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
488 SetBookmarkSpecifics(new_value); | 496 SetBookmarkSpecifics(new_value); |
489 } | 497 } |
490 | 498 |
491 void WriteNode::MarkForSyncing() { | 499 void WriteNode::MarkForSyncing() { |
492 syncable::MarkForSyncing(entry_); | 500 syncable::MarkForSyncing(entry_); |
493 } | 501 } |
494 | 502 |
495 } // namespace sync_api | 503 } // namespace sync_api |
OLD | NEW |