summaryrefslogtreecommitdiffstats
path: root/sync/sessions
diff options
context:
space:
mode:
authorstanisc <stanisc@chromium.org>2015-09-28 12:28:42 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-28 19:30:57 +0000
commita4e4a10e92844d0274895c1d078d9119fa76f041 (patch)
treeb91de6790c80c7c1587e54860fc47052d2bb15e9 /sync/sessions
parent516bee16e9437521cdd20a78d683f9dbaf35df3e (diff)
downloadchromium_src-a4e4a10e92844d0274895c1d078d9119fa76f041.zip
chromium_src-a4e4a10e92844d0274895c1d078d9119fa76f041.tar.gz
chromium_src-a4e4a10e92844d0274895c1d078d9119fa76f041.tar.bz2
USS SyncContextProxy / data type activation refactoring
This refactoring prepares the code to introduction of NonBlockingDataTypeController for USS datatypes. The goal was to split the very large NonBlockingDataTypeController change into a couple of smaller to make it easier to review and verify. The following changes are included here: 1) Introduced ActivationContext which is a structure that contains all arguments needed to activate a USS datatype. For now ActivationContext is passed via SyncContext / SyncContextProxy, but the goal is to pass it directly via BackendDataTypeConfigurer as an argument for ActivateNonBlockingDataType. ActivationContext is needed as a separate class because NonBlockingDataTypeController will have to receive it from the type processor's callback and temporarily hold on to it. 2) BackendDataTypeConfigurer - two activation methods are renamed to be directory specific and two more activation methods for non-blocking data types are added. 3) DataTypeController cleanup - OnModelLoaded() virtual method shouldn't be on the base class because it applies only to some of the subclasses and is never invoked via the base class. BUG=515962 Review URL: https://codereview.chromium.org/1368683003 Cr-Commit-Position: refs/heads/master@{#351110}
Diffstat (limited to 'sync/sessions')
-rw-r--r--sync/sessions/model_type_registry.cc18
-rw-r--r--sync/sessions/model_type_registry.h6
-rw-r--r--sync/sessions/model_type_registry_unittest.cc57
3 files changed, 49 insertions, 32 deletions
diff --git a/sync/sessions/model_type_registry.cc b/sync/sessions/model_type_registry.cc
index f0375f7..9c1609a 100644
--- a/sync/sessions/model_type_registry.cc
+++ b/sync/sessions/model_type_registry.cc
@@ -13,7 +13,7 @@
#include "sync/engine/model_type_processor.h"
#include "sync/engine/model_type_processor_impl.h"
#include "sync/engine/model_type_worker.h"
-#include "sync/internal_api/public/non_blocking_sync_common.h"
+#include "sync/internal_api/public/activation_context.h"
#include "sync/sessions/directory_type_debug_info_emitter.h"
#include "sync/util/cryptographer.h"
@@ -188,30 +188,30 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes(
void ModelTypeRegistry::ConnectSyncTypeToWorker(
ModelType type,
- const syncer_v2::DataTypeState& data_type_state,
- const syncer_v2::UpdateResponseDataList& saved_pending_updates,
- const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
- const base::WeakPtr<syncer_v2::ModelTypeProcessor>& type_processor) {
+ scoped_ptr<syncer_v2::ActivationContext> activation_context) {
DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type);
// Initialize Worker -> Processor communication channel.
scoped_ptr<syncer_v2::ModelTypeProcessor> processor_proxy(
- new ModelTypeProcessorProxy(type_processor, type_task_runner));
+ new ModelTypeProcessorProxy(activation_context->type_processor,
+ activation_context->type_task_runner));
scoped_ptr<Cryptographer> cryptographer_copy;
if (encrypted_types_.Has(type))
cryptographer_copy.reset(new Cryptographer(*cryptographer_));
scoped_ptr<syncer_v2::ModelTypeWorker> worker(new syncer_v2::ModelTypeWorker(
- type, data_type_state, saved_pending_updates, cryptographer_copy.Pass(),
+ type, activation_context->data_type_state,
+ activation_context->saved_pending_updates, cryptographer_copy.Pass(),
nudge_handler_, processor_proxy.Pass()));
// Initialize Processor -> Worker communication channel.
scoped_ptr<syncer_v2::CommitQueue> commit_queue_proxy(new CommitQueueProxy(
worker->AsWeakPtr(), scoped_refptr<base::SequencedTaskRunner>(
base::ThreadTaskRunnerHandle::Get())));
- type_task_runner->PostTask(
+ activation_context->type_task_runner->PostTask(
FROM_HERE, base::Bind(&syncer_v2::ModelTypeProcessor::OnConnect,
- type_processor, base::Passed(&commit_queue_proxy)));
+ activation_context->type_processor,
+ base::Passed(&commit_queue_proxy)));
DCHECK(update_handler_map_.find(type) == update_handler_map_.end());
DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end());
diff --git a/sync/sessions/model_type_registry.h b/sync/sessions/model_type_registry.h
index 9e097cf..6ac0c7c 100644
--- a/sync/sessions/model_type_registry.h
+++ b/sync/sessions/model_type_registry.h
@@ -63,11 +63,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry
// Expects that the proxy's ModelType is not currently enabled.
void ConnectSyncTypeToWorker(
syncer::ModelType type,
- const syncer_v2::DataTypeState& data_type_state,
- const syncer_v2::UpdateResponseDataList& saved_pending_updates,
- const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
- const base::WeakPtr<syncer_v2::ModelTypeProcessor>& type_processor)
- override;
+ scoped_ptr<syncer_v2::ActivationContext> activation_context) override;
// Disables the syncing of an off-thread type.
//
diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc
index 9ab1d29..74967ac 100644
--- a/sync/sessions/model_type_registry_unittest.cc
+++ b/sync/sessions/model_type_registry_unittest.cc
@@ -8,6 +8,7 @@
#include "base/message_loop/message_loop.h"
#include "base/thread_task_runner_handle.h"
#include "sync/engine/model_type_processor_impl.h"
+#include "sync/internal_api/public/activation_context.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/sessions/model_type_registry.h"
#include "sync/test/engine/fake_model_worker.h"
@@ -32,6 +33,20 @@ class ModelTypeRegistryTest : public ::testing::Test {
return state;
}
+ static scoped_ptr<syncer_v2::ActivationContext> MakeActivationContext(
+ const syncer_v2::DataTypeState& data_type_state,
+ const syncer_v2::UpdateResponseDataList& saved_pending_updates,
+ const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
+ const base::WeakPtr<syncer_v2::ModelTypeProcessor>& type_processor) {
+ scoped_ptr<syncer_v2::ActivationContext> context =
+ make_scoped_ptr(new syncer_v2::ActivationContext);
+ context->data_type_state = data_type_state;
+ context->saved_pending_updates = saved_pending_updates;
+ context->type_task_runner = type_task_runner;
+ context->type_processor = type_processor;
+ return context.Pass();
+ }
+
private:
syncable::Directory* directory();
@@ -154,16 +169,18 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) {
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
registry()->ConnectSyncTypeToWorker(
- syncer::THEMES, MakeInitialDataTypeState(THEMES),
- syncer_v2::UpdateResponseDataList(), task_runner,
- themes_sync_proxy.AsWeakPtrForUI());
+ syncer::THEMES,
+ MakeActivationContext(MakeInitialDataTypeState(THEMES),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ themes_sync_proxy.AsWeakPtrForUI()));
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES)));
registry()->ConnectSyncTypeToWorker(
- syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS),
- syncer_v2::UpdateResponseDataList(), task_runner,
- sessions_sync_proxy.AsWeakPtrForUI());
+ syncer::SESSIONS,
+ MakeActivationContext(MakeInitialDataTypeState(SESSIONS),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ sessions_sync_proxy.AsWeakPtrForUI()));
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES, syncer::SESSIONS)));
@@ -194,9 +211,10 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
// Add the themes non-blocking type.
registry()->ConnectSyncTypeToWorker(
- syncer::THEMES, MakeInitialDataTypeState(THEMES),
- syncer_v2::UpdateResponseDataList(), task_runner,
- themes_sync_proxy.AsWeakPtrForUI());
+ syncer::THEMES,
+ MakeActivationContext(MakeInitialDataTypeState(THEMES),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ themes_sync_proxy.AsWeakPtrForUI()));
current_types.Put(syncer::THEMES);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
@@ -207,9 +225,10 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
// Add sessions non-blocking type.
registry()->ConnectSyncTypeToWorker(
- syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS),
- syncer_v2::UpdateResponseDataList(), task_runner,
- sessions_sync_proxy.AsWeakPtrForUI());
+ syncer::SESSIONS,
+ MakeActivationContext(MakeInitialDataTypeState(SESSIONS),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ sessions_sync_proxy.AsWeakPtrForUI()));
current_types.Put(syncer::SESSIONS);
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types));
@@ -239,13 +258,15 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) {
EXPECT_TRUE(registry()->GetEnabledTypes().Empty());
registry()->ConnectSyncTypeToWorker(
- syncer::THEMES, MakeInitialDataTypeState(THEMES),
- syncer_v2::UpdateResponseDataList(), task_runner,
- themes_sync_proxy->AsWeakPtrForUI());
+ syncer::THEMES,
+ MakeActivationContext(MakeInitialDataTypeState(THEMES),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ themes_sync_proxy->AsWeakPtrForUI()));
registry()->ConnectSyncTypeToWorker(
- syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS),
- syncer_v2::UpdateResponseDataList(), task_runner,
- sessions_sync_proxy->AsWeakPtrForUI());
+ syncer::SESSIONS,
+ MakeActivationContext(MakeInitialDataTypeState(SESSIONS),
+ syncer_v2::UpdateResponseDataList(), task_runner,
+ sessions_sync_proxy->AsWeakPtrForUI()));
EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
ModelTypeSet(syncer::THEMES, syncer::SESSIONS)));