diff options
author | pavely <pavely@chromium.org> | 2015-09-10 15:19:28 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-10 22:20:08 +0000 |
commit | 3c9575830013f5e70842c52c5757122e83b4dea8 (patch) | |
tree | 3765565a7308275b057cebf4aa1e8019ab0c6369 | |
parent | d98e50a25b7c98ede036b630c5bcde1700cb07bc (diff) | |
download | chromium_src-3c9575830013f5e70842c52c5757122e83b4dea8.zip chromium_src-3c9575830013f5e70842c52c5757122e83b4dea8.tar.gz chromium_src-3c9575830013f5e70842c52c5757122e83b4dea8.tar.bz2 |
[Sync] Introduce ModelTypeStore interface
In this change:
- Add empty ModelTypeStore interface
- Pass WeakPtr to store into ModelTypeProcessorImpl::ctor.
BUG=517663
R=stanisc@chromium.org
Review URL: https://codereview.chromium.org/1311363009
Cr-Commit-Position: refs/heads/master@{#348255}
-rw-r--r-- | components/sync_driver/non_blocking_data_type_controller_unittest.cc | 3 | ||||
-rw-r--r-- | sync/BUILD.gn | 2 | ||||
-rw-r--r-- | sync/api/model_type_store.cc | 13 | ||||
-rw-r--r-- | sync/api/model_type_store.h | 20 | ||||
-rw-r--r-- | sync/engine/model_type_processor_impl.cc | 5 | ||||
-rw-r--r-- | sync/engine/model_type_processor_impl.h | 9 | ||||
-rw-r--r-- | sync/engine/model_type_processor_impl_unittest.cc | 4 | ||||
-rw-r--r-- | sync/internal_api/sync_context_proxy_impl_unittest.cc | 12 | ||||
-rw-r--r-- | sync/sessions/model_type_registry_unittest.cc | 24 | ||||
-rw-r--r-- | sync/sync.gyp | 2 |
10 files changed, 76 insertions, 18 deletions
diff --git a/components/sync_driver/non_blocking_data_type_controller_unittest.cc b/components/sync_driver/non_blocking_data_type_controller_unittest.cc index c0e0ecb..ef31daa 100644 --- a/components/sync_driver/non_blocking_data_type_controller_unittest.cc +++ b/components/sync_driver/non_blocking_data_type_controller_unittest.cc @@ -120,7 +120,8 @@ class MockSyncContextProxy : public syncer_v2::SyncContextProxy { class NonBlockingDataTypeControllerTest : public testing::Test { public: NonBlockingDataTypeControllerTest() - : type_processor_(syncer::DICTIONARY), + : type_processor_(syncer::DICTIONARY, + base::WeakPtr<syncer_v2::ModelTypeStore>()), model_thread_(new base::TestSimpleTaskRunner()), sync_thread_(new base::TestSimpleTaskRunner()), controller_(syncer::DICTIONARY, true), diff --git a/sync/BUILD.gn b/sync/BUILD.gn index 2bc56fd..34b57b7 100644 --- a/sync/BUILD.gn +++ b/sync/BUILD.gn @@ -25,6 +25,8 @@ source_set("sync_core") { "api/attachments/attachment_store.h", "api/attachments/attachment_store_backend.cc", "api/attachments/attachment_store_backend.h", + "api/model_type_store.cc", + "api/model_type_store.h", "api/string_ordinal.h", "api/sync_change.cc", "api/sync_change.h", diff --git a/sync/api/model_type_store.cc b/sync/api/model_type_store.cc new file mode 100644 index 0000000..2555ddc --- /dev/null +++ b/sync/api/model_type_store.cc @@ -0,0 +1,13 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/api/model_type_store.h" + +namespace syncer_v2 { + +ModelTypeStore::ModelTypeStore() {} + +ModelTypeStore::~ModelTypeStore() {} + +} // namespace sync_v2 diff --git a/sync/api/model_type_store.h b/sync/api/model_type_store.h new file mode 100644 index 0000000..817238e --- /dev/null +++ b/sync/api/model_type_store.h @@ -0,0 +1,20 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_API_MODEL_TYPE_STORE_H_ +#define SYNC_API_MODEL_TYPE_STORE_H_ + +namespace syncer_v2 { + +// Interface for store used by ModelTypeProcessor for persisting sync related +// data (entity state and data type state). +class ModelTypeStore { + public: + ModelTypeStore(); + virtual ~ModelTypeStore(); +}; + +} // namespace syncer_v2 + +#endif // SYNC_API_MODEL_TYPE_STORE_H_ diff --git a/sync/engine/model_type_processor_impl.cc b/sync/engine/model_type_processor_impl.cc index 3afd428..55aa73b 100644 --- a/sync/engine/model_type_processor_impl.cc +++ b/sync/engine/model_type_processor_impl.cc @@ -13,10 +13,13 @@ namespace syncer_v2 { -ModelTypeProcessorImpl::ModelTypeProcessorImpl(syncer::ModelType type) +ModelTypeProcessorImpl::ModelTypeProcessorImpl( + syncer::ModelType type, + base::WeakPtr<ModelTypeStore> store) : type_(type), is_preferred_(false), is_connected_(false), + store_(store), weak_ptr_factory_for_ui_(this), weak_ptr_factory_for_sync_(this) {} diff --git a/sync/engine/model_type_processor_impl.h b/sync/engine/model_type_processor_impl.h index fb626e8..04a3141 100644 --- a/sync/engine/model_type_processor_impl.h +++ b/sync/engine/model_type_processor_impl.h @@ -18,6 +18,7 @@ namespace syncer_v2 { class CommitQueue; class ModelTypeEntity; +class ModelTypeStore; class SyncContextProxy; // A sync component embedded on the synced type's thread that helps to handle @@ -25,7 +26,8 @@ class SyncContextProxy; class SYNC_EXPORT_PRIVATE ModelTypeProcessorImpl : public ModelTypeProcessor, base::NonThreadSafe { public: - ModelTypeProcessorImpl(syncer::ModelType type); + ModelTypeProcessorImpl(syncer::ModelType type, + base::WeakPtr<ModelTypeStore> store); ~ModelTypeProcessorImpl() override; // Returns true if this object believes that sync is preferred for this type. @@ -141,6 +143,11 @@ class SYNC_EXPORT_PRIVATE ModelTypeProcessorImpl : public ModelTypeProcessor, // them across restarts, and keep them in sync with our progress markers. UpdateMap pending_updates_map_; + // Store is supplied by model type implementation. ModelTypeProcessorImpl + // uses store for persisting sync related data (entity state and data type + // state). + base::WeakPtr<ModelTypeStore> store_; + // We use two different WeakPtrFactories because we want the pointers they // issue to have different lifetimes. When asked to disconnect from the sync // thread, we want to make sure that no tasks generated as part of the diff --git a/sync/engine/model_type_processor_impl_unittest.cc b/sync/engine/model_type_processor_impl_unittest.cc index c1b6b88..8f57d69 100644 --- a/sync/engine/model_type_processor_impl_unittest.cc +++ b/sync/engine/model_type_processor_impl_unittest.cc @@ -135,7 +135,9 @@ ModelTypeProcessorImplTest::ModelTypeProcessorImplTest() : mock_queue_(new MockCommitQueue()), injectable_sync_context_proxy_( new InjectableSyncContextProxy(mock_queue_)), - type_processor_(new ModelTypeProcessorImpl(kModelType)) {} + type_processor_( + new ModelTypeProcessorImpl(kModelType, + base::WeakPtr<ModelTypeStore>())) {} ModelTypeProcessorImplTest::~ModelTypeProcessorImplTest() { } diff --git a/sync/internal_api/sync_context_proxy_impl_unittest.cc b/sync/internal_api/sync_context_proxy_impl_unittest.cc index 00fe80c..f4981d7 100644 --- a/sync/internal_api/sync_context_proxy_impl_unittest.cc +++ b/sync/internal_api/sync_context_proxy_impl_unittest.cc @@ -58,7 +58,8 @@ class SyncContextProxyImplTest : public ::testing::Test { // Try to connect a type to a SyncContext that has already shut down. TEST_F(SyncContextProxyImplTest, FailToConnect1) { - ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); + ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES, + base::WeakPtr<ModelTypeStore>()); DisableSync(); themes_sync_proxy.Enable(GetProxy()); @@ -69,7 +70,8 @@ TEST_F(SyncContextProxyImplTest, FailToConnect1) { // Try to connect a type to a SyncContext as it shuts down. TEST_F(SyncContextProxyImplTest, FailToConnect2) { - ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); + ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES, + base::WeakPtr<ModelTypeStore>()); themes_sync_proxy.Enable(GetProxy()); DisableSync(); @@ -81,7 +83,8 @@ TEST_F(SyncContextProxyImplTest, FailToConnect2) { // Tests the case where the type's sync proxy shuts down first. TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { scoped_ptr<ModelTypeProcessorImpl> themes_sync_proxy( - new ModelTypeProcessorImpl(syncer::THEMES)); + new ModelTypeProcessorImpl(syncer::THEMES, + base::WeakPtr<ModelTypeStore>())); themes_sync_proxy->Enable(GetProxy()); base::RunLoop run_loop_; @@ -94,7 +97,8 @@ TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { // Tests the case where the sync thread shuts down first. TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { scoped_ptr<ModelTypeProcessorImpl> themes_sync_proxy( - new ModelTypeProcessorImpl(syncer::THEMES)); + new ModelTypeProcessorImpl(syncer::THEMES, + base::WeakPtr<ModelTypeStore>())); themes_sync_proxy->Enable(GetProxy()); base::RunLoop run_loop_; diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc index 648a6a8..9ab1d29 100644 --- a/sync/sessions/model_type_registry_unittest.cc +++ b/sync/sessions/model_type_registry_unittest.cc @@ -17,8 +17,6 @@ namespace syncer { -using syncer_v2::ModelTypeProcessorImpl; - class ModelTypeRegistryTest : public ::testing::Test { public: ModelTypeRegistryTest(); @@ -145,8 +143,10 @@ TEST_F(ModelTypeRegistryTest, SetEnabledDirectoryTypes_OffAndOn) { } TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { - ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); - ModelTypeProcessorImpl sessions_sync_proxy(syncer::SESSIONS); + syncer_v2::ModelTypeProcessorImpl themes_sync_proxy( + syncer::THEMES, base::WeakPtr<syncer_v2::ModelTypeStore>()); + syncer_v2::ModelTypeProcessorImpl sessions_sync_proxy( + syncer::SESSIONS, base::WeakPtr<syncer_v2::ModelTypeStore>()); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner( base::ThreadTaskRunnerHandle::Get()); @@ -176,8 +176,10 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { } TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { - ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); - ModelTypeProcessorImpl sessions_sync_proxy(syncer::SESSIONS); + syncer_v2::ModelTypeProcessorImpl themes_sync_proxy( + syncer::THEMES, base::WeakPtr<syncer_v2::ModelTypeStore>()); + syncer_v2::ModelTypeProcessorImpl sessions_sync_proxy( + syncer::SESSIONS, base::WeakPtr<syncer_v2::ModelTypeStore>()); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner( base::ThreadTaskRunnerHandle::Get()); @@ -224,10 +226,12 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { } TEST_F(ModelTypeRegistryTest, DeletionOrdering) { - scoped_ptr<ModelTypeProcessorImpl> themes_sync_proxy( - new ModelTypeProcessorImpl(syncer::THEMES)); - scoped_ptr<ModelTypeProcessorImpl> sessions_sync_proxy( - new ModelTypeProcessorImpl(syncer::SESSIONS)); + scoped_ptr<syncer_v2::ModelTypeProcessorImpl> themes_sync_proxy( + new syncer_v2::ModelTypeProcessorImpl( + syncer::THEMES, base::WeakPtr<syncer_v2::ModelTypeStore>())); + scoped_ptr<syncer_v2::ModelTypeProcessorImpl> sessions_sync_proxy( + new syncer_v2::ModelTypeProcessorImpl( + syncer::SESSIONS, base::WeakPtr<syncer_v2::ModelTypeStore>())); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner( base::ThreadTaskRunnerHandle::Get()); diff --git a/sync/sync.gyp b/sync/sync.gyp index 37eb375..177c332 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -76,6 +76,8 @@ 'api/attachments/attachment_store.h', 'api/attachments/attachment_store_backend.cc', 'api/attachments/attachment_store_backend.h', + 'api/model_type_store.cc', + 'api/model_type_store.h', 'api/string_ordinal.h', 'api/sync_change.cc', 'api/sync_change.h', |