summaryrefslogtreecommitdiffstats
path: root/sync/syncable/model_neutral_mutable_entry.cc
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 09:42:36 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 09:42:36 +0000
commit74af91054eb44cb477ea60a9a32d16a88e978711 (patch)
treeffd889379d9c11a311e66f17e55b6068567ad6b7 /sync/syncable/model_neutral_mutable_entry.cc
parent1f332826bdd0d92b8502c671f538ca1807eaefe4 (diff)
downloadchromium_src-74af91054eb44cb477ea60a9a32d16a88e978711.zip
chromium_src-74af91054eb44cb477ea60a9a32d16a88e978711.tar.gz
chromium_src-74af91054eb44cb477ea60a9a32d16a88e978711.tar.bz2
sync: Introduce ModelNeutralWriteTransactions
Introduce ModelNeutralWriteTransactions that allows changes to entries only if those changes do not need to be sent back to the model. In other words, they have write access to almost everything except SPECIFICS, UNIQUE_POSITION, PARENT_ID, and other similar fields that need to be reported back to the model to keep it in sync. We enforce this restriction by allowing the construction of ModelNeutralMutableEntries from these transactions, but requiring a full WriteTransaction to construct regular MutableEntries. To make it easier to write generic functions, this change also introduces a common base class called BaseWriteTransaction. This class is a parent of both WriteTransaction and ModelNeutralWriteTransaction, so it can be used in contexts where we're willing to accept either. This is similar to the way BaseTransaction currently enables generic functions to work with either ReadTransactions or WriteTransactions. This patch does not actually instantiate any ModelNeutralWriteTransactions. The work of converting existing code to use this new function will be started in future CLs. BUG=284672 Review URL: https://codereview.chromium.org/24435002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/syncable/model_neutral_mutable_entry.cc')
-rw-r--r--sync/syncable/model_neutral_mutable_entry.cc68
1 files changed, 34 insertions, 34 deletions
diff --git a/sync/syncable/model_neutral_mutable_entry.cc b/sync/syncable/model_neutral_mutable_entry.cc
index 3d019e6..9b054ef 100644
--- a/sync/syncable/model_neutral_mutable_entry.cc
+++ b/sync/syncable/model_neutral_mutable_entry.cc
@@ -19,28 +19,28 @@ namespace syncer {
namespace syncable {
ModelNeutralMutableEntry::ModelNeutralMutableEntry(
- WriteTransaction* trans, GetById, const Id& id)
- : Entry(trans, GET_BY_ID, id), write_transaction_(trans) {
+ BaseWriteTransaction* trans, GetById, const Id& id)
+ : Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) {
}
ModelNeutralMutableEntry::ModelNeutralMutableEntry(
- WriteTransaction* trans, GetByHandle, int64 metahandle)
- : Entry(trans, GET_BY_HANDLE, metahandle), write_transaction_(trans) {
+ BaseWriteTransaction* trans, GetByHandle, int64 metahandle)
+ : Entry(trans, GET_BY_HANDLE, metahandle), base_write_transaction_(trans) {
}
ModelNeutralMutableEntry::ModelNeutralMutableEntry(
- WriteTransaction* trans, GetByClientTag, const std::string& tag)
- : Entry(trans, GET_BY_CLIENT_TAG, tag), write_transaction_(trans) {
+ BaseWriteTransaction* trans, GetByClientTag, const std::string& tag)
+ : Entry(trans, GET_BY_CLIENT_TAG, tag), base_write_transaction_(trans) {
}
ModelNeutralMutableEntry::ModelNeutralMutableEntry(
- WriteTransaction* trans, GetByServerTag, const string& tag)
- : Entry(trans, GET_BY_SERVER_TAG, tag), write_transaction_(trans) {
+ BaseWriteTransaction* trans, GetByServerTag, const string& tag)
+ : Entry(trans, GET_BY_SERVER_TAG, tag), base_write_transaction_(trans) {
}
void ModelNeutralMutableEntry::PutBaseVersion(int64 value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(BASE_VERSION) != value) {
kernel_->put(BASE_VERSION, value);
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
@@ -49,7 +49,7 @@ void ModelNeutralMutableEntry::PutBaseVersion(int64 value) {
void ModelNeutralMutableEntry::PutServerVersion(int64 value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(SERVER_VERSION) != value) {
ScopedKernelLock lock(dir());
kernel_->put(SERVER_VERSION, value);
@@ -59,7 +59,7 @@ void ModelNeutralMutableEntry::PutServerVersion(int64 value) {
void ModelNeutralMutableEntry::PutServerMtime(base::Time value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(SERVER_MTIME) != value) {
kernel_->put(SERVER_MTIME, value);
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
@@ -68,7 +68,7 @@ void ModelNeutralMutableEntry::PutServerMtime(base::Time value) {
void ModelNeutralMutableEntry::PutServerCtime(base::Time value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(SERVER_CTIME) != value) {
kernel_->put(SERVER_CTIME, value);
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
@@ -77,9 +77,9 @@ void ModelNeutralMutableEntry::PutServerCtime(base::Time value) {
bool ModelNeutralMutableEntry::PutId(const Id& value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(ID) != value) {
- if (!dir()->ReindexId(write_transaction(), kernel_, value))
+ if (!dir()->ReindexId(base_write_transaction(), kernel_, value))
return false;
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
}
@@ -88,7 +88,7 @@ bool ModelNeutralMutableEntry::PutId(const Id& value) {
void ModelNeutralMutableEntry::PutServerParentId(const Id& value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(SERVER_PARENT_ID) != value) {
kernel_->put(SERVER_PARENT_ID, value);
@@ -98,7 +98,7 @@ void ModelNeutralMutableEntry::PutServerParentId(const Id& value) {
bool ModelNeutralMutableEntry::PutIsUnsynced(bool value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(IS_UNSYNCED) != value) {
MetahandleSet* index = &dir()->kernel_->unsynced_metahandles;
@@ -107,14 +107,14 @@ bool ModelNeutralMutableEntry::PutIsUnsynced(bool value) {
if (!SyncAssert(index->insert(kernel_->ref(META_HANDLE)).second,
FROM_HERE,
"Could not insert",
- write_transaction())) {
+ base_write_transaction())) {
return false;
}
} else {
if (!SyncAssert(1U == index->erase(kernel_->ref(META_HANDLE)),
FROM_HERE,
"Entry Not succesfully erased",
- write_transaction())) {
+ base_write_transaction())) {
return false;
}
}
@@ -126,7 +126,7 @@ bool ModelNeutralMutableEntry::PutIsUnsynced(bool value) {
bool ModelNeutralMutableEntry::PutIsUnappliedUpdate(bool value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(IS_UNAPPLIED_UPDATE) != value) {
// Use kernel_->GetServerModelType() instead of
// GetServerModelType() as we may trigger some DCHECKs in the
@@ -139,14 +139,14 @@ bool ModelNeutralMutableEntry::PutIsUnappliedUpdate(bool value) {
if (!SyncAssert(index->insert(kernel_->ref(META_HANDLE)).second,
FROM_HERE,
"Could not insert",
- write_transaction())) {
+ base_write_transaction())) {
return false;
}
} else {
if (!SyncAssert(1U == index->erase(kernel_->ref(META_HANDLE)),
FROM_HERE,
"Entry Not succesfully erased",
- write_transaction())) {
+ base_write_transaction())) {
return false;
}
}
@@ -158,7 +158,7 @@ bool ModelNeutralMutableEntry::PutIsUnappliedUpdate(bool value) {
void ModelNeutralMutableEntry::PutServerIsDir(bool value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
bool old_value = kernel_->ref(SERVER_IS_DIR);
if (old_value != value) {
kernel_->put(SERVER_IS_DIR, value);
@@ -168,7 +168,7 @@ void ModelNeutralMutableEntry::PutServerIsDir(bool value) {
void ModelNeutralMutableEntry::PutServerIsDel(bool value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
bool old_value = kernel_->ref(SERVER_IS_DEL);
if (old_value != value) {
kernel_->put(SERVER_IS_DEL, value);
@@ -181,13 +181,13 @@ void ModelNeutralMutableEntry::PutServerIsDel(bool value) {
// UpdateDeleteJournalForServerDelete() checks for SERVER_IS_DEL, it has
// to be called on sync thread.
dir()->delete_journal()->UpdateDeleteJournalForServerDelete(
- write_transaction(), old_value, *kernel_);
+ base_write_transaction(), old_value, *kernel_);
}
void ModelNeutralMutableEntry::PutServerNonUniqueName(
const std::string& value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if (kernel_->ref(SERVER_NON_UNIQUE_NAME) != value) {
kernel_->put(SERVER_NON_UNIQUE_NAME, value);
@@ -200,7 +200,7 @@ bool ModelNeutralMutableEntry::PutUniqueServerTag(const string& new_tag) {
return true;
}
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
ScopedKernelLock lock(dir());
// Make sure your new value is not in there already.
if (dir()->kernel_->server_tags_map.find(new_tag) !=
@@ -224,7 +224,7 @@ bool ModelNeutralMutableEntry::PutUniqueClientTag(const string& new_tag) {
return true;
}
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
ScopedKernelLock lock(dir());
// Make sure your new value is not in there already.
if (dir()->kernel_->client_tags_map.find(new_tag) !=
@@ -270,7 +270,7 @@ void ModelNeutralMutableEntry::PutServerSpecifics(
const sync_pb::EntitySpecifics& value) {
DCHECK(kernel_);
CHECK(!value.password().has_client_only_encrypted_data());
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
// TODO(ncarter): This is unfortunately heavyweight. Can we do
// better?
if (kernel_->ref(SERVER_SPECIFICS).SerializeAsString() !=
@@ -304,7 +304,7 @@ void ModelNeutralMutableEntry::PutBaseServerSpecifics(
const sync_pb::EntitySpecifics& value) {
DCHECK(kernel_);
CHECK(!value.password().has_client_only_encrypted_data());
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
// TODO(ncarter): This is unfortunately heavyweight. Can we do
// better?
if (kernel_->ref(BASE_SERVER_SPECIFICS).SerializeAsString()
@@ -317,7 +317,7 @@ void ModelNeutralMutableEntry::PutBaseServerSpecifics(
void ModelNeutralMutableEntry::PutServerUniquePosition(
const UniquePosition& value) {
DCHECK(kernel_);
- write_transaction_->SaveOriginal(kernel_);
+ base_write_transaction_->TrackChangesTo(kernel_);
if(!kernel_->ref(SERVER_UNIQUE_POSITION).Equals(value)) {
// We should never overwrite a valid position with an invalid one.
DCHECK(value.IsValid());
@@ -332,8 +332,8 @@ void ModelNeutralMutableEntry::PutSyncing(bool value) {
}
void ModelNeutralMutableEntry::PutParentIdPropertyOnly(const Id& parent_id) {
- write_transaction_->SaveOriginal(kernel_);
- dir()->ReindexParentId(write_transaction(), kernel_, parent_id);
+ base_write_transaction_->TrackChangesTo(kernel_);
+ dir()->ReindexParentId(base_write_transaction(), kernel_, parent_id);
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
}
@@ -343,8 +343,8 @@ void ModelNeutralMutableEntry::UpdateTransactionVersion(int64 value) {
kernel_->mark_dirty(&(dir()->kernel_->dirty_metahandles));
}
-ModelNeutralMutableEntry::ModelNeutralMutableEntry(WriteTransaction* trans)
- : Entry(trans), write_transaction_(trans) {}
+ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans)
+ : Entry(trans), base_write_transaction_(trans) {}
MetahandleSet* ModelNeutralMutableEntry::GetDirtyIndexHelper() {
return &dir()->kernel_->dirty_metahandles;