| Index: sync/internal_api/write_node.cc
|
| ===================================================================
|
| --- sync/internal_api/write_node.cc (revision 176351)
|
| +++ sync/internal_api/write_node.cc (working copy)
|
| @@ -212,7 +212,12 @@
|
| DCHECK_NE(new_specifics_type, UNSPECIFIED);
|
| DVLOG(1) << "Writing entity specifics of type "
|
| << ModelTypeToString(new_specifics_type);
|
| - DCHECK_EQ(new_specifics_type, GetModelType());
|
| + // 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());
|
| + }
|
|
|
| // Preserve unknown fields.
|
| const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS);
|
| @@ -322,10 +327,22 @@
|
| 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::InitBookmarkByCreation(const BaseNode& parent,
|
| - const BaseNode* predecessor) {
|
| +bool WriteNode::InitByCreation(ModelType model_type,
|
| + 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()) {
|
| @@ -340,8 +357,7 @@
|
| string dummy(kDefaultNameForNewNodes);
|
|
|
| entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
|
| - syncable::CREATE, BOOKMARKS,
|
| - parent_id, dummy);
|
| + syncable::CREATE, parent_id, dummy);
|
|
|
| if (!entry_->good())
|
| return false;
|
| @@ -349,6 +365,8 @@
|
| // 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);
|
| }
|
| @@ -416,8 +434,7 @@
|
| }
|
| } else {
|
| entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
|
| - syncable::CREATE,
|
| - model_type, parent_id, dummy);
|
| + syncable::CREATE, parent_id, dummy);
|
| if (!entry_->good())
|
| return INIT_FAILED_COULD_NOT_CREATE_ENTRY;
|
|
|
| @@ -428,6 +445,9 @@
|
| // 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)
|
|
|