| Index: sync/internal_api/write_node.cc
|
| diff --git a/sync/internal_api/write_node.cc b/sync/internal_api/write_node.cc
|
| index 6f70b3da11bc2debfe95b2af23503f1840e7c92d..1367ecb8759bec83fe2a7800edfb67a44ea4c065 100644
|
| --- a/sync/internal_api/write_node.cc
|
| +++ b/sync/internal_api/write_node.cc
|
| @@ -19,6 +19,7 @@
|
| #include "sync/protocol/typed_url_specifics.pb.h"
|
| #include "sync/syncable/mutable_entry.h"
|
| #include "sync/syncable/nigori_util.h"
|
| +#include "sync/syncable/syncable_util.h"
|
| #include "sync/util/cryptographer.h"
|
|
|
| using std::string;
|
| @@ -204,12 +205,7 @@ void WriteNode::SetEntitySpecifics(
|
| DCHECK_NE(new_specifics_type, UNSPECIFIED);
|
| DVLOG(1) << "Writing entity specifics of type "
|
| << ModelTypeToString(new_specifics_type);
|
| - // GetModelType() can be unspecified if this is the first time this
|
| - // node is being initialized (see PutModelType()). Otherwise, it
|
| - // should match |new_specifics_type|.
|
| - if (GetModelType() != UNSPECIFIED) {
|
| - DCHECK_EQ(new_specifics_type, GetModelType());
|
| - }
|
| + DCHECK_EQ(new_specifics_type, GetModelType());
|
|
|
| // Preserve unknown fields.
|
| const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS);
|
| @@ -292,7 +288,7 @@ BaseNode::InitByLookupResult WriteNode::InitByClientTagLookup(
|
| if (tag.empty())
|
| return INIT_FAILED_PRECONDITION;
|
|
|
| - const std::string hash = GenerateSyncableHash(model_type, tag);
|
| + const std::string hash = syncable::GenerateSyncableHash(model_type, tag);
|
|
|
| entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
|
| syncable::GET_BY_CLIENT_TAG, hash);
|
| @@ -319,22 +315,10 @@ BaseNode::InitByLookupResult WriteNode::InitByTagLookup(
|
| return INIT_OK;
|
| }
|
|
|
| -void WriteNode::PutModelType(ModelType model_type) {
|
| - // Set an empty specifics of the appropriate datatype. The presence
|
| - // of the specific field will identify the model type.
|
| - DCHECK(GetModelType() == model_type ||
|
| - GetModelType() == UNSPECIFIED); // Immutable once set.
|
| -
|
| - sync_pb::EntitySpecifics specifics;
|
| - AddDefaultFieldValue(model_type, &specifics);
|
| - SetEntitySpecifics(specifics);
|
| -}
|
| -
|
| // Create a new node with default properties, and bind this WriteNode to it.
|
| // Return true on success.
|
| -bool WriteNode::InitByCreation(ModelType model_type,
|
| - const BaseNode& parent,
|
| - const BaseNode* predecessor) {
|
| +bool WriteNode::InitBookmarkByCreation(const BaseNode& parent,
|
| + const BaseNode* predecessor) {
|
| DCHECK(!entry_) << "Init called twice";
|
| // |predecessor| must be a child of |parent| or NULL.
|
| if (predecessor && predecessor->GetParentId() != parent.GetId()) {
|
| @@ -349,7 +333,8 @@ bool WriteNode::InitByCreation(ModelType model_type,
|
| string dummy(kDefaultNameForNewNodes);
|
|
|
| entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
|
| - syncable::CREATE, parent_id, dummy);
|
| + syncable::CREATE_BOOKMARK, parent_id,
|
| + dummy);
|
|
|
| if (!entry_->good())
|
| return false;
|
| @@ -357,8 +342,6 @@ bool WriteNode::InitByCreation(ModelType model_type,
|
| // Entries are untitled folders by default.
|
| entry_->Put(syncable::IS_DIR, true);
|
|
|
| - PutModelType(model_type);
|
| -
|
| // Now set the predecessor, which sets IS_UNSYNCED as necessary.
|
| return PutPredecessor(predecessor);
|
| }
|
| @@ -380,7 +363,7 @@ WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation(
|
| return INIT_FAILED_EMPTY_TAG;
|
| }
|
|
|
| - const std::string hash = GenerateSyncableHash(model_type, tag);
|
| + const std::string hash = syncable::GenerateSyncableHash(model_type, tag);
|
|
|
| syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
|
|
|
| @@ -426,7 +409,8 @@ WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation(
|
| }
|
| } else {
|
| entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
|
| - syncable::CREATE, parent_id, dummy);
|
| + syncable::CREATE_UNIQUE,
|
| + model_type, parent_id, dummy);
|
| if (!entry_->good())
|
| return INIT_FAILED_COULD_NOT_CREATE_ENTRY;
|
|
|
| @@ -437,9 +421,6 @@ WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation(
|
| // We don't support directory and tag combinations.
|
| entry_->Put(syncable::IS_DIR, false);
|
|
|
| - // Will clear specifics data.
|
| - PutModelType(model_type);
|
| -
|
| // Now set the predecessor, which sets IS_UNSYNCED as necessary.
|
| bool success = PutPredecessor(NULL);
|
| if (!success)
|
| @@ -460,7 +441,7 @@ bool WriteNode::SetPosition(const BaseNode& new_parent,
|
|
|
| // Filter out redundant changes if both the parent and the predecessor match.
|
| if (new_parent_id == entry_->Get(syncable::PARENT_ID)) {
|
| - const syncable::Id& old = entry_->Get(syncable::PREV_ID);
|
| + const syncable::Id& old = entry_->GetPredecessorId();
|
| if ((!predecessor && old.IsRoot()) ||
|
| (predecessor && (old == predecessor->GetEntry()->Get(syncable::ID)))) {
|
| return true;
|
| @@ -474,6 +455,7 @@ bool WriteNode::SetPosition(const BaseNode& new_parent,
|
|
|
| // Now set the predecessor, which sets IS_UNSYNCED as necessary.
|
| return PutPredecessor(predecessor);
|
| + return true;
|
| }
|
|
|
| const syncable::Entry* WriteNode::GetEntry() const {
|
|
|