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

Unified Diff: sync/syncable/mutable_entry.cc

Issue 11817010: sync: Initialize entries with a valid model type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix broken DCHECKs Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/syncable/mutable_entry.h ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/mutable_entry.cc
diff --git a/sync/syncable/mutable_entry.cc b/sync/syncable/mutable_entry.cc
index 64a23ced691f04c7f20b9dd1ae1a0504ebc2e878..23531287a764df3eb09e5d22d648b10864543543 100644
--- a/sync/syncable/mutable_entry.cc
+++ b/sync/syncable/mutable_entry.cc
@@ -19,15 +19,9 @@ using std::string;
namespace syncer {
namespace syncable {
-MutableEntry::MutableEntry(WriteTransaction* trans, Create,
- const Id& parent_id, const string& name)
- : Entry(trans),
- write_transaction_(trans) {
- Init(trans, parent_id, name);
-}
-
-
-void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id,
+void MutableEntry::Init(WriteTransaction* trans,
+ ModelType model_type,
+ const Id& parent_id,
const string& name) {
scoped_ptr<EntryKernel> kernel(new EntryKernel);
kernel_ = NULL;
@@ -43,9 +37,15 @@ void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id,
// We match the database defaults here
kernel->put(BASE_VERSION, CHANGES_VERSION);
kernel->put(SERVER_ORDINAL_IN_PARENT, NodeOrdinal::CreateInitialOrdinal());
- if (!trans->directory()->InsertEntry(trans, kernel.get())) {
- return; // We failed inserting, nothing more to do.
- }
+
+ // Normally the SPECIFICS setting code is wrapped in logic to deal with
+ // unknown fields and encryption. Since all we want to do here is ensure that
+ // GetModelType() returns a correct value from the very beginning, these
+ // few lines are sufficient.
+ sync_pb::EntitySpecifics specifics;
+ AddDefaultFieldValue(model_type, &specifics);
+ kernel->put(SPECIFICS, specifics);
+
// Because this entry is new, it was originally deleted.
kernel->put(IS_DEL, true);
trans->SaveOriginal(kernel.get());
@@ -55,6 +55,18 @@ void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id,
kernel_ = kernel.release();
}
+MutableEntry::MutableEntry(WriteTransaction* trans,
+ Create,
+ ModelType model_type,
+ const Id& parent_id,
+ const string& name)
+ : Entry(trans),
+ write_transaction_(trans) {
+ Init(trans, model_type, parent_id, name);
+ bool insert_result = trans->directory()->InsertEntry(trans, kernel_);
+ DCHECK(insert_result);
+}
+
MutableEntry::MutableEntry(WriteTransaction* trans, CreateNewUpdateItem,
const Id& id)
: Entry(trans), write_transaction_(trans) {
« no previous file with comments | « sync/syncable/mutable_entry.h ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698