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 "sync/internal_api/write_node.h" | 5 #include "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 "sync/engine/nigori_util.h" | 9 #include "sync/engine/nigori_util.h" |
10 #include "sync/internal_api/base_transaction.h" | 10 #include "sync/internal_api/base_transaction.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 // Now set the predecessor, which sets IS_UNSYNCED as necessary. | 357 // Now set the predecessor, which sets IS_UNSYNCED as necessary. |
358 return PutPredecessor(predecessor); | 358 return PutPredecessor(predecessor); |
359 } | 359 } |
360 | 360 |
361 // Create a new node with default properties and a client defined unique tag, | 361 // Create a new node with default properties and a client defined unique tag, |
362 // and bind this WriteNode to it. | 362 // and bind this WriteNode to it. |
363 // Return true on success. If the tag exists in the database, then | 363 // Return true on success. If the tag exists in the database, then |
364 // we will attempt to undelete the node. | 364 // we will attempt to undelete the node. |
365 // TODO(chron): Code datatype into hash tag. | 365 // TODO(chron): Code datatype into hash tag. |
366 // TODO(chron): Is model type ever lost? | 366 // TODO(chron): Is model type ever lost? |
367 bool WriteNode::InitUniqueByCreation(syncable::ModelType model_type, | 367 WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation( |
368 const BaseNode& parent, | 368 syncable::ModelType model_type, |
369 const std::string& tag) { | 369 const BaseNode& parent, |
370 DCHECK(!entry_) << "Init called twice"; | 370 const std::string& tag) { |
371 // This DCHECK will only fail if init is called twice. | |
tim (not reviewing)
2012/05/17 00:22:10
Is there a reason to not stream this to the dcheck
Ilya Sherman
2012/05/17 00:40:04
I removed the streaming based on this thread: [1 (
| |
372 DCHECK(!entry_); | |
371 if (tag.empty()) { | 373 if (tag.empty()) { |
372 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag."; | 374 LOG(WARNING) << "InitUniqueByCreation failed due to empty tag."; |
373 return false; | 375 return INIT_FAILED_EMPTY_TAG; |
374 } | 376 } |
375 | 377 |
376 const std::string hash = GenerateSyncableHash(model_type, tag); | 378 const std::string hash = GenerateSyncableHash(model_type, tag); |
377 | 379 |
378 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID); | 380 syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID); |
379 | 381 |
380 // Start out with a dummy name. We expect | 382 // Start out with a dummy name. We expect |
381 // the caller to set a meaningful name after creation. | 383 // the caller to set a meaningful name after creation. |
382 string dummy(kDefaultNameForNewNodes); | 384 string dummy(kDefaultNameForNewNodes); |
383 | 385 |
(...skipping 24 matching lines...) Expand all Loading... | |
408 // Client tags are immutable and must be paired with the ID. | 410 // Client tags are immutable and must be paired with the ID. |
409 // If a server update comes down with an ID and client tag combo, | 411 // If a server update comes down with an ID and client tag combo, |
410 // and it already exists, always overwrite it and store only one copy. | 412 // and it already exists, always overwrite it and store only one copy. |
411 // We have to undelete entries because we can't disassociate IDs from | 413 // We have to undelete entries because we can't disassociate IDs from |
412 // tags and updates. | 414 // tags and updates. |
413 | 415 |
414 existing_entry->Put(syncable::NON_UNIQUE_NAME, dummy); | 416 existing_entry->Put(syncable::NON_UNIQUE_NAME, dummy); |
415 existing_entry->Put(syncable::PARENT_ID, parent_id); | 417 existing_entry->Put(syncable::PARENT_ID, parent_id); |
416 entry_ = existing_entry.release(); | 418 entry_ = existing_entry.release(); |
417 } else { | 419 } else { |
418 return false; | 420 return INIT_FAILED_ENTRY_ALREADY_EXISTS; |
419 } | 421 } |
420 } else { | 422 } else { |
421 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), | 423 entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), |
422 syncable::CREATE, parent_id, dummy); | 424 syncable::CREATE, parent_id, dummy); |
423 if (!entry_->good()) { | 425 if (!entry_->good()) |
424 return false; | 426 return INIT_FAILED_COULD_NOT_CREATE_ENTRY; |
425 } | |
426 | 427 |
427 // Only set IS_DIR for new entries. Don't bitflip undeleted ones. | 428 // Only set IS_DIR for new entries. Don't bitflip undeleted ones. |
428 entry_->Put(syncable::UNIQUE_CLIENT_TAG, hash); | 429 entry_->Put(syncable::UNIQUE_CLIENT_TAG, hash); |
429 } | 430 } |
430 | 431 |
431 // We don't support directory and tag combinations. | 432 // We don't support directory and tag combinations. |
432 entry_->Put(syncable::IS_DIR, false); | 433 entry_->Put(syncable::IS_DIR, false); |
433 | 434 |
434 // Will clear specifics data. | 435 // Will clear specifics data. |
435 PutModelType(model_type); | 436 PutModelType(model_type); |
436 | 437 |
437 // Now set the predecessor, which sets IS_UNSYNCED as necessary. | 438 // Now set the predecessor, which sets IS_UNSYNCED as necessary. |
438 return PutPredecessor(NULL); | 439 bool success = PutPredecessor(NULL); |
440 if (!success) | |
441 return INIT_FAILED_SET_PREDECESSOR; | |
442 | |
443 return INIT_SUCCESS; | |
439 } | 444 } |
440 | 445 |
441 bool WriteNode::SetPosition(const BaseNode& new_parent, | 446 bool WriteNode::SetPosition(const BaseNode& new_parent, |
442 const BaseNode* predecessor) { | 447 const BaseNode* predecessor) { |
443 // |predecessor| must be a child of |new_parent| or NULL. | 448 // |predecessor| must be a child of |new_parent| or NULL. |
444 if (predecessor && predecessor->GetParentId() != new_parent.GetId()) { | 449 if (predecessor && predecessor->GetParentId() != new_parent.GetId()) { |
445 DCHECK(false); | 450 DCHECK(false); |
446 return false; | 451 return false; |
447 } | 452 } |
448 | 453 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 499 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
495 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 500 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
496 SetBookmarkSpecifics(new_value); | 501 SetBookmarkSpecifics(new_value); |
497 } | 502 } |
498 | 503 |
499 void WriteNode::MarkForSyncing() { | 504 void WriteNode::MarkForSyncing() { |
500 syncable::MarkForSyncing(entry_); | 505 syncable::MarkForSyncing(entry_); |
501 } | 506 } |
502 | 507 |
503 } // namespace sync_api | 508 } // namespace sync_api |
OLD | NEW |