summaryrefslogtreecommitdiffstats
path: root/sync/syncable
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-01 20:15:12 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-01 20:15:12 +0000
commit3e332453aa32dbca036c7e7b252dc7e5b7c55a27 (patch)
tree6a49ea32e7317f306d44c8fda08e8edf248b9767 /sync/syncable
parentfd6c39e9b18d373bbf58ffe8975206308a3ef5e3 (diff)
downloadchromium_src-3e332453aa32dbca036c7e7b252dc7e5b7c55a27.zip
chromium_src-3e332453aa32dbca036c7e7b252dc7e5b7c55a27.tar.gz
chromium_src-3e332453aa32dbca036c7e7b252dc7e5b7c55a27.tar.bz2
sync: Process updates responses on the sync thread
Convert ProcessUpdatesCommand from a ModelChangingSyncerCommand to a SyncerCommand. This means it will be executed only on the syncer thread, rather than delegating to a collection of model threads. In order to ensure this change is safe and will not be broken by future CLs, it converts all transactions used by the ProcessUpdatesCommand into ModelNeutralWriteTransactions. When implemented correctly, this guarantees that no change performed by this command will need to be forwarded to the model threads. This commit adds a constructor to ModelNeutralMutableEntry to allow it to instantiate "update" items. This is safe because these update items can be saved and manipulated inside the sync directory as long as they remain locally IS_DEL. The native models do not need to be made aware of them until this flag is unset when we apply the updates in a later SyncerCommand. BUG=299023 Review URL: https://codereview.chromium.org/24879002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/syncable')
-rw-r--r--sync/syncable/directory.cc4
-rw-r--r--sync/syncable/directory.h4
-rw-r--r--sync/syncable/model_neutral_mutable_entry.cc26
-rw-r--r--sync/syncable/model_neutral_mutable_entry.h7
-rw-r--r--sync/syncable/mutable_entry.cc23
-rw-r--r--sync/syncable/mutable_entry.h4
6 files changed, 39 insertions, 29 deletions
diff --git a/sync/syncable/directory.cc b/sync/syncable/directory.cc
index 855d442..85e5107 100644
--- a/sync/syncable/directory.cc
+++ b/sync/syncable/directory.cc
@@ -343,12 +343,12 @@ EntryKernel* Directory::GetRootEntry() {
return GetEntryById(Id());
}
-bool Directory::InsertEntry(WriteTransaction* trans, EntryKernel* entry) {
+bool Directory::InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry) {
ScopedKernelLock lock(this);
return InsertEntry(trans, entry, &lock);
}
-bool Directory::InsertEntry(WriteTransaction* trans,
+bool Directory::InsertEntry(BaseWriteTransaction* trans,
EntryKernel* entry,
ScopedKernelLock* lock) {
DCHECK(NULL != lock);
diff --git a/sync/syncable/directory.h b/sync/syncable/directory.h
index 5a07322..7a58dfc 100644
--- a/sync/syncable/directory.h
+++ b/sync/syncable/directory.h
@@ -507,9 +507,9 @@ class SYNC_EXPORT Directory {
void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot);
// For new entry creation only
- bool InsertEntry(WriteTransaction* trans,
+ bool InsertEntry(BaseWriteTransaction* trans,
EntryKernel* entry, ScopedKernelLock* lock);
- bool InsertEntry(WriteTransaction* trans, EntryKernel* entry);
+ bool InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry);
// Used by CheckTreeInvariants
void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result);
diff --git a/sync/syncable/model_neutral_mutable_entry.cc b/sync/syncable/model_neutral_mutable_entry.cc
index 9b054ef..d778aba 100644
--- a/sync/syncable/model_neutral_mutable_entry.cc
+++ b/sync/syncable/model_neutral_mutable_entry.cc
@@ -9,6 +9,7 @@
#include "sync/internal_api/public/base/unique_position.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/scoped_kernel_lock.h"
+#include "sync/syncable/syncable_changes_version.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/syncable_write_transaction.h"
@@ -18,6 +19,31 @@ namespace syncer {
namespace syncable {
+ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans,
+ CreateNewUpdateItem,
+ const Id& id)
+ : Entry(trans), base_write_transaction_(trans) {
+ Entry same_id(trans, GET_BY_ID, id);
+ kernel_ = NULL;
+ if (same_id.good()) {
+ return; // already have an item with this ID.
+ }
+ scoped_ptr<EntryKernel> kernel(new EntryKernel());
+
+ kernel->put(ID, id);
+ kernel->put(META_HANDLE, trans->directory()->NextMetahandle());
+ kernel->mark_dirty(&trans->directory()->kernel_->dirty_metahandles);
+ kernel->put(IS_DEL, true);
+ // We match the database defaults here
+ kernel->put(BASE_VERSION, CHANGES_VERSION);
+ if (!trans->directory()->InsertEntry(trans, kernel.get())) {
+ return; // Failed inserting.
+ }
+ trans->TrackChangesTo(kernel.get());
+
+ kernel_ = kernel.release();
+}
+
ModelNeutralMutableEntry::ModelNeutralMutableEntry(
BaseWriteTransaction* trans, GetById, const Id& id)
: Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) {
diff --git a/sync/syncable/model_neutral_mutable_entry.h b/sync/syncable/model_neutral_mutable_entry.h
index c9f6c8b..e2292e7 100644
--- a/sync/syncable/model_neutral_mutable_entry.h
+++ b/sync/syncable/model_neutral_mutable_entry.h
@@ -16,6 +16,10 @@ namespace syncable {
class BaseWriteTransaction;
+enum CreateNewUpdateItem {
+ CREATE_NEW_UPDATE_ITEM
+};
+
// This Entry includes all the operations one can safely perform on the sync
// thread. In particular, it does not expose setters to make changes that need
// to be communicated to the model (and the model's thread). It is not possible
@@ -23,6 +27,9 @@ class BaseWriteTransaction;
// entry.
class SYNC_EXPORT_PRIVATE ModelNeutralMutableEntry : public Entry {
public:
+ ModelNeutralMutableEntry(BaseWriteTransaction* trans,
+ CreateNewUpdateItem,
+ const Id& id);
ModelNeutralMutableEntry(BaseWriteTransaction* trans, GetByHandle, int64);
ModelNeutralMutableEntry(BaseWriteTransaction* trans, GetById, const Id&);
ModelNeutralMutableEntry(
diff --git a/sync/syncable/mutable_entry.cc b/sync/syncable/mutable_entry.cc
index a4fadd2..863e65b 100644
--- a/sync/syncable/mutable_entry.cc
+++ b/sync/syncable/mutable_entry.cc
@@ -78,27 +78,8 @@ MutableEntry::MutableEntry(WriteTransaction* trans,
MutableEntry::MutableEntry(WriteTransaction* trans, CreateNewUpdateItem,
const Id& id)
- : ModelNeutralMutableEntry(trans), write_transaction_(trans) {
- Entry same_id(trans, GET_BY_ID, id);
- kernel_ = NULL;
- if (same_id.good()) {
- return; // already have an item with this ID.
- }
- scoped_ptr<EntryKernel> kernel(new EntryKernel());
-
- kernel->put(ID, id);
- kernel->put(META_HANDLE, trans->directory_->NextMetahandle());
- kernel->mark_dirty(&trans->directory_->kernel_->dirty_metahandles);
- kernel->put(IS_DEL, true);
- // We match the database defaults here
- kernel->put(BASE_VERSION, CHANGES_VERSION);
- if (!trans->directory()->InsertEntry(trans, kernel.get())) {
- return; // Failed inserting.
- }
- trans->TrackChangesTo(kernel.get());
-
- kernel_ = kernel.release();
-}
+ : ModelNeutralMutableEntry(trans, CREATE_NEW_UPDATE_ITEM, id),
+ write_transaction_(trans) {}
MutableEntry::MutableEntry(WriteTransaction* trans, GetById, const Id& id)
: ModelNeutralMutableEntry(trans, GET_BY_ID, id),
diff --git a/sync/syncable/mutable_entry.h b/sync/syncable/mutable_entry.h
index 0b72bcc..8c2f2ab 100644
--- a/sync/syncable/mutable_entry.h
+++ b/sync/syncable/mutable_entry.h
@@ -20,10 +20,6 @@ enum Create {
CREATE
};
-enum CreateNewUpdateItem {
- CREATE_NEW_UPDATE_ITEM
-};
-
class WriteTransaction;
// A mutable meta entry. Changes get committed to the database when the