Skip to content

Commit

Permalink
[Sync] Introduce ModelTypeStore interface
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
pavely authored and Commit bot committed Sep 10, 2015
1 parent d98e50a commit 3c95758
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions sync/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions sync/api/model_type_store.cc
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions sync/api/model_type_store.h
Original file line number Diff line number Diff line change
@@ -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_
5 changes: 4 additions & 1 deletion sync/engine/model_type_processor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
9 changes: 8 additions & 1 deletion sync/engine/model_type_processor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
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
// communication between sync and model type threads.
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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion sync/engine/model_type_processor_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
12 changes: 8 additions & 4 deletions sync/internal_api/sync_context_proxy_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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();

Expand All @@ -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_;
Expand All @@ -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_;
Expand Down
24 changes: 14 additions & 10 deletions sync/sessions/model_type_registry_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace syncer {

using syncer_v2::ModelTypeProcessorImpl;

class ModelTypeRegistryTest : public ::testing::Test {
public:
ModelTypeRegistryTest();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions sync/sync.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3c95758

Please sign in to comment.