summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 21:43:48 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 21:43:48 +0000
commit89a7865e74d82a34a565401f2bd5963028bc3aed (patch)
tree2374b6565b073956230063196d24de083f085892 /sync
parent50007578be00daeb58db28579f2a59c51df8ca7f (diff)
downloadchromium_src-89a7865e74d82a34a565401f2bd5963028bc3aed.zip
chromium_src-89a7865e74d82a34a565401f2bd5963028bc3aed.tar.gz
chromium_src-89a7865e74d82a34a565401f2bd5963028bc3aed.tar.bz2
sync: Inheritance refactor for non-blocking sync
Implements several previously discussed changes to the inheritance hierarchy for non-blocking sync classes. Changes SyncContext from a wrapper around ModelTypeRegistry to an interface class that ModelTypeRegistry implemnts. Makes ModelTypeSyncWorkerImpl implement the ModelTypeSyncWorker interface, even though it is never referenced via this interface. Makes the same change to ModelTypeSyncProxyImpl and the ModelTypeSyncProxy interface. These refactoring required that some methods be renamed to be consistent with the interface. This completes the refactoring that was started in r279618. BUG=351005 Review URL: https://codereview.chromium.org/351073005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/engine/model_type_sync_proxy.h4
-rw-r--r--sync/engine/model_type_sync_proxy_impl.cc4
-rw-r--r--sync/engine/model_type_sync_proxy_impl.h4
-rw-r--r--sync/engine/model_type_sync_proxy_impl_unittest.cc2
-rw-r--r--sync/engine/model_type_sync_worker.h3
-rw-r--r--sync/engine/model_type_sync_worker_impl.cc7
-rw-r--r--sync/engine/model_type_sync_worker_impl.h7
-rw-r--r--sync/internal_api/public/sync_context.h (renamed from sync/internal_api/sync_context.h)19
-rw-r--r--sync/internal_api/sync_context.cc26
-rw-r--r--sync/internal_api/sync_context_proxy_impl.cc5
-rw-r--r--sync/internal_api/sync_context_proxy_impl_unittest.cc11
-rw-r--r--sync/internal_api/sync_manager_impl.cc6
-rw-r--r--sync/sessions/model_type_registry.cc28
-rw-r--r--sync/sessions/model_type_registry.h17
-rw-r--r--sync/sessions/model_type_registry_unittest.cc56
-rw-r--r--sync/sync_internal_api.gypi2
-rw-r--r--sync/test/engine/mock_model_type_sync_proxy.cc19
-rw-r--r--sync/test/engine/mock_model_type_sync_proxy.h12
-rw-r--r--sync/test/engine/mock_model_type_sync_worker.cc2
-rw-r--r--sync/test/engine/mock_model_type_sync_worker.h2
20 files changed, 108 insertions, 128 deletions
diff --git a/sync/engine/model_type_sync_proxy.h b/sync/engine/model_type_sync_proxy.h
index 2851a09..7442841 100644
--- a/sync/engine/model_type_sync_proxy.h
+++ b/sync/engine/model_type_sync_proxy.h
@@ -16,10 +16,10 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxy {
ModelTypeSyncProxy();
virtual ~ModelTypeSyncProxy();
- virtual void ReceiveCommitResponse(
+ virtual void OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) = 0;
- virtual void ReceiveUpdateResponse(
+ virtual void OnUpdateReceived(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) = 0;
};
diff --git a/sync/engine/model_type_sync_proxy_impl.cc b/sync/engine/model_type_sync_proxy_impl.cc
index d865998..3ea8552 100644
--- a/sync/engine/model_type_sync_proxy_impl.cc
+++ b/sync/engine/model_type_sync_proxy_impl.cc
@@ -159,10 +159,10 @@ void ModelTypeSyncProxyImpl::FlushPendingCommitRequests() {
}
if (!commit_requests.empty())
- worker_->RequestCommits(commit_requests);
+ worker_->EnqueueForCommit(commit_requests);
}
-void ModelTypeSyncProxyImpl::OnCommitCompletion(
+void ModelTypeSyncProxyImpl::OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) {
data_type_state_ = type_state;
diff --git a/sync/engine/model_type_sync_proxy_impl.h b/sync/engine/model_type_sync_proxy_impl.h
index 0091112..3a988e5 100644
--- a/sync/engine/model_type_sync_proxy_impl.h
+++ b/sync/engine/model_type_sync_proxy_impl.h
@@ -67,8 +67,8 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe {
// Informs this object that some of its commit requests have been
// successfully serviced.
- void OnCommitCompletion(const DataTypeState& type_state,
- const CommitResponseDataList& response_list);
+ void OnCommitCompleted(const DataTypeState& type_state,
+ const CommitResponseDataList& response_list);
// Informs this object that there are some incoming updates is should
// handle.
diff --git a/sync/engine/model_type_sync_proxy_impl_unittest.cc b/sync/engine/model_type_sync_proxy_impl_unittest.cc
index 810c6b6..f781d16 100644
--- a/sync/engine/model_type_sync_proxy_impl_unittest.cc
+++ b/sync/engine/model_type_sync_proxy_impl_unittest.cc
@@ -197,7 +197,7 @@ void ModelTypeSyncProxyImplTest::SuccessfulCommitResponse(
const CommitRequestData& request_data) {
CommitResponseDataList list;
list.push_back(mock_worker_->SuccessfulCommitResponse(request_data));
- type_sync_proxy_->OnCommitCompletion(data_type_state_, list);
+ type_sync_proxy_->OnCommitCompleted(data_type_state_, list);
}
std::string ModelTypeSyncProxyImplTest::GenerateTagHash(
diff --git a/sync/engine/model_type_sync_worker.h b/sync/engine/model_type_sync_worker.h
index 9add845..eeb5f88 100644
--- a/sync/engine/model_type_sync_worker.h
+++ b/sync/engine/model_type_sync_worker.h
@@ -15,7 +15,8 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncWorker {
ModelTypeSyncWorker();
virtual ~ModelTypeSyncWorker();
- virtual void RequestCommits(const CommitRequestDataList& list) = 0;
+ // Entry point for the ModelTypeSyncProxy to send commit requests.
+ virtual void EnqueueForCommit(const CommitRequestDataList& list) = 0;
};
} // namespace syncer
diff --git a/sync/engine/model_type_sync_worker_impl.cc b/sync/engine/model_type_sync_worker_impl.cc
index 0e2ade0..090db11 100644
--- a/sync/engine/model_type_sync_worker_impl.cc
+++ b/sync/engine/model_type_sync_worker_impl.cc
@@ -108,7 +108,7 @@ SyncerError ModelTypeSyncWorkerImpl::ProcessGetUpdatesResponse(
}
// Forward these updates to the model thread so it can do the rest.
- type_sync_proxy_->ReceiveUpdateResponse(data_type_state_, response_datas);
+ type_sync_proxy_->OnUpdateReceived(data_type_state_, response_datas);
return SYNCER_OK;
}
@@ -123,8 +123,7 @@ void ModelTypeSyncWorkerImpl::ApplyUpdates(sessions::StatusController* status) {
data_type_state_.initial_sync_done = true;
UpdateResponseDataList empty_update_list;
- type_sync_proxy_->ReceiveUpdateResponse(data_type_state_,
- empty_update_list);
+ type_sync_proxy_->OnUpdateReceived(data_type_state_, empty_update_list);
}
}
@@ -247,7 +246,7 @@ void ModelTypeSyncWorkerImpl::OnCommitResponse(
// Send the responses back to the model thread. It needs to know which
// items have been successfully committed so it can save that information in
// permanent storage.
- type_sync_proxy_->ReceiveCommitResponse(data_type_state_, response_list);
+ type_sync_proxy_->OnCommitCompleted(data_type_state_, response_list);
}
base::WeakPtr<ModelTypeSyncWorkerImpl> ModelTypeSyncWorkerImpl::AsWeakPtr() {
diff --git a/sync/engine/model_type_sync_worker_impl.h b/sync/engine/model_type_sync_worker_impl.h
index a0e87b1..5837222 100644
--- a/sync/engine/model_type_sync_worker_impl.h
+++ b/sync/engine/model_type_sync_worker_impl.h
@@ -10,6 +10,7 @@
#include "base/threading/non_thread_safe.h"
#include "sync/base/sync_export.h"
#include "sync/engine/commit_contributor.h"
+#include "sync/engine/model_type_sync_worker.h"
#include "sync/engine/non_blocking_sync_common.h"
#include "sync/engine/update_handler.h"
#include "sync/internal_api/public/base/model_type.h"
@@ -46,6 +47,7 @@ class EntityTracker;
// cancel the pending commit.
class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler,
public CommitContributor,
+ public ModelTypeSyncWorker,
public base::NonThreadSafe {
public:
ModelTypeSyncWorkerImpl(ModelType type,
@@ -68,8 +70,9 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler,
virtual void ApplyUpdates(sessions::StatusController* status) OVERRIDE;
virtual void PassiveApplyUpdates(sessions::StatusController* status) OVERRIDE;
- // Entry point for the ModelTypeSyncProxy to send commit requests.
- void EnqueueForCommit(const CommitRequestDataList& request_list);
+ // ModelTypeSyncWorker implementation.
+ virtual void EnqueueForCommit(
+ const CommitRequestDataList& request_list) OVERRIDE;
// CommitContributor implementation.
virtual scoped_ptr<CommitContribution> GetContribution(
diff --git a/sync/internal_api/sync_context.h b/sync/internal_api/public/sync_context.h
index 3dc2ae0..67b1a41 100644
--- a/sync/internal_api/sync_context.h
+++ b/sync/internal_api/public/sync_context.h
@@ -13,7 +13,6 @@
namespace syncer {
-class ModelTypeRegistry;
class ModelTypeSyncProxyImpl;
struct DataTypeState;
@@ -27,17 +26,17 @@ struct DataTypeState;
// instantiate.
class SYNC_EXPORT_PRIVATE SyncContext {
public:
- explicit SyncContext(ModelTypeRegistry* model_type_registry);
- ~SyncContext();
+ SyncContext();
+ virtual ~SyncContext();
// Initializes the connection between the sync context on the sync thread and
// a proxy for the specified non-blocking sync type that lives on the data
// type's thread.
- void ConnectSyncTypeToWorker(
+ virtual void ConnectSyncTypeToWorker(
syncer::ModelType type,
const DataTypeState& data_type_state,
const scoped_refptr<base::SequencedTaskRunner>& datatype_task_runner,
- const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy);
+ const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0;
// Disconnects the syncer from the model and stops syncing the type.
//
@@ -48,15 +47,7 @@ class SYNC_EXPORT_PRIVATE SyncContext {
// This is the sync thread's chance to clear state associated with the type.
// It also causes the syncer to stop requesting updates for this type, and to
// abort any in-progress commit requests.
- void Disconnect(ModelType type);
-
- base::WeakPtr<SyncContext> AsWeakPtr();
-
- private:
- ModelTypeRegistry* model_type_registry_;
- base::WeakPtrFactory<SyncContext> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(SyncContext);
+ virtual void DisconnectSyncWorker(ModelType type) = 0;
};
} // namespace syncer
diff --git a/sync/internal_api/sync_context.cc b/sync/internal_api/sync_context.cc
index a1e87e2..d5253b4 100644
--- a/sync/internal_api/sync_context.cc
+++ b/sync/internal_api/sync_context.cc
@@ -2,38 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/sync_context.h"
+#include "sync/internal_api/public/sync_context.h"
#include "sync/engine/model_type_sync_worker_impl.h"
-#include "sync/sessions/model_type_registry.h"
namespace syncer {
-SyncContext::SyncContext(ModelTypeRegistry* model_type_registry)
- : model_type_registry_(model_type_registry), weak_ptr_factory_(this) {
+SyncContext::SyncContext() {
}
SyncContext::~SyncContext() {
}
-void SyncContext::ConnectSyncTypeToWorker(
- ModelType type,
- const DataTypeState& data_type_state,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner,
- const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) {
- // Initialize the type sync proxy's sync-thread sibling and the
- // ModelTypeSyncProxy <-> ModelTypeSyncWorker
- // (ie. model thread <-> sync thread) communication channel.
- model_type_registry_->InitializeNonBlockingType(
- type, data_type_state, task_runner, type_sync_proxy);
-}
-
-void SyncContext::Disconnect(ModelType type) {
- model_type_registry_->RemoveNonBlockingType(type);
-}
-
-base::WeakPtr<SyncContext> SyncContext::AsWeakPtr() {
- return weak_ptr_factory_.GetWeakPtr();
-}
-
} // namespace syncer
diff --git a/sync/internal_api/sync_context_proxy_impl.cc b/sync/internal_api/sync_context_proxy_impl.cc
index 77f3d6a..91edfbe 100644
--- a/sync/internal_api/sync_context_proxy_impl.cc
+++ b/sync/internal_api/sync_context_proxy_impl.cc
@@ -8,7 +8,7 @@
#include "base/location.h"
#include "base/message_loop/message_loop_proxy.h"
#include "sync/engine/non_blocking_sync_common.h"
-#include "sync/internal_api/sync_context.h"
+#include "sync/internal_api/public/sync_context.h"
namespace syncer {
@@ -37,7 +37,8 @@ void SyncContextProxyImpl::ConnectTypeToSync(
void SyncContextProxyImpl::Disconnect(ModelType type) {
sync_task_runner_->PostTask(
- FROM_HERE, base::Bind(&SyncContext::Disconnect, sync_context_, type));
+ FROM_HERE,
+ base::Bind(&SyncContext::DisconnectSyncWorker, sync_context_, type));
}
scoped_ptr<SyncContextProxy> SyncContextProxyImpl::Clone() const {
diff --git a/sync/internal_api/sync_context_proxy_impl_unittest.cc b/sync/internal_api/sync_context_proxy_impl_unittest.cc
index 62edfec..18f5bbf 100644
--- a/sync/internal_api/sync_context_proxy_impl_unittest.cc
+++ b/sync/internal_api/sync_context_proxy_impl_unittest.cc
@@ -8,7 +8,7 @@
#include "base/sequenced_task_runner.h"
#include "sync/engine/model_type_sync_proxy_impl.h"
#include "sync/internal_api/public/base/model_type.h"
-#include "sync/internal_api/sync_context.h"
+#include "sync/internal_api/public/sync_context.h"
#include "sync/internal_api/sync_context_proxy_impl.h"
#include "sync/sessions/model_type_registry.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,12 +20,12 @@ class SyncContextProxyImplTest : public ::testing::Test {
SyncContextProxyImplTest()
: sync_task_runner_(base::MessageLoopProxy::current()),
type_task_runner_(base::MessageLoopProxy::current()),
- context_(new SyncContext(&registry_)),
- context_proxy_(sync_task_runner_, context_->AsWeakPtr()) {}
+ registry_(new ModelTypeRegistry()),
+ context_proxy_(sync_task_runner_, registry_->AsWeakPtr()) {}
// The sync thread could be shut down at any time without warning. This
// function simulates such an event.
- void DisableSync() { context_.reset(); }
+ void DisableSync() { registry_.reset(); }
scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_.Clone(); }
@@ -33,8 +33,7 @@ class SyncContextProxyImplTest : public ::testing::Test {
base::MessageLoop loop_;
scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
scoped_refptr<base::SequencedTaskRunner> type_task_runner_;
- ModelTypeRegistry registry_;
- scoped_ptr<SyncContext> context_;
+ scoped_ptr<ModelTypeRegistry> registry_;
SyncContextProxyImpl context_proxy_;
};
diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc
index bf73315..eece641 100644
--- a/sync/internal_api/sync_manager_impl.cc
+++ b/sync/internal_api/sync_manager_impl.cc
@@ -28,12 +28,12 @@
#include "sync/internal_api/public/internal_components_factory.h"
#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/read_transaction.h"
+#include "sync/internal_api/public/sync_context.h"
#include "sync/internal_api/public/sync_context_proxy.h"
#include "sync/internal_api/public/user_share.h"
#include "sync/internal_api/public/util/experiments.h"
#include "sync/internal_api/public/write_node.h"
#include "sync/internal_api/public/write_transaction.h"
-#include "sync/internal_api/sync_context.h"
#include "sync/internal_api/sync_context_proxy_impl.h"
#include "sync/internal_api/syncapi_internal.h"
#include "sync/internal_api/syncapi_server_connection_manager.h"
@@ -390,11 +390,9 @@ void SyncManagerImpl::Init(
model_type_registry_.reset(new ModelTypeRegistry(workers, directory()));
- sync_context_.reset(new SyncContext(model_type_registry_.get()));
-
// Bind the SyncContext WeakPtr to this thread. This helps us crash earlier
// if the pointer is misused in debug mode.
- base::WeakPtr<SyncContext> weak_core = sync_context_->AsWeakPtr();
+ base::WeakPtr<SyncContext> weak_core = model_type_registry_->AsWeakPtr();
weak_core.get();
sync_context_proxy_.reset(
diff --git a/sync/sessions/model_type_registry.cc b/sync/sessions/model_type_registry.cc
index b8ab74b..46e09a5 100644
--- a/sync/sessions/model_type_registry.cc
+++ b/sync/sessions/model_type_registry.cc
@@ -27,10 +27,10 @@ class ModelTypeSyncProxyWrapper : public ModelTypeSyncProxy {
const scoped_refptr<base::SequencedTaskRunner>& processor_task_runner);
virtual ~ModelTypeSyncProxyWrapper();
- virtual void ReceiveCommitResponse(
+ virtual void OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) OVERRIDE;
- virtual void ReceiveUpdateResponse(
+ virtual void OnUpdateReceived(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) OVERRIDE;
@@ -48,18 +48,18 @@ ModelTypeSyncProxyWrapper::ModelTypeSyncProxyWrapper(
ModelTypeSyncProxyWrapper::~ModelTypeSyncProxyWrapper() {
}
-void ModelTypeSyncProxyWrapper::ReceiveCommitResponse(
+void ModelTypeSyncProxyWrapper::OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) {
processor_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&ModelTypeSyncProxyImpl::OnCommitCompletion,
+ base::Bind(&ModelTypeSyncProxyImpl::OnCommitCompleted,
processor_,
type_state,
response_list));
}
-void ModelTypeSyncProxyWrapper::ReceiveUpdateResponse(
+void ModelTypeSyncProxyWrapper::OnUpdateReceived(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) {
processor_task_runner_->PostTask(
@@ -77,7 +77,7 @@ class ModelTypeSyncWorkerWrapper : public ModelTypeSyncWorker {
const scoped_refptr<base::SequencedTaskRunner>& sync_thread);
virtual ~ModelTypeSyncWorkerWrapper();
- virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE;
+ virtual void EnqueueForCommit(const CommitRequestDataList& list) OVERRIDE;
private:
base::WeakPtr<ModelTypeSyncWorkerImpl> worker_;
@@ -93,7 +93,7 @@ ModelTypeSyncWorkerWrapper::ModelTypeSyncWorkerWrapper(
ModelTypeSyncWorkerWrapper::~ModelTypeSyncWorkerWrapper() {
}
-void ModelTypeSyncWorkerWrapper::RequestCommits(
+void ModelTypeSyncWorkerWrapper::EnqueueForCommit(
const CommitRequestDataList& list) {
sync_thread_->PostTask(
FROM_HERE,
@@ -102,12 +102,14 @@ void ModelTypeSyncWorkerWrapper::RequestCommits(
} // namespace
-ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {}
+ModelTypeRegistry::ModelTypeRegistry()
+ : directory_(NULL), weak_ptr_factory_(this) {
+}
ModelTypeRegistry::ModelTypeRegistry(
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
syncable::Directory* directory)
- : directory_(directory) {
+ : directory_(directory), weak_ptr_factory_(this) {
for (size_t i = 0u; i < workers.size(); ++i) {
workers_map_.insert(
std::make_pair(workers[i]->GetModelSafeGroup(), workers[i]));
@@ -181,7 +183,7 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes(
GetEnabledNonBlockingTypes()).Empty());
}
-void ModelTypeRegistry::InitializeNonBlockingType(
+void ModelTypeRegistry::ConnectSyncTypeToWorker(
ModelType type,
const DataTypeState& data_type_state,
const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
@@ -217,7 +219,7 @@ void ModelTypeRegistry::InitializeNonBlockingType(
GetEnabledNonBlockingTypes()).Empty());
}
-void ModelTypeRegistry::RemoveNonBlockingType(ModelType type) {
+void ModelTypeRegistry::DisconnectSyncWorker(ModelType type) {
DVLOG(1) << "Disabling an off-thread sync type: " << ModelTypeToString(type);
DCHECK(update_handler_map_.find(type) != update_handler_map_.end());
DCHECK(commit_contributor_map_.find(type) != commit_contributor_map_.end());
@@ -283,6 +285,10 @@ void ModelTypeRegistry::RequestEmitDebugInfo() {
}
}
+base::WeakPtr<SyncContext> ModelTypeRegistry::AsWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const {
return enabled_directory_types_;
}
diff --git a/sync/sessions/model_type_registry.h b/sync/sessions/model_type_registry.h
index 255a841..4444682 100644
--- a/sync/sessions/model_type_registry.h
+++ b/sync/sessions/model_type_registry.h
@@ -10,10 +10,12 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
#include "sync/base/sync_export.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/sessions/type_debug_info_observer.h"
+#include "sync/internal_api/public/sync_context.h"
namespace syncer {
@@ -36,7 +38,7 @@ typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
DirectoryTypeDebugInfoEmitterMap;
// Keeps track of the sets of active update handlers and commit contributors.
-class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
+class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext {
public:
// This alternative constructor does not support any directory types.
// It is used only in tests.
@@ -46,7 +48,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
ModelTypeRegistry(
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
syncable::Directory* directory);
- ~ModelTypeRegistry();
+ virtual ~ModelTypeRegistry();
// Sets the set of enabled types.
void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info);
@@ -55,17 +57,17 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
// and its task_runner to the newly created worker.
//
// Expects that the proxy's ModelType is not currently enabled.
- void InitializeNonBlockingType(
+ virtual void ConnectSyncTypeToWorker(
syncer::ModelType type,
const DataTypeState& data_type_state,
const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
- const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy);
+ const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE;
// Disables the syncing of an off-thread type.
//
// Expects that the type is currently enabled.
// Deletes the worker associated with the type.
- void RemoveNonBlockingType(syncer::ModelType type);
+ virtual void DisconnectSyncWorker(syncer::ModelType type) OVERRIDE;
// Gets the set of enabled types.
ModelTypeSet GetEnabledTypes() const;
@@ -83,6 +85,8 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
syncer::TypeDebugInfoObserver* observer);
void RequestEmitDebugInfo();
+ base::WeakPtr<SyncContext> AsWeakPtr();
+
private:
ModelTypeSet GetEnabledNonBlockingTypes() const;
ModelTypeSet GetEnabledDirectoryTypes() const;
@@ -122,10 +126,11 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry {
// guaranteed to live as long as this sync backend.
ObserverList<TypeDebugInfoObserver> type_debug_info_observers_;
+ base::WeakPtrFactory<ModelTypeRegistry> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ModelTypeRegistry);
};
} // namespace syncer
#endif // SYNC_ENGINE_MODEL_TYPE_REGISTRY_H_
-
diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc
index d9d314e..ca1ddb1 100644
--- a/sync/sessions/model_type_registry_unittest.cc
+++ b/sync/sessions/model_type_registry_unittest.cc
@@ -147,21 +147,21 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) {
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
- registry()->InitializeNonBlockingType(syncer::THEMES,
- MakeInitialDataTypeState(THEMES),
- task_runner,
- themes_sync_proxy.AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::THEMES,
+ MakeInitialDataTypeState(THEMES),
+ task_runner,
+ themes_sync_proxy.AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES)));
- registry()->InitializeNonBlockingType(syncer::SESSIONS,
- MakeInitialDataTypeState(SESSIONS),
- task_runner,
- sessions_sync_proxy.AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
+ MakeInitialDataTypeState(SESSIONS),
+ task_runner,
+ sessions_sync_proxy.AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES, syncer::SESSIONS)));
- registry()->RemoveNonBlockingType(syncer::THEMES);
+ registry()->DisconnectSyncWorker(syncer::THEMES);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::SESSIONS)));
@@ -184,10 +184,10 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
// Add the themes non-blocking type.
- registry()->InitializeNonBlockingType(syncer::THEMES,
- MakeInitialDataTypeState(THEMES),
- task_runner,
- themes_sync_proxy.AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::THEMES,
+ MakeInitialDataTypeState(THEMES),
+ task_runner,
+ themes_sync_proxy.AsWeakPtrForUI());
current_types.Put(syncer::THEMES);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
@@ -197,15 +197,15 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
// Add sessions non-blocking type.
- registry()->InitializeNonBlockingType(syncer::SESSIONS,
- MakeInitialDataTypeState(SESSIONS),
- task_runner,
- sessions_sync_proxy.AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
+ MakeInitialDataTypeState(SESSIONS),
+ task_runner,
+ sessions_sync_proxy.AsWeakPtrForUI());
current_types.Put(syncer::SESSIONS);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
// Remove themes non-blocking type.
- registry()->RemoveNonBlockingType(syncer::THEMES);
+ registry()->DisconnectSyncWorker(syncer::THEMES);
current_types.Remove(syncer::THEMES);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
@@ -226,24 +226,24 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) {
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
- registry()->InitializeNonBlockingType(syncer::THEMES,
- MakeInitialDataTypeState(THEMES),
- task_runner,
- themes_sync_proxy->AsWeakPtrForUI());
- registry()->InitializeNonBlockingType(syncer::SESSIONS,
- MakeInitialDataTypeState(SESSIONS),
- task_runner,
- sessions_sync_proxy->AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::THEMES,
+ MakeInitialDataTypeState(THEMES),
+ task_runner,
+ themes_sync_proxy->AsWeakPtrForUI());
+ registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
+ MakeInitialDataTypeState(SESSIONS),
+ task_runner,
+ sessions_sync_proxy->AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES, syncer::SESSIONS)));
// Tear down themes processing, starting with the worker.
- registry()->RemoveNonBlockingType(syncer::THEMES);
+ registry()->DisconnectSyncWorker(syncer::THEMES);
themes_sync_proxy.reset();
// Tear down sessions processing, starting with the type sync proxy.
sessions_sync_proxy.reset();
- registry()->RemoveNonBlockingType(syncer::SESSIONS);
+ registry()->DisconnectSyncWorker(syncer::SESSIONS);
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
}
diff --git a/sync/sync_internal_api.gypi b/sync/sync_internal_api.gypi
index fc49a48f..6920ea0 100644
--- a/sync/sync_internal_api.gypi
+++ b/sync/sync_internal_api.gypi
@@ -120,6 +120,7 @@
'internal_api/public/sessions/update_counters.cc',
'internal_api/public/sessions/update_counters.h',
'internal_api/public/sync_auth_provider.h',
+ 'internal_api/public/sync_context.h',
'internal_api/public/sync_context_proxy.h',
'internal_api/public/sync_encryption_handler.cc',
'internal_api/public/sync_encryption_handler.h',
@@ -146,7 +147,6 @@
'internal_api/sync_backup_manager.cc',
'internal_api/sync_backup_manager.h',
'internal_api/sync_context.cc',
- 'internal_api/sync_context.h',
'internal_api/sync_context_proxy.cc',
'internal_api/sync_context_proxy_impl.cc',
'internal_api/sync_context_proxy_impl.h',
diff --git a/sync/test/engine/mock_model_type_sync_proxy.cc b/sync/test/engine/mock_model_type_sync_proxy.cc
index 440269d..56f53fb1 100644
--- a/sync/test/engine/mock_model_type_sync_proxy.cc
+++ b/sync/test/engine/mock_model_type_sync_proxy.cc
@@ -14,11 +14,11 @@ MockModelTypeSyncProxy::MockModelTypeSyncProxy() : is_synchronous_(true) {
MockModelTypeSyncProxy::~MockModelTypeSyncProxy() {
}
-void MockModelTypeSyncProxy::ReceiveCommitResponse(
+void MockModelTypeSyncProxy::OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) {
base::Closure task =
- base::Bind(&MockModelTypeSyncProxy::ReceiveCommitResponseImpl,
+ base::Bind(&MockModelTypeSyncProxy::OnCommitCompletedImpl,
base::Unretained(this),
type_state,
response_list);
@@ -27,14 +27,13 @@ void MockModelTypeSyncProxy::ReceiveCommitResponse(
RunQueuedTasks();
}
-void MockModelTypeSyncProxy::ReceiveUpdateResponse(
+void MockModelTypeSyncProxy::OnUpdateReceived(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) {
- base::Closure task =
- base::Bind(&MockModelTypeSyncProxy::ReceiveUpdateResponseImpl,
- base::Unretained(this),
- type_state,
- response_list);
+ base::Closure task = base::Bind(&MockModelTypeSyncProxy::OnUpdateReceivedImpl,
+ base::Unretained(this),
+ type_state,
+ response_list);
pending_tasks_.push_back(task);
if (is_synchronous_)
RunQueuedTasks();
@@ -164,7 +163,7 @@ CommitResponseData MockModelTypeSyncProxy::GetCommitResponse(
return it->second;
}
-void MockModelTypeSyncProxy::ReceiveCommitResponseImpl(
+void MockModelTypeSyncProxy::OnCommitCompletedImpl(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) {
received_commit_responses_.push_back(response_list);
@@ -180,7 +179,7 @@ void MockModelTypeSyncProxy::ReceiveCommitResponseImpl(
}
}
-void MockModelTypeSyncProxy::ReceiveUpdateResponseImpl(
+void MockModelTypeSyncProxy::OnUpdateReceivedImpl(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) {
received_update_responses_.push_back(response_list);
diff --git a/sync/test/engine/mock_model_type_sync_proxy.h b/sync/test/engine/mock_model_type_sync_proxy.h
index 54283d0..e6f16a9 100644
--- a/sync/test/engine/mock_model_type_sync_proxy.h
+++ b/sync/test/engine/mock_model_type_sync_proxy.h
@@ -31,10 +31,10 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
virtual ~MockModelTypeSyncProxy();
// Implementation of ModelTypeSyncProxy.
- virtual void ReceiveCommitResponse(
+ virtual void OnCommitCompleted(
const DataTypeState& type_state,
const CommitResponseDataList& response_list) OVERRIDE;
- virtual void ReceiveUpdateResponse(
+ virtual void OnUpdateReceived(
const DataTypeState& type_state,
const UpdateResponseDataList& response_list) OVERRIDE;
@@ -86,14 +86,14 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
// Process a received commit response.
//
// Implemented as an Impl method so we can defer its execution in some cases.
- void ReceiveCommitResponseImpl(const DataTypeState& type_state,
- const CommitResponseDataList& response_list);
+ void OnCommitCompletedImpl(const DataTypeState& type_state,
+ const CommitResponseDataList& response_list);
// Process a received update response.
//
// Implemented as an Impl method so we can defer its execution in some cases.
- void ReceiveUpdateResponseImpl(const DataTypeState& type_state,
- const UpdateResponseDataList& response_list);
+ void OnUpdateReceivedImpl(const DataTypeState& type_state,
+ const UpdateResponseDataList& response_list);
// Getter and setter for per-item sequence number tracking.
int64 GetCurrentSequenceNumber(const std::string& tag_hash) const;
diff --git a/sync/test/engine/mock_model_type_sync_worker.cc b/sync/test/engine/mock_model_type_sync_worker.cc
index 66c8242..9c90232 100644
--- a/sync/test/engine/mock_model_type_sync_worker.cc
+++ b/sync/test/engine/mock_model_type_sync_worker.cc
@@ -14,7 +14,7 @@ MockModelTypeSyncWorker::MockModelTypeSyncWorker() {
MockModelTypeSyncWorker::~MockModelTypeSyncWorker() {
}
-void MockModelTypeSyncWorker::RequestCommits(
+void MockModelTypeSyncWorker::EnqueueForCommit(
const CommitRequestDataList& list) {
commit_request_lists_.push_back(list);
}
diff --git a/sync/test/engine/mock_model_type_sync_worker.h b/sync/test/engine/mock_model_type_sync_worker.h
index deb675e9..5fb96f3 100644
--- a/sync/test/engine/mock_model_type_sync_worker.h
+++ b/sync/test/engine/mock_model_type_sync_worker.h
@@ -24,7 +24,7 @@ class MockModelTypeSyncWorker : public ModelTypeSyncWorker {
virtual ~MockModelTypeSyncWorker();
// Implementation of ModelTypeSyncWorker.
- virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE;
+ virtual void EnqueueForCommit(const CommitRequestDataList& list) OVERRIDE;
// Getters to inspect the requests sent to this object.
size_t GetNumCommitRequestLists() const;