diff options
69 files changed, 1525 insertions, 1564 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index d92fe044..3249a45 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -16,7 +16,7 @@ #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/configure_reason.h" #include "sync/internal_api/public/sessions/sync_session_snapshot.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_manager.h" #include "sync/internal_api/public/sync_manager_factory.h" #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" @@ -148,11 +148,11 @@ class SyncBackendHost : public BackendDataTypeConfigurer { // initialization is complete with OnBackendInitialized(). virtual syncer::UserShare* GetUserShare() const = 0; - // Called on |frontend_loop_| to obtain a handle to the SyncCore needed by + // Called on |frontend_loop_| to obtain a handle to the SyncContext needed by // the non-blocking sync types to communicate with the server. // // Should be called only when the backend is initialized. - virtual scoped_ptr<syncer::SyncCoreProxy> GetSyncCoreProxy() = 0; + virtual scoped_ptr<syncer::SyncContextProxy> GetSyncContextProxy() = 0; // Called from any thread to obtain current status information in detailed or // summarized form. diff --git a/chrome/browser/sync/glue/sync_backend_host_core.cc b/chrome/browser/sync/glue/sync_backend_host_core.cc index 688ec23..1b6a5ff 100644 --- a/chrome/browser/sync/glue/sync_backend_host_core.cc +++ b/chrome/browser/sync/glue/sync_backend_host_core.cc @@ -17,7 +17,7 @@ #include "sync/internal_api/public/sessions/status_counters.h" #include "sync/internal_api/public/sessions/sync_session_snapshot.h" #include "sync/internal_api/public/sessions/update_counters.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_manager.h" #include "sync/internal_api/public/sync_manager_factory.h" @@ -494,12 +494,11 @@ void SyncBackendHostCore::DoFinishInitialProcessControlTypes() { synced_device_tracker_.get(), sync_manager_->GetUserShare()); - host_.Call( - FROM_HERE, - &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, - js_backend_, - debug_info_listener_, - sync_manager_->GetSyncCoreProxy()); + host_.Call(FROM_HERE, + &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, + js_backend_, + debug_info_listener_, + sync_manager_->GetSyncContextProxy()); js_backend_.Reset(); debug_info_listener_.Reset(); diff --git a/chrome/browser/sync/glue/sync_backend_host_impl.cc b/chrome/browser/sync/glue/sync_backend_host_impl.cc index 5f38753..dc0de63 100644 --- a/chrome/browser/sync/glue/sync_backend_host_impl.cc +++ b/chrome/browser/sync/glue/sync_backend_host_impl.cc @@ -256,7 +256,7 @@ void SyncBackendHostImpl::StopSyncingForShutdown() { notification_registrar_.RemoveAll(); // Stop non-blocking sync types from sending any more requests to the syncer. - sync_core_proxy_.reset(); + sync_context_proxy_.reset(); DCHECK(registrar_->sync_thread()->IsRunning()); @@ -459,10 +459,11 @@ syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { return core_->sync_manager()->GetUserShare(); } -scoped_ptr<syncer::SyncCoreProxy> SyncBackendHostImpl::GetSyncCoreProxy() { - return sync_core_proxy_.get() ? - scoped_ptr<syncer::SyncCoreProxy>(sync_core_proxy_->Clone()) : - scoped_ptr<syncer::SyncCoreProxy>(); +scoped_ptr<syncer::SyncContextProxy> +SyncBackendHostImpl::GetSyncContextProxy() { + return sync_context_proxy_.get() ? scoped_ptr<syncer::SyncContextProxy>( + sync_context_proxy_->Clone()) + : scoped_ptr<syncer::SyncContextProxy>(); } SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { @@ -645,11 +646,11 @@ void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( const syncer::WeakHandle<syncer::JsBackend> js_backend, const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener, - syncer::SyncCoreProxy* sync_core_proxy) { + syncer::SyncContextProxy* sync_context_proxy) { DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); - if (sync_core_proxy) - sync_core_proxy_ = sync_core_proxy->Clone(); + if (sync_context_proxy) + sync_context_proxy_ = sync_context_proxy->Clone(); if (!frontend_) return; diff --git a/chrome/browser/sync/glue/sync_backend_host_impl.h b/chrome/browser/sync/glue/sync_backend_host_impl.h index b347a99..2eb6014 100644 --- a/chrome/browser/sync/glue/sync_backend_host_impl.h +++ b/chrome/browser/sync/glue/sync_backend_host_impl.h @@ -115,7 +115,7 @@ class SyncBackendHostImpl virtual void DeactivateDataType(syncer::ModelType type) OVERRIDE; virtual void EnableEncryptEverything() OVERRIDE; virtual syncer::UserShare* GetUserShare() const OVERRIDE; - virtual scoped_ptr<syncer::SyncCoreProxy> GetSyncCoreProxy() OVERRIDE; + virtual scoped_ptr<syncer::SyncContextProxy> GetSyncContextProxy() OVERRIDE; virtual Status GetDetailedStatus() OVERRIDE; virtual syncer::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const OVERRIDE; @@ -170,14 +170,14 @@ class SyncBackendHostImpl // Reports backend initialization success. Includes some objects from sync // manager initialization to be passed back to the UI thread. // - // |sync_core_proxy| points to an object owned by the SyncManager. Ownership - // is not transferred, but we can obtain our own copy of the object using its - // Clone() method. + // |sync_context_proxy| points to an object owned by the SyncManager. + // Ownership is not transferred, but we can obtain our own copy of the object + // using its Clone() method. virtual void HandleInitializationSuccessOnFrontendLoop( - const syncer::WeakHandle<syncer::JsBackend> js_backend, - const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> - debug_info_listener, - syncer::SyncCoreProxy* sync_core_proxy); + const syncer::WeakHandle<syncer::JsBackend> js_backend, + const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> + debug_info_listener, + syncer::SyncContextProxy* sync_context_proxy); // Downloading of control types failed and will be retried. Invokes the // frontend's sync configure retry method. @@ -324,7 +324,7 @@ class SyncBackendHostImpl scoped_refptr<SyncBackendHostCore> core_; // A handle referencing the main interface for non-blocking sync types. - scoped_ptr<syncer::SyncCoreProxy> sync_core_proxy_; + scoped_ptr<syncer::SyncContextProxy> sync_context_proxy_; bool initialized_; diff --git a/chrome/browser/sync/glue/sync_backend_host_mock.cc b/chrome/browser/sync/glue/sync_backend_host_mock.cc index b1257a0..7a0eeeb 100644 --- a/chrome/browser/sync/glue/sync_backend_host_mock.cc +++ b/chrome/browser/sync/glue/sync_backend_host_mock.cc @@ -69,8 +69,9 @@ syncer::UserShare* SyncBackendHostMock::GetUserShare() const { return NULL; } -scoped_ptr<syncer::SyncCoreProxy> SyncBackendHostMock::GetSyncCoreProxy() { - return scoped_ptr<syncer::SyncCoreProxy>(); +scoped_ptr<syncer::SyncContextProxy> +SyncBackendHostMock::GetSyncContextProxy() { + return scoped_ptr<syncer::SyncContextProxy>(); } SyncBackendHost::Status SyncBackendHostMock::GetDetailedStatus() { diff --git a/chrome/browser/sync/glue/sync_backend_host_mock.h b/chrome/browser/sync/glue/sync_backend_host_mock.h index 42cfeae..e5ebb65 100644 --- a/chrome/browser/sync/glue/sync_backend_host_mock.h +++ b/chrome/browser/sync/glue/sync_backend_host_mock.h @@ -72,7 +72,7 @@ class SyncBackendHostMock : public SyncBackendHost { virtual syncer::UserShare* GetUserShare() const OVERRIDE; - virtual scoped_ptr<syncer::SyncCoreProxy> GetSyncCoreProxy() OVERRIDE; + virtual scoped_ptr<syncer::SyncContextProxy> GetSyncContextProxy() OVERRIDE; virtual Status GetDetailedStatus() OVERRIDE; diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 0cace5c..eb11ad8 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -85,7 +85,7 @@ #include "sync/internal_api/public/http_bridge_network_resources.h" #include "sync/internal_api/public/network_resources.h" #include "sync/internal_api/public/sessions/type_debug_info_observer.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_encryption_handler.h" #include "sync/internal_api/public/util/experiments.h" #include "sync/internal_api/public/util/sync_string_conversions.h" @@ -397,12 +397,10 @@ void ProfileSyncService::RegisterNonBlockingType(syncer::ModelType type) { void ProfileSyncService::InitializeNonBlockingType( syncer::ModelType type, - scoped_refptr<base::SequencedTaskRunner> task_runner, - base::WeakPtr<syncer::NonBlockingTypeProcessor> processor) { - non_blocking_data_type_manager_.InitializeTypeProcessor( - type, - task_runner, - processor); + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) { + non_blocking_data_type_manager_.InitializeType( + type, task_runner, type_sync_proxy); } bool ProfileSyncService::IsSessionsDataTypeControllerRunning() const { @@ -1016,7 +1014,7 @@ void ProfileSyncService::PostBackendInitialization() { } non_blocking_data_type_manager_.ConnectSyncBackend( - backend_->GetSyncCoreProxy()); + backend_->GetSyncContextProxy()); if (type_debug_info_observers_.might_have_observers()) { backend_->EnableDirectoryTypeDebugInfoForwarding(); diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index bd11376..719a1c0 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -344,8 +344,8 @@ class ProfileSyncService : public ProfileSyncServiceBase, // in a message that allows the component to delete its local sync state. void InitializeNonBlockingType( syncer::ModelType type, - scoped_refptr<base::SequencedTaskRunner> task_runner, - base::WeakPtr<syncer::NonBlockingTypeProcessor> processor); + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& proxy); // Return the active OpenTabsUIDelegate. If sessions is not enabled or not // currently syncing, returns NULL. diff --git a/components/sync_driver/non_blocking_data_type_controller.cc b/components/sync_driver/non_blocking_data_type_controller.cc index 55af708..21b1dab 100644 --- a/components/sync_driver/non_blocking_data_type_controller.cc +++ b/components/sync_driver/non_blocking_data_type_controller.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/location.h" -#include "sync/engine/non_blocking_type_processor.h" +#include "sync/engine/model_type_sync_proxy_impl.h" namespace browser_sync { @@ -19,30 +19,30 @@ NonBlockingDataTypeController::NonBlockingDataTypeController( NonBlockingDataTypeController::~NonBlockingDataTypeController() {} -void NonBlockingDataTypeController::InitializeProcessor( - scoped_refptr<base::SequencedTaskRunner> task_runner, - base::WeakPtr<syncer::NonBlockingTypeProcessor> processor) { - DCHECK(!IsTypeProcessorConnected()); +void NonBlockingDataTypeController::InitializeType( + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) { + DCHECK(!IsSyncProxyConnected()); task_runner_ = task_runner; - processor_ = processor; - DCHECK(IsTypeProcessorConnected()); + type_sync_proxy_ = type_sync_proxy; + DCHECK(IsSyncProxyConnected()); UpdateState(); } -void NonBlockingDataTypeController::InitializeSyncCoreProxy( - scoped_ptr<syncer::SyncCoreProxy> proxy) { +void NonBlockingDataTypeController::InitializeSyncContext( + scoped_ptr<syncer::SyncContextProxy> sync_context_proxy) { DCHECK(!IsSyncBackendConnected()); - proxy_ = proxy.Pass(); + sync_context_proxy_ = sync_context_proxy.Pass(); UpdateState(); } -void NonBlockingDataTypeController::ClearSyncCoreProxy() { - // Never had a sync core proxy to begin with. No change. - if (!proxy_) +void NonBlockingDataTypeController::ClearSyncContext() { + // Never had a sync context proxy to begin with. No change. + if (!sync_context_proxy_) return; - proxy_.reset(); + sync_context_proxy_.reset(); UpdateState(); } @@ -59,12 +59,12 @@ void NonBlockingDataTypeController::UpdateState() { return; } - // Return immediately if the processor is not ready yet. - if (!IsTypeProcessorConnected()) { + // Return immediately if the sync context proxy is not ready yet. + if (!IsSyncProxyConnected()) { return; } - // Send the appropriate state transition request to the processor. + // Send the appropriate state transition request to the type sync proxy. switch (GetDesiredState()) { case ENABLED: SendEnableSignal(); @@ -84,10 +84,11 @@ void NonBlockingDataTypeController::SendEnableSignal() { DCHECK_EQ(ENABLED, GetDesiredState()); DVLOG(1) << "Enabling non-blocking sync type " << ModelTypeToString(type_); - task_runner_->PostTask(FROM_HERE, - base::Bind(&syncer::NonBlockingTypeProcessor::Enable, - processor_, - base::Passed(proxy_->Clone()))); + task_runner_->PostTask( + FROM_HERE, + base::Bind(&syncer::ModelTypeSyncProxyImpl::Enable, + type_sync_proxy_, + base::Passed(sync_context_proxy_->Clone()))); current_state_ = ENABLED; } @@ -96,7 +97,7 @@ void NonBlockingDataTypeController::SendDisableSignal() { DVLOG(1) << "Disabling non-blocking sync type " << ModelTypeToString(type_); task_runner_->PostTask( FROM_HERE, - base::Bind(&syncer::NonBlockingTypeProcessor::Disable, processor_)); + base::Bind(&syncer::ModelTypeSyncProxyImpl::Disable, type_sync_proxy_)); current_state_ = DISABLED; } @@ -104,9 +105,9 @@ void NonBlockingDataTypeController::SendDisconnectSignal() { DCHECK_EQ(DISCONNECTED, GetDesiredState()); DVLOG(1) << "Disconnecting non-blocking sync type " << ModelTypeToString(type_); - task_runner_->PostTask( - FROM_HERE, - base::Bind(&syncer::NonBlockingTypeProcessor::Disconnect, processor_)); + task_runner_->PostTask(FROM_HERE, + base::Bind(&syncer::ModelTypeSyncProxyImpl::Disconnect, + type_sync_proxy_)); current_state_ = DISCONNECTED; } @@ -114,19 +115,19 @@ bool NonBlockingDataTypeController::IsPreferred() const { return is_preferred_; } -bool NonBlockingDataTypeController::IsTypeProcessorConnected() const { +bool NonBlockingDataTypeController::IsSyncProxyConnected() const { return task_runner_ != NULL; } bool NonBlockingDataTypeController::IsSyncBackendConnected() const { - return proxy_; + return sync_context_proxy_; } -NonBlockingDataTypeController::TypeProcessorState +NonBlockingDataTypeController::TypeState NonBlockingDataTypeController::GetDesiredState() const { if (!IsPreferred()) { return DISABLED; - } else if (!IsSyncBackendConnected() || !IsTypeProcessorConnected()) { + } else if (!IsSyncBackendConnected() || !IsSyncProxyConnected()) { return DISCONNECTED; } else { return ENABLED; diff --git a/components/sync_driver/non_blocking_data_type_controller.h b/components/sync_driver/non_blocking_data_type_controller.h index 4a1c66c..080e821 100644 --- a/components/sync_driver/non_blocking_data_type_controller.h +++ b/components/sync_driver/non_blocking_data_type_controller.h @@ -9,10 +9,10 @@ #include "base/memory/weak_ptr.h" #include "base/sequenced_task_runner.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" namespace syncer { -class NonBlockingTypeProcessor; +class ModelTypeSyncProxy; } namespace browser_sync { @@ -21,32 +21,33 @@ namespace browser_sync { // components. // // There are three main parts to this controller: -// - The SyncCoreProxy, represening the sync thread. -// - The NonBlockingTypeProcessor, representing the model type thread. +// - The SyncContextProxy, represening the sync thread. +// - The ModelTypeSyncProxy, representing the model type thread. // - The user-set state for this type (prefs), which lives on the UI thread. // -// The NonBlockingSyncTypeProcessor can exist in three different states. Those +// The ModelTypeSyncProxy can exist in three different states. Those // states are: // - Enabled: Changes are being synced. // - Disconnected: Changes would be synced, but there is no connection between // the sync thread and the model thread. -// - Disabled: Syncing is intentionally disabled. The processor may clear any +// - Disabled: Syncing is intentionally disabled. The type proxy may clear any // of its local state associated with sync when this happens, since // this is expected to last a while. // -// This controller is responsible for transitioning the processor into and out +// This controller is responsible for transitioning the type proxy into and out // of these states. It does this by posting tasks to the model type thread. // -// The processor is enabled when the user has indicated a desire to sync this -// type, and the NonBlockingTypeProcessor and SyncCoreProxy are available. +// The type proxy is enabled when the user has indicated a desire to sync this +// type, and the ModelTypeSyncProxy and SyncContextProxy are available. // -// The processor is disconnected during initialization, or when either the -// NonBlockingDataTypeController or SyncCoreProxy have not yet registered. It -// can also be disconnected later on if the sync backend becomes unavailable. +// The type proxy is disconnected during initialization, or when either the +// NonBlockingDataTypeController or SyncContextProxy have not yet registered. +// It can also be disconnected later on if the sync backend becomes +// unavailable. // -// The processor is disabled if the user has disabled sync for this type. The -// signal indicating this state will be sent to the processor when the pref is -// first changed, or when the processor first connects to the controller. +// The type proxy is disabled if the user has disabled sync for this type. The +// signal indicating this state will be sent to the type proxy when the pref is +// first changed, or when the type proxy first connects to the controller. // // This class is structured using some state machine patterns. It's a bit // awkward at times, but this seems to be the clearest way to express the @@ -56,21 +57,22 @@ class NonBlockingDataTypeController { NonBlockingDataTypeController(syncer::ModelType type, bool is_preferred); ~NonBlockingDataTypeController(); - // Connects the NonBlockingTypeProcessor to this controller. + // Connects the ModelTypeSyncProxy to this controller. // // There is no "undo" for this operation. The NonBlockingDataTypeController - // will only ever deal with a single processor. - void InitializeProcessor( - scoped_refptr<base::SequencedTaskRunner> task_runner, - base::WeakPtr<syncer::NonBlockingTypeProcessor> processor); + // will only ever deal with a single type proxy. + void InitializeType( + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy); - // Initialize the connection to the SyncCoreProxy. + // Initialize the connection to the SyncContextProxy. // - // This process may be reversed with ClearSyncCoreProxy(). - void InitializeSyncCoreProxy(scoped_ptr<syncer::SyncCoreProxy> proxy); + // This process may be reversed with ClearSyncContextProxy(). + void InitializeSyncContext( + scoped_ptr<syncer::SyncContextProxy> sync_context_proxy); - // Disconnect from the current SyncCoreProxy. - void ClearSyncCoreProxy(); + // Disconnect from the current SyncContextProxy. + void ClearSyncContext(); // Sets the current preferred state. // @@ -80,53 +82,54 @@ class NonBlockingDataTypeController { void SetIsPreferred(bool is_preferred); private: - enum TypeProcessorState { ENABLED, DISABLED, DISCONNECTED }; + enum TypeState { ENABLED, DISABLED, DISCONNECTED }; // Figures out which signals need to be sent then send then sends them. void UpdateState(); - // Sends an enable signal to the NonBlockingTypeProcessor. + // Sends an enable signal to the ModelTypeSyncProxyImpl. void SendEnableSignal(); - // Sends a disable signal to the NonBlockingTypeProcessor. + // Sends a disable signal to the ModelTypeSyncProxyImpl. void SendDisableSignal(); - // Sends a disconnect signal to the NonBlockingTypeProcessor. + // Sends a disconnect signal to the ModelTypeSyncProxyImpl. void SendDisconnectSignal(); // Returns true if this type should be synced. bool IsPreferred() const; - // Returns true if this object has access to the NonBlockingTypeProcessor. - bool IsTypeProcessorConnected() const; + // Returns true if this object has access to the ModelTypeSyncProxyImpl. + bool IsSyncProxyConnected() const; - // Returns true if this object has access to the SyncCoreProxy. + // Returns true if this object has access to the SyncContextProxy. bool IsSyncBackendConnected() const; - // Returns the state that the processor *should* be in. - TypeProcessorState GetDesiredState() const; + // Returns the state that the type sync proxy should be in. + TypeState GetDesiredState() const; // The ModelType we're controlling. Kept mainly for debugging. const syncer::ModelType type_; - // Returns the state that the processor is actually in, from this class' - // point of view. + // Returns the state that the type sync proxy is actually in, from this + // class' point of view. // // This state is inferred based on the most recently sent signals, and is - // intended to represent the state the processor will be in by the time any + // intended to represent the state the sync proxy will be in by the time any // tasks we post to it now will be run. Due to threading / queueing effects, // this may or may not be the actual state at this point in time. - TypeProcessorState current_state_; + TypeState current_state_; // Whether or not the user wants to sync this type. bool is_preferred_; - // The NonBlockingTypeProcessor and its associated thread. May be NULL. + // The ModelTypeSyncProxyImpl and its associated thread. May be NULL. scoped_refptr<base::SequencedTaskRunner> task_runner_; - base::WeakPtr<syncer::NonBlockingTypeProcessor> processor_; + base::WeakPtr<syncer::ModelTypeSyncProxyImpl> type_sync_proxy_; - // The SyncCoreProxy that connects to the current sync backend. May be NULL. - scoped_ptr<syncer::SyncCoreProxy> proxy_; + // The SyncContextProxy that connects to the current sync backend. May be + // NULL. + scoped_ptr<syncer::SyncContextProxy> sync_context_proxy_; DISALLOW_COPY_AND_ASSIGN(NonBlockingDataTypeController); }; 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 2c9076c..e01715d 100644 --- a/components/sync_driver/non_blocking_data_type_controller_unittest.cc +++ b/components/sync_driver/non_blocking_data_type_controller_unittest.cc @@ -11,54 +11,52 @@ #include "base/sequenced_task_runner.h" #include "base/test/test_simple_task_runner.h" #include "components/sync_driver/non_blocking_data_type_controller.h" -#include "sync/engine/non_blocking_type_processor.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" +#include "sync/engine/model_type_sync_proxy_impl.h" +#include "sync/engine/model_type_sync_worker.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { -class NonBlockingTypeProcessorCore; +class ModelTypeSyncWorker; namespace { -// A useless instance of NonBlockingTypeProcessorCore. -class NullNonBlockingTypeProcessorCore - : public NonBlockingTypeProcessorCoreInterface { +// A useless instance of ModelTypeSyncWorker. +class NullModelTypeSyncWorker : public ModelTypeSyncWorker { public: - NullNonBlockingTypeProcessorCore(); - virtual ~NullNonBlockingTypeProcessorCore(); + NullModelTypeSyncWorker(); + virtual ~NullModelTypeSyncWorker(); virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE; }; -NullNonBlockingTypeProcessorCore::NullNonBlockingTypeProcessorCore() { +NullModelTypeSyncWorker::NullModelTypeSyncWorker() { } -NullNonBlockingTypeProcessorCore::~NullNonBlockingTypeProcessorCore() { +NullModelTypeSyncWorker::~NullModelTypeSyncWorker() { } -void NullNonBlockingTypeProcessorCore::RequestCommits( +void NullModelTypeSyncWorker::RequestCommits( const CommitRequestDataList& list) { NOTREACHED() << "Not implemented."; } // A class that pretends to be the sync backend. -class MockSyncCore { +class MockSyncContext { public: void Connect( syncer::ModelType type, const scoped_refptr<base::SingleThreadTaskRunner>& model_task_runner, - const base::WeakPtr<syncer::NonBlockingTypeProcessor>& type_processor) { + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_proxy) { enabled_types_.Put(type); model_task_runner->PostTask( FROM_HERE, - base::Bind( - &syncer::NonBlockingTypeProcessor::OnConnect, - type_processor, - base::Passed(scoped_ptr<NonBlockingTypeProcessorCoreInterface>( - new NullNonBlockingTypeProcessorCore()).Pass()))); + base::Bind(&syncer::ModelTypeSyncProxyImpl::OnConnect, + type_proxy, + base::Passed(scoped_ptr<ModelTypeSyncWorker>( + new NullModelTypeSyncWorker()).Pass()))); } void Disconnect(syncer::ModelType type) { @@ -71,47 +69,48 @@ class MockSyncCore { syncer::ModelTypeSet enabled_types_; }; -// A proxy to the MockSyncCore that implements SyncCoreProxy. -class MockSyncCoreProxy : public syncer::SyncCoreProxy { +// A proxy to the MockSyncContext that implements SyncContextProxy. +class MockSyncContextProxy : public syncer::SyncContextProxy { public: - MockSyncCoreProxy( - MockSyncCore* sync_core, + MockSyncContextProxy( + MockSyncContext* sync_context, const scoped_refptr<base::TestSimpleTaskRunner>& model_task_runner, const scoped_refptr<base::TestSimpleTaskRunner>& sync_task_runner) - : mock_sync_core_(sync_core), + : mock_sync_context_(sync_context), model_task_runner_(model_task_runner), sync_task_runner_(sync_task_runner) {} - virtual ~MockSyncCoreProxy() {} + virtual ~MockSyncContextProxy() {} - virtual void ConnectTypeToCore( + virtual void ConnectTypeToSync( syncer::ModelType type, const DataTypeState& data_type_state, - base::WeakPtr<syncer::NonBlockingTypeProcessor> type_processor) OVERRIDE { + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_proxy) + OVERRIDE { // Normally we'd use MessageLoopProxy::current() as the TaskRunner argument // to Connect(). That won't work here in this test, so we use the // model_task_runner_ that was injected for this purpose instead. sync_task_runner_->PostTask(FROM_HERE, - base::Bind(&MockSyncCore::Connect, - base::Unretained(mock_sync_core_), + base::Bind(&MockSyncContext::Connect, + base::Unretained(mock_sync_context_), type, model_task_runner_, - type_processor)); + type_proxy)); } virtual void Disconnect(syncer::ModelType type) OVERRIDE { sync_task_runner_->PostTask(FROM_HERE, - base::Bind(&MockSyncCore::Disconnect, - base::Unretained(mock_sync_core_), + base::Bind(&MockSyncContext::Disconnect, + base::Unretained(mock_sync_context_), type)); } - virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE { - return scoped_ptr<SyncCoreProxy>(new MockSyncCoreProxy( - mock_sync_core_, model_task_runner_, sync_task_runner_)); + virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE { + return scoped_ptr<SyncContextProxy>(new MockSyncContextProxy( + mock_sync_context_, model_task_runner_, sync_task_runner_)); } private: - MockSyncCore* mock_sync_core_; + MockSyncContext* mock_sync_context_; scoped_refptr<base::TestSimpleTaskRunner> model_task_runner_; scoped_refptr<base::TestSimpleTaskRunner> sync_task_runner_; }; @@ -121,34 +120,35 @@ class MockSyncCoreProxy : public syncer::SyncCoreProxy { class NonBlockingDataTypeControllerTest : public testing::Test { public: NonBlockingDataTypeControllerTest() - : processor_(syncer::DICTIONARY), + : type_sync_proxy_(syncer::DICTIONARY), model_thread_(new base::TestSimpleTaskRunner()), sync_thread_(new base::TestSimpleTaskRunner()), controller_(syncer::DICTIONARY, true), - mock_core_proxy_(&mock_sync_core_, model_thread_, sync_thread_), + mock_context_proxy_(&mock_sync_context_, model_thread_, sync_thread_), auto_run_tasks_(true) {} virtual ~NonBlockingDataTypeControllerTest() {} - // Connects the processor to the NonBlockingDataTypeController. - void InitProcessor() { - controller_.InitializeProcessor(model_thread_, processor_.AsWeakPtrForUI()); + // Connects the sync type proxy to the NonBlockingDataTypeController. + void InitTypeSyncProxy() { + controller_.InitializeType(model_thread_, + type_sync_proxy_.AsWeakPtrForUI()); if (auto_run_tasks_) { RunAllTasks(); } } // Connects the sync backend to the NonBlockingDataTypeController. - void InitSync() { - controller_.InitializeSyncCoreProxy(mock_core_proxy_.Clone()); + void InitSyncBackend() { + controller_.InitializeSyncContext(mock_context_proxy_.Clone()); if (auto_run_tasks_) { RunAllTasks(); } } // Disconnects the sync backend from the NonBlockingDataTypeController. - void UninitializeSync() { - controller_.ClearSyncCoreProxy(); + void UninitializeSyncBackend() { + controller_.ClearSyncContext(); if (auto_run_tasks_) { RunAllTasks(); } @@ -169,7 +169,7 @@ class NonBlockingDataTypeControllerTest : public testing::Test { RunQueuedModelThreadTasks(); } - // The processor pretends to run tasks on a different thread. + // The sync type proxy pretends to run tasks on a different thread. // This function runs any posted tasks. void RunQueuedModelThreadTasks() { model_thread_->RunUntilIdle(); } @@ -182,14 +182,14 @@ class NonBlockingDataTypeControllerTest : public testing::Test { } protected: - syncer::NonBlockingTypeProcessor processor_; + syncer::ModelTypeSyncProxyImpl type_sync_proxy_; scoped_refptr<base::TestSimpleTaskRunner> model_thread_; scoped_refptr<base::TestSimpleTaskRunner> sync_thread_; browser_sync::NonBlockingDataTypeController controller_; - MockSyncCore mock_sync_core_; - MockSyncCoreProxy mock_core_proxy_; + MockSyncContext mock_sync_context_; + MockSyncContextProxy mock_context_proxy_; bool auto_run_tasks_; }; @@ -197,144 +197,144 @@ class NonBlockingDataTypeControllerTest : public testing::Test { // Initialization when the user has disabled syncing for this type. TEST_F(NonBlockingDataTypeControllerTest, UserDisabled) { SetIsPreferred(false); - InitProcessor(); - InitSync(); + InitTypeSyncProxy(); + InitSyncBackend(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); - UninitializeSync(); + UninitializeSyncBackend(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } -// Init the sync backend then the type processor. +// Init the sync backend then the type sync proxy. TEST_F(NonBlockingDataTypeControllerTest, Enabled_SyncFirst) { SetIsPreferred(true); - InitSync(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + InitSyncBackend(); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); - InitProcessor(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + InitTypeSyncProxy(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); - UninitializeSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + UninitializeSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } -// Init the type processor then the sync backend. +// Init the type sync proxy then the sync backend. TEST_F(NonBlockingDataTypeControllerTest, Enabled_ProcessorFirst) { SetIsPreferred(true); - InitProcessor(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + InitTypeSyncProxy(); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); - InitSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + InitSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); - UninitializeSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + UninitializeSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } // Initialize sync then disable it with a pref change. TEST_F(NonBlockingDataTypeControllerTest, PreferThenNot) { SetIsPreferred(true); - InitProcessor(); - InitSync(); + InitTypeSyncProxy(); + InitSyncBackend(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); SetIsPreferred(false); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } -// Connect type processor and sync backend, then toggle prefs repeatedly. +// Connect type sync proxy and sync backend, then toggle prefs repeatedly. TEST_F(NonBlockingDataTypeControllerTest, RepeatedTogglePreference) { SetIsPreferred(false); - InitProcessor(); - InitSync(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + InitTypeSyncProxy(); + InitSyncBackend(); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); SetIsPreferred(true); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); SetIsPreferred(false); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); SetIsPreferred(true); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); SetIsPreferred(false); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } // Test sync backend getting restarted while processor is connected. TEST_F(NonBlockingDataTypeControllerTest, RestartSyncBackend) { SetIsPreferred(true); - InitProcessor(); - InitSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + InitTypeSyncProxy(); + InitSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); // Shutting down sync backend should disconnect but not disable the type. - UninitializeSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + UninitializeSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); // Brining the backend back should reconnect the type. - InitSync(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + InitSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); } // Test sync backend being restarted before processor connects. TEST_F(NonBlockingDataTypeControllerTest, RestartSyncBackendEarly) { SetIsPreferred(true); - // Toggle sync off and on before the type processor is available. - InitSync(); - EXPECT_FALSE(processor_.IsConnected()); - UninitializeSync(); - EXPECT_FALSE(processor_.IsConnected()); - InitSync(); - EXPECT_FALSE(processor_.IsConnected()); + // Toggle sync off and on before the type sync proxy is available. + InitSyncBackend(); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + UninitializeSyncBackend(); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + InitSyncBackend(); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); // Introduce the processor. - InitProcessor(); - EXPECT_TRUE(processor_.IsConnected()); + InitTypeSyncProxy(); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); } // Test pref toggling before the sync backend has connected. TEST_F(NonBlockingDataTypeControllerTest, TogglePreferenceWithoutBackend) { SetIsPreferred(true); - InitProcessor(); + InitTypeSyncProxy(); // This should emit a disable signal. SetIsPreferred(false); - EXPECT_FALSE(processor_.IsConnected()); - EXPECT_FALSE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); // This won't enable us, since we don't have a sync backend. SetIsPreferred(true); - EXPECT_FALSE(processor_.IsConnected()); - EXPECT_FALSE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); // Only now do we start sending enable signals. - InitSync(); - EXPECT_TRUE(processor_.IsConnected()); - EXPECT_TRUE(processor_.IsPreferred()); + InitSyncBackend(); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); } // Turns off auto-task-running to test the effects of delaying a connection @@ -347,24 +347,24 @@ TEST_F(NonBlockingDataTypeControllerTest, DelayedConnect) { SetAutoRunTasks(false); SetIsPreferred(true); - InitProcessor(); - InitSync(); + InitTypeSyncProxy(); + InitSyncBackend(); // Allow the model to emit the request. RunQueuedModelThreadTasks(); // That should result in a request to connect, but it won't be // executed right away. - EXPECT_FALSE(processor_.IsConnected()); - EXPECT_TRUE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); // Let the sync thread process the request and the model thread handle its // response. RunQueuedSyncThreadTasks(); RunQueuedModelThreadTasks(); - EXPECT_TRUE(processor_.IsConnected()); - EXPECT_TRUE(processor_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); } // Send Disable signal while a connection request is in progress. @@ -372,16 +372,16 @@ TEST_F(NonBlockingDataTypeControllerTest, DisableRacesWithOnConnect) { SetAutoRunTasks(false); SetIsPreferred(true); - InitProcessor(); - InitSync(); + InitTypeSyncProxy(); + InitSyncBackend(); // Allow the model to emit the request. RunQueuedModelThreadTasks(); // That should result in a request to connect, but it won't be // executed right away. - EXPECT_FALSE(processor_.IsConnected()); - EXPECT_TRUE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); // Send and execute a disable signal before the OnConnect callback returns. SetIsPreferred(false); @@ -396,8 +396,8 @@ TEST_F(NonBlockingDataTypeControllerTest, DisableRacesWithOnConnect) { // from the UI thread earlier. We need to make sure that doesn't happen. RunQueuedModelThreadTasks(); - EXPECT_FALSE(processor_.IsPreferred()); - EXPECT_FALSE(processor_.IsConnected()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); } // Send a request to enable, then disable, then re-enable the data type. @@ -408,23 +408,23 @@ TEST_F(NonBlockingDataTypeControllerTest, EnableDisableEnableRace) { SetAutoRunTasks(false); SetIsPreferred(true); - InitProcessor(); - InitSync(); + InitTypeSyncProxy(); + InitSyncBackend(); RunQueuedModelThreadTasks(); // That was the first enable. - EXPECT_FALSE(processor_.IsConnected()); - EXPECT_TRUE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); // Now disable. SetIsPreferred(false); RunQueuedModelThreadTasks(); - EXPECT_FALSE(processor_.IsPreferred()); + EXPECT_FALSE(type_sync_proxy_.IsPreferred()); // And re-enable. SetIsPreferred(true); RunQueuedModelThreadTasks(); - EXPECT_TRUE(processor_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); // The sync thread has three messages related to those enables and // disables sittin in its queue. Let's allow it to process them. @@ -432,8 +432,8 @@ TEST_F(NonBlockingDataTypeControllerTest, EnableDisableEnableRace) { // Let the model thread process any messages from the sync thread. RunQueuedModelThreadTasks(); - EXPECT_TRUE(processor_.IsPreferred()); - EXPECT_TRUE(processor_.IsConnected()); + EXPECT_TRUE(type_sync_proxy_.IsPreferred()); + EXPECT_TRUE(type_sync_proxy_.IsConnected()); } } // namespace syncer diff --git a/components/sync_driver/non_blocking_data_type_manager.cc b/components/sync_driver/non_blocking_data_type_manager.cc index 19ed50e..348d0a6 100644 --- a/components/sync_driver/non_blocking_data_type_manager.cc +++ b/components/sync_driver/non_blocking_data_type_manager.cc @@ -6,7 +6,7 @@ #include "base/sequenced_task_runner.h" #include "components/sync_driver/non_blocking_data_type_controller.h" -#include "sync/engine/non_blocking_type_processor.h" +#include "sync/engine/model_type_sync_proxy_impl.h" namespace browser_sync { @@ -29,22 +29,22 @@ void NonBlockingDataTypeManager::RegisterType( enabled))); } -void NonBlockingDataTypeManager::InitializeTypeProcessor( - syncer::ModelType type, - const scoped_refptr<base::SequencedTaskRunner>& task_runner, - const base::WeakPtr<syncer::NonBlockingTypeProcessor>& processor) { +void NonBlockingDataTypeManager::InitializeType( + syncer::ModelType type, + const scoped_refptr<base::SequencedTaskRunner>& task_runner, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& proxy_impl) { NonBlockingDataTypeControllerMap::iterator it = non_blocking_data_type_controllers_.find(type); DCHECK(it != non_blocking_data_type_controllers_.end()); - it->second->InitializeProcessor(task_runner, processor); + it->second->InitializeType(task_runner, proxy_impl); } void NonBlockingDataTypeManager::ConnectSyncBackend( - scoped_ptr<syncer::SyncCoreProxy> proxy) { + scoped_ptr<syncer::SyncContextProxy> proxy) { for (NonBlockingDataTypeControllerMap::iterator it = non_blocking_data_type_controllers_.begin(); it != non_blocking_data_type_controllers_.end(); ++it) { - it->second->InitializeSyncCoreProxy(proxy->Clone()); + it->second->InitializeSyncContext(proxy->Clone()); } } @@ -52,7 +52,7 @@ void NonBlockingDataTypeManager::DisconnectSyncBackend() { for (NonBlockingDataTypeControllerMap::iterator it = non_blocking_data_type_controllers_.begin(); it != non_blocking_data_type_controllers_.end(); ++it) { - it->second->ClearSyncCoreProxy(); + it->second->ClearSyncContext(); } } diff --git a/components/sync_driver/non_blocking_data_type_manager.h b/components/sync_driver/non_blocking_data_type_manager.h index 49e85b3..19b4731 100644 --- a/components/sync_driver/non_blocking_data_type_manager.h +++ b/components/sync_driver/non_blocking_data_type_manager.h @@ -18,8 +18,8 @@ class SequencedTaskRunner; } // namespace base namespace syncer { -class NonBlockingTypeProcessor; -class SyncCoreProxy; +class ModelTypeSyncProxyImpl; +class SyncContextProxy; } //namespace syncer namespace browser_sync { @@ -42,16 +42,16 @@ class NonBlockingDataTypeManager { // The |preferred| flag indicates whether or not this type should be synced. void RegisterType(syncer::ModelType type, bool preferred); - // Connects the NonBlockingTypeProcessor and associated model type + // Connects the ModelTypeSyncProxyImpl and associated model type // thread to its NonBlockingDataTypeController on the UI thread. - void InitializeTypeProcessor( + void InitializeType( syncer::ModelType type, const scoped_refptr<base::SequencedTaskRunner>& task_runner, - const base::WeakPtr<syncer::NonBlockingTypeProcessor>& processor); + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy); - // Connects the sync backend, as represented by a SyncCoreProxy, to the + // Connects the sync backend, as represented by a SyncContextProxy, to the // NonBlockingDataTypeController on the UI thread. - void ConnectSyncBackend(scoped_ptr<syncer::SyncCoreProxy> proxy); + void ConnectSyncBackend(scoped_ptr<syncer::SyncContextProxy> proxy); // Disconnects the sync backend from the UI thread. Should be called // early on during shutdown, but the whole procedure is asynchronous so diff --git a/sync/engine/sync_thread_sync_entity.cc b/sync/engine/entity_tracker.cc index 21899d2..c9738b2 100644 --- a/sync/engine/sync_thread_sync_entity.cc +++ b/sync/engine/entity_tracker.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/sync_thread_sync_entity.h" +#include "sync/engine/entity_tracker.h" #include "base/logging.h" #include "sync/engine/non_blocking_sync_common.h" @@ -12,15 +12,14 @@ namespace syncer { -SyncThreadSyncEntity* SyncThreadSyncEntity::FromServerUpdate( +EntityTracker* EntityTracker::FromServerUpdate( const std::string& id_string, const std::string& client_tag_hash, int64 received_version) { - return new SyncThreadSyncEntity( - id_string, client_tag_hash, 0, received_version); + return new EntityTracker(id_string, client_tag_hash, 0, received_version); } -SyncThreadSyncEntity* SyncThreadSyncEntity::FromCommitRequest( +EntityTracker* EntityTracker::FromCommitRequest( const std::string& id_string, const std::string& client_tag_hash, int64 sequence_number, @@ -30,26 +29,25 @@ SyncThreadSyncEntity* SyncThreadSyncEntity::FromCommitRequest( const std::string& non_unique_name, bool deleted, const sync_pb::EntitySpecifics& specifics) { - return new SyncThreadSyncEntity(id_string, - client_tag_hash, - 0, - 0, - true, - sequence_number, - base_version, - ctime, - mtime, - non_unique_name, - deleted, - specifics); + return new EntityTracker(id_string, + client_tag_hash, + 0, + 0, + true, + sequence_number, + base_version, + ctime, + mtime, + non_unique_name, + deleted, + specifics); } // Constructor that does not set any pending commit fields. -SyncThreadSyncEntity::SyncThreadSyncEntity( - const std::string& id, - const std::string& client_tag_hash, - int64 highest_commit_response_version, - int64 highest_gu_response_version) +EntityTracker::EntityTracker(const std::string& id, + const std::string& client_tag_hash, + int64 highest_commit_response_version, + int64 highest_gu_response_version) : id_(id), client_tag_hash_(client_tag_hash), highest_commit_response_version_(highest_commit_response_version), @@ -60,19 +58,18 @@ SyncThreadSyncEntity::SyncThreadSyncEntity( deleted_(false) { } -SyncThreadSyncEntity::SyncThreadSyncEntity( - const std::string& id, - const std::string& client_tag_hash, - int64 highest_commit_response_version, - int64 highest_gu_response_version, - bool is_commit_pending, - int64 sequence_number, - int64 base_version, - base::Time ctime, - base::Time mtime, - const std::string& non_unique_name, - bool deleted, - const sync_pb::EntitySpecifics& specifics) +EntityTracker::EntityTracker(const std::string& id, + const std::string& client_tag_hash, + int64 highest_commit_response_version, + int64 highest_gu_response_version, + bool is_commit_pending, + int64 sequence_number, + int64 base_version, + base::Time ctime, + base::Time mtime, + const std::string& non_unique_name, + bool deleted, + const sync_pb::EntitySpecifics& specifics) : id_(id), client_tag_hash_(client_tag_hash), highest_commit_response_version_(highest_commit_response_version), @@ -87,16 +84,15 @@ SyncThreadSyncEntity::SyncThreadSyncEntity( specifics_(specifics) { } -SyncThreadSyncEntity::~SyncThreadSyncEntity() { +EntityTracker::~EntityTracker() { } -bool SyncThreadSyncEntity::IsCommitPending() const { +bool EntityTracker::IsCommitPending() const { return is_commit_pending_; } -void SyncThreadSyncEntity::PrepareCommitProto( - sync_pb::SyncEntity* commit_entity, - int64* sequence_number) const { +void EntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity, + int64* sequence_number) const { // Set ID if we have a server-assigned ID. Otherwise, it will be up to // our caller to assign a client-unique initial ID. if (base_version_ != kUncommittedVersion) { @@ -117,16 +113,15 @@ void SyncThreadSyncEntity::PrepareCommitProto( *sequence_number = sequence_number_; } -void SyncThreadSyncEntity::RequestCommit( - const std::string& id, - const std::string& client_tag_hash, - int64 sequence_number, - int64 base_version, - base::Time ctime, - base::Time mtime, - const std::string& non_unique_name, - bool deleted, - const sync_pb::EntitySpecifics& specifics) { +void EntityTracker::RequestCommit(const std::string& id, + const std::string& client_tag_hash, + int64 sequence_number, + int64 base_version, + base::Time ctime, + base::Time mtime, + const std::string& non_unique_name, + bool deleted, + const sync_pb::EntitySpecifics& specifics) { DCHECK_GE(base_version, base_version_) << "Base version should never decrease"; @@ -172,9 +167,9 @@ void SyncThreadSyncEntity::RequestCommit( specifics_ = specifics; } -void SyncThreadSyncEntity::ReceiveCommitResponse(const std::string& response_id, - int64 response_version, - int64 sequence_number) { +void EntityTracker::ReceiveCommitResponse(const std::string& response_id, + int64 response_version, + int64 sequence_number) { // Commit responses, especially after the first commit, can update our ID. id_ = response_id; @@ -197,7 +192,7 @@ void SyncThreadSyncEntity::ReceiveCommitResponse(const std::string& response_id, ClearPendingCommit(); } -void SyncThreadSyncEntity::ReceiveUpdate(int64 version) { +void EntityTracker::ReceiveUpdate(int64 version) { highest_gu_response_version_ = std::max(highest_gu_response_version_, version); @@ -208,7 +203,7 @@ void SyncThreadSyncEntity::ReceiveUpdate(int64 version) { } } -bool SyncThreadSyncEntity::IsInConflict() const { +bool EntityTracker::IsInConflict() const { if (!is_commit_pending_) return false; @@ -228,11 +223,11 @@ bool SyncThreadSyncEntity::IsInConflict() const { } } -bool SyncThreadSyncEntity::IsServerKnown() const { +bool EntityTracker::IsServerKnown() const { return base_version_ != kUncommittedVersion; } -void SyncThreadSyncEntity::ClearPendingCommit() { +void EntityTracker::ClearPendingCommit() { is_commit_pending_ = false; // Clearing the specifics might free up some memory. It can't hurt to try. diff --git a/sync/engine/sync_thread_sync_entity.h b/sync/engine/entity_tracker.h index 6ed9685..db2d09b 100644 --- a/sync/engine/sync_thread_sync_entity.h +++ b/sync/engine/entity_tracker.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ -#define SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ +#ifndef SYNC_ENGINE_ENTITY_TRACKER_H_ +#define SYNC_ENGINE_ENTITY_TRACKER_H_ #include <string> @@ -18,7 +18,7 @@ namespace syncer { // thread. // // It should be considered a helper class internal to the -// NonBlockingTypeProcessorCore. +// ModelTypeSyncWorker. // // Maintains the state associated with a particular sync entity which is // necessary for decision-making on the sync thread. It can track pending @@ -27,18 +27,17 @@ namespace syncer { // This object may or may not contain state associated with a pending commit. // If no commit is pending, the |is_commit_pending_| flag will be set to false // and many of this object's fields will be cleared. -class SYNC_EXPORT SyncThreadSyncEntity { +class SYNC_EXPORT EntityTracker { public: - ~SyncThreadSyncEntity(); + ~EntityTracker(); // Initialize a new entity based on an update response. - static SyncThreadSyncEntity* FromServerUpdate( - const std::string& id_string, - const std::string& client_tag_hash, - int64 version); + static EntityTracker* FromServerUpdate(const std::string& id_string, + const std::string& client_tag_hash, + int64 version); // Initialize a new entity based on a commit request. - static SyncThreadSyncEntity* FromCommitRequest( + static EntityTracker* FromCommitRequest( const std::string& id_string, const std::string& client_tag_hash, int64 sequence_number, @@ -85,24 +84,24 @@ class SYNC_EXPORT SyncThreadSyncEntity { private: // Initializes received update state. Does not initialize state related to // pending commits and sets |is_commit_pending_| to false. - SyncThreadSyncEntity(const std::string& id, - const std::string& client_tag_hash, - int64 highest_commit_response_version, - int64 highest_gu_response_version); + EntityTracker(const std::string& id, + const std::string& client_tag_hash, + int64 highest_commit_response_version, + int64 highest_gu_response_version); // Initializes all fields. Sets |is_commit_pending_| to true. - SyncThreadSyncEntity(const std::string& id, - const std::string& client_tag_hash, - int64 highest_commit_response_version, - int64 highest_gu_response_version, - bool is_commit_pending, - int64 sequence_number, - int64 base_version, - base::Time ctime, - base::Time mtime, - const std::string& non_unique_name, - bool deleted, - const sync_pb::EntitySpecifics& specifics); + EntityTracker(const std::string& id, + const std::string& client_tag_hash, + int64 highest_commit_response_version, + int64 highest_gu_response_version, + bool is_commit_pending, + int64 sequence_number, + int64 base_version, + base::Time ctime, + base::Time mtime, + const std::string& non_unique_name, + bool deleted, + const sync_pb::EntitySpecifics& specifics); // Checks if the current state indicates a conflict. // @@ -147,9 +146,9 @@ class SYNC_EXPORT SyncThreadSyncEntity { bool deleted_; sync_pb::EntitySpecifics specifics_; - DISALLOW_COPY_AND_ASSIGN(SyncThreadSyncEntity); + DISALLOW_COPY_AND_ASSIGN(EntityTracker); }; } // namespace syncer -#endif // SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ +#endif // SYNC_ENGINE_ENTITY_TRACKER_H_ diff --git a/sync/engine/sync_thread_sync_entity_unittest.cc b/sync/engine/entity_tracker_unittest.cc index be2604b..7a1b04b 100644 --- a/sync/engine/sync_thread_sync_entity_unittest.cc +++ b/sync/engine/entity_tracker_unittest.cc @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/sync_thread_sync_entity.h" +#include "sync/engine/entity_tracker.h" #include "base/memory/scoped_ptr.h" #include "base/time/time.h" @@ -14,18 +14,17 @@ namespace syncer { -// Some simple tests for the SyncThreadSyncEntity. +// Some simple tests for the EntityTracker. // -// The SyncThreadSyncEntity is an implementation detail of the -// NonBlockingTypeProcessorCore. As such, it doesn't make much sense to test -// it exhaustively, since it already gets a lot of test coverage from the -// NonBlockingTypeProcessorCore unit tests. +// The EntityTracker is an implementation detail of the ModelTypeSyncWorker. +// As such, it doesn't make much sense to test it exhaustively, since it +// already gets a lot of test coverage from the ModelTypeSyncWorker unit tests. // // These tests are intended as a basic sanity check. Anything more complicated // would be redundant. -class SyncThreadSyncEntityTest : public ::testing::Test { +class EntityTrackerTest : public ::testing::Test { public: - SyncThreadSyncEntityTest() + EntityTrackerTest() : kServerId("ServerID"), kClientTag("some.sample.tag"), kClientTagHash(syncable::GenerateSyncableHash(PREFERENCES, kClientTag)), @@ -35,7 +34,7 @@ class SyncThreadSyncEntityTest : public ::testing::Test { specifics.mutable_preference()->set_value("pref.value"); } - virtual ~SyncThreadSyncEntityTest() {} + virtual ~EntityTrackerTest() {} const std::string kServerId; const std::string kClientTag; @@ -46,9 +45,9 @@ class SyncThreadSyncEntityTest : public ::testing::Test { }; // Construct a new entity from a server update. Then receive another update. -TEST_F(SyncThreadSyncEntityTest, FromServerUpdate) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromServerUpdate(kServerId, kClientTagHash, 10)); +TEST_F(EntityTrackerTest, FromServerUpdate) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromServerUpdate(kServerId, kClientTagHash, 10)); EXPECT_FALSE(entity->IsCommitPending()); entity->ReceiveUpdate(20); @@ -56,17 +55,17 @@ TEST_F(SyncThreadSyncEntityTest, FromServerUpdate) { } // Construct a new entity from a commit request. Then serialize it. -TEST_F(SyncThreadSyncEntityTest, FromCommitRequest) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromCommitRequest(kServerId, - kClientTagHash, - 22, - 33, - kCtime, - kMtime, - kClientTag, - false, - specifics)); +TEST_F(EntityTrackerTest, FromCommitRequest) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromCommitRequest(kServerId, + kClientTagHash, + 22, + 33, + kCtime, + kMtime, + kClientTag, + false, + specifics)); ASSERT_TRUE(entity->IsCommitPending()); sync_pb::SyncEntity pb_entity; @@ -86,9 +85,9 @@ TEST_F(SyncThreadSyncEntityTest, FromCommitRequest) { } // Start with a server initiated entity. Commit over top of it. -TEST_F(SyncThreadSyncEntityTest, RequestCommit) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromServerUpdate(kServerId, kClientTagHash, 10)); +TEST_F(EntityTrackerTest, RequestCommit) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromServerUpdate(kServerId, kClientTagHash, 10)); entity->RequestCommit(kServerId, kClientTagHash, @@ -105,9 +104,9 @@ TEST_F(SyncThreadSyncEntityTest, RequestCommit) { // Start with a server initiated entity. Fail to request a commit because of // an out of date base version. -TEST_F(SyncThreadSyncEntityTest, RequestCommitFailure) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromServerUpdate(kServerId, kClientTagHash, 10)); +TEST_F(EntityTrackerTest, RequestCommitFailure) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromServerUpdate(kServerId, kClientTagHash, 10)); EXPECT_FALSE(entity->IsCommitPending()); entity->RequestCommit(kServerId, @@ -123,17 +122,17 @@ TEST_F(SyncThreadSyncEntityTest, RequestCommitFailure) { } // Start with a pending commit. Clobber it with an incoming update. -TEST_F(SyncThreadSyncEntityTest, UpdateClobbersCommit) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromCommitRequest(kServerId, - kClientTagHash, - 22, - 33, - kCtime, - kMtime, - kClientTag, - false, - specifics)); +TEST_F(EntityTrackerTest, UpdateClobbersCommit) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromCommitRequest(kServerId, + kClientTagHash, + 22, + 33, + kCtime, + kMtime, + kClientTag, + false, + specifics)); EXPECT_TRUE(entity->IsCommitPending()); @@ -143,17 +142,17 @@ TEST_F(SyncThreadSyncEntityTest, UpdateClobbersCommit) { // Start with a pending commit. Send it a reflected update that // will not override the in-progress commit. -TEST_F(SyncThreadSyncEntityTest, ReflectedUpdateDoesntClobberCommit) { - scoped_ptr<SyncThreadSyncEntity> entity( - SyncThreadSyncEntity::FromCommitRequest(kServerId, - kClientTagHash, - 22, - 33, - kCtime, - kMtime, - kClientTag, - false, - specifics)); +TEST_F(EntityTrackerTest, ReflectedUpdateDoesntClobberCommit) { + scoped_ptr<EntityTracker> entity( + EntityTracker::FromCommitRequest(kServerId, + kClientTagHash, + 22, + 33, + kCtime, + kMtime, + kClientTag, + false, + specifics)); EXPECT_TRUE(entity->IsCommitPending()); diff --git a/sync/engine/model_thread_sync_entity.cc b/sync/engine/model_type_entity.cc index 053a6c8..5acf5db 100644 --- a/sync/engine/model_thread_sync_entity.cc +++ b/sync/engine/model_type_entity.cc @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/model_thread_sync_entity.h" +#include "sync/engine/model_type_entity.h" #include "sync/syncable/syncable_util.h" namespace syncer { -scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::NewLocalItem( +scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem( const std::string& client_tag, const sync_pb::EntitySpecifics& specifics, base::Time now) { - return scoped_ptr<ModelThreadSyncEntity>(new ModelThreadSyncEntity( + return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity( 1, 0, 0, @@ -27,7 +27,7 @@ scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::NewLocalItem( now)); } -scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::FromServerUpdate( +scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( const std::string& id, const std::string& client_tag_hash, const std::string& non_unique_name, @@ -36,34 +36,32 @@ scoped_ptr<ModelThreadSyncEntity> ModelThreadSyncEntity::FromServerUpdate( bool deleted, base::Time ctime, base::Time mtime) { - return scoped_ptr<ModelThreadSyncEntity>( - new ModelThreadSyncEntity(0, - 0, - 0, - version, - true, - id, - client_tag_hash, - non_unique_name, - specifics, - deleted, - ctime, - mtime)); -} - -ModelThreadSyncEntity::ModelThreadSyncEntity( - int64 sequence_number, - int64 commit_requested_sequence_number, - int64 acked_sequence_number, - int64 base_version, - bool is_dirty, - const std::string& id, - const std::string& client_tag_hash, - const std::string& non_unique_name, - const sync_pb::EntitySpecifics& specifics, - bool deleted, - base::Time ctime, - base::Time mtime) + return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0, + 0, + 0, + version, + true, + id, + client_tag_hash, + non_unique_name, + specifics, + deleted, + ctime, + mtime)); +} + +ModelTypeEntity::ModelTypeEntity(int64 sequence_number, + int64 commit_requested_sequence_number, + int64 acked_sequence_number, + int64 base_version, + bool is_dirty, + const std::string& id, + const std::string& client_tag_hash, + const std::string& non_unique_name, + const sync_pb::EntitySpecifics& specifics, + bool deleted, + base::Time ctime, + base::Time mtime) : sequence_number_(sequence_number), commit_requested_sequence_number_(commit_requested_sequence_number), acked_sequence_number_(acked_sequence_number), @@ -78,30 +76,30 @@ ModelThreadSyncEntity::ModelThreadSyncEntity( mtime_(mtime) { } -ModelThreadSyncEntity::~ModelThreadSyncEntity() { +ModelTypeEntity::~ModelTypeEntity() { } -bool ModelThreadSyncEntity::IsWriteRequired() const { +bool ModelTypeEntity::IsWriteRequired() const { return is_dirty_; } -bool ModelThreadSyncEntity::IsUnsynced() const { +bool ModelTypeEntity::IsUnsynced() const { return sequence_number_ > acked_sequence_number_; } -bool ModelThreadSyncEntity::RequiresCommitRequest() const { +bool ModelTypeEntity::RequiresCommitRequest() const { return sequence_number_ > commit_requested_sequence_number_; } -bool ModelThreadSyncEntity::UpdateIsReflection(int64 update_version) const { +bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const { return base_version_ >= update_version; } -bool ModelThreadSyncEntity::UpdateIsInConflict(int64 update_version) const { +bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const { return IsUnsynced() && !UpdateIsReflection(update_version); } -void ModelThreadSyncEntity::ApplyUpdateFromServer( +void ModelTypeEntity::ApplyUpdateFromServer( int64 update_version, bool deleted, const sync_pb::EntitySpecifics& specifics, @@ -117,19 +115,19 @@ void ModelThreadSyncEntity::ApplyUpdateFromServer( mtime_ = mtime; } -void ModelThreadSyncEntity::MakeLocalChange( +void ModelTypeEntity::MakeLocalChange( const sync_pb::EntitySpecifics& specifics) { sequence_number_++; specifics_ = specifics; } -void ModelThreadSyncEntity::Delete() { +void ModelTypeEntity::Delete() { sequence_number_++; specifics_.Clear(); deleted_ = true; } -void ModelThreadSyncEntity::InitializeCommitRequestData( +void ModelTypeEntity::InitializeCommitRequestData( CommitRequestData* request) const { request->id = id_; request->client_tag_hash = client_tag_hash_; @@ -142,25 +140,25 @@ void ModelThreadSyncEntity::InitializeCommitRequestData( request->specifics.CopyFrom(specifics_); } -void ModelThreadSyncEntity::SetCommitRequestInProgress() { +void ModelTypeEntity::SetCommitRequestInProgress() { commit_requested_sequence_number_ = sequence_number_; } -void ModelThreadSyncEntity::ReceiveCommitResponse(const std::string& id, - int64 sequence_number, - int64 response_version) { +void ModelTypeEntity::ReceiveCommitResponse(const std::string& id, + int64 sequence_number, + int64 response_version) { id_ = id; // The server can assign us a new ID in a commit response. acked_sequence_number_ = sequence_number; base_version_ = response_version; } -void ModelThreadSyncEntity::ClearTransientSyncState() { +void ModelTypeEntity::ClearTransientSyncState() { // If we have any unacknowledged commit requests outstatnding, they've been // dropped and we should forget about them. commit_requested_sequence_number_ = acked_sequence_number_; } -void ModelThreadSyncEntity::ClearSyncState() { +void ModelTypeEntity::ClearSyncState() { base_version_ = kUncommittedVersion; is_dirty_ = true; sequence_number_ = 1; diff --git a/sync/engine/model_thread_sync_entity.h b/sync/engine/model_type_entity.h index 03a6d27..a457cb3 100644 --- a/sync/engine/model_thread_sync_entity.h +++ b/sync/engine/model_type_entity.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ -#define SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ +#ifndef SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ +#define SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ #include <string> @@ -17,7 +17,7 @@ namespace syncer { // This is the model thread's representation of a SyncEntity. // -// The model thread sync entity receives updates from the model itself and +// The model type entity receives updates from the model itself and // (asynchronously) from the sync server via the sync thread. From the point // of view of this class, updates from the server take precedence over local // changes, though the model may be given an opportunity to overwrite this @@ -29,16 +29,16 @@ namespace syncer { // Most of the logic related to those processes live outside this class. This // class helps out a bit by offering some functions to serialize its data to // various formats and query the entity's status. -class SYNC_EXPORT_PRIVATE ModelThreadSyncEntity { +class SYNC_EXPORT_PRIVATE ModelTypeEntity { public: // Construct an instance representing a new locally-created item. - static scoped_ptr<ModelThreadSyncEntity> NewLocalItem( + static scoped_ptr<ModelTypeEntity> NewLocalItem( const std::string& client_tag, const sync_pb::EntitySpecifics& specifics, base::Time now); // Construct an instance representing an item newly received from the server. - static scoped_ptr<ModelThreadSyncEntity> FromServerUpdate( + static scoped_ptr<ModelTypeEntity> FromServerUpdate( const std::string& id, const std::string& client_tag_hash, const std::string& non_unique_name, @@ -50,7 +50,7 @@ class SYNC_EXPORT_PRIVATE ModelThreadSyncEntity { // TODO(rlarocque): Implement FromDisk constructor when we implement storage. - ~ModelThreadSyncEntity(); + ~ModelTypeEntity(); // Returns true if this data is out of sync with local storage. bool IsWriteRequired() const; @@ -113,18 +113,18 @@ class SYNC_EXPORT_PRIVATE ModelThreadSyncEntity { void ClearSyncState(); private: - ModelThreadSyncEntity(int64 sequence_number, - int64 commit_requested_sequence_number, - int64 acked_sequence_number, - int64 base_version, - bool is_dirty, - const std::string& id, - const std::string& client_tag_hash, - const std::string& non_unique_name, - const sync_pb::EntitySpecifics& specifics, - bool deleted, - base::Time ctime, - base::Time mtime); + ModelTypeEntity(int64 sequence_number, + int64 commit_requested_sequence_number, + int64 acked_sequence_number, + int64 base_version, + bool is_dirty, + const std::string& id, + const std::string& client_tag_hash, + const std::string& non_unique_name, + const sync_pb::EntitySpecifics& specifics, + bool deleted, + base::Time ctime, + base::Time mtime); // A sequence number used to track in-progress commits. Each local change // increments this number. @@ -189,4 +189,4 @@ class SYNC_EXPORT_PRIVATE ModelThreadSyncEntity { } // namespace syncer -#endif // SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ +#endif // SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ diff --git a/sync/engine/model_thread_sync_entity_unittest.cc b/sync/engine/model_type_entity_unittest.cc index 6b158dd..c605732 100644 --- a/sync/engine/model_thread_sync_entity_unittest.cc +++ b/sync/engine/model_type_entity_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/model_thread_sync_entity.h" +#include "sync/engine/model_type_entity.h" #include "base/memory/scoped_ptr.h" #include "base/time/time.h" @@ -14,18 +14,18 @@ namespace syncer { -// Some simple sanity tests for the ModelThreadSyncEntity. +// Some simple sanity tests for the ModelTypeEntity. // // A lot of the more complicated sync logic is implemented in the -// NonBlockingTypeProcessor that owns the ModelThreadSyncEntity. We -// can't unit test it here. +// ModelTypeSyncProxyImpl that owns the ModelTypeEntity. We can't unit test it +// here. // // Instead, we focus on simple tests to make sure that variables are getting // properly intialized and flags properly set. Anything more complicated would -// be a redundant and incomplete version of the NonBlockingTypeProcessor tests. -class ModelThreadSyncEntityTest : public ::testing::Test { +// be a redundant and incomplete version of the ModelTypeSyncProxyImpl tests. +class ModelTypeEntityTest : public ::testing::Test { public: - ModelThreadSyncEntityTest() + ModelTypeEntityTest() : kServerId("ServerID"), kClientTag("sample.pref.name"), kClientTagHash(syncable::GenerateSyncableHash(PREFERENCES, kClientTag)), @@ -45,9 +45,9 @@ class ModelThreadSyncEntityTest : public ::testing::Test { sync_pb::EntitySpecifics specifics; }; -TEST_F(ModelThreadSyncEntityTest, NewLocalItem) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::NewLocalItem("asdf", specifics, kCtime)); +TEST_F(ModelTypeEntityTest, NewLocalItem) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::NewLocalItem("asdf", specifics, kCtime)); EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_TRUE(entity->IsUnsynced()); @@ -55,17 +55,16 @@ TEST_F(ModelThreadSyncEntityTest, NewLocalItem) { EXPECT_TRUE(entity->UpdateIsInConflict(1)); } -TEST_F(ModelThreadSyncEntityTest, FromServerUpdate) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::FromServerUpdate( - kServerId, - kClientTagHash, - kClientTag, // As non-unique name. - 10, - specifics, - false, - kCtime, - kMtime)); +TEST_F(ModelTypeEntityTest, FromServerUpdate) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::FromServerUpdate(kServerId, + kClientTagHash, + kClientTag, // As non-unique name. + 10, + specifics, + false, + kCtime, + kMtime)); EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_FALSE(entity->IsUnsynced()); @@ -79,17 +78,16 @@ TEST_F(ModelThreadSyncEntityTest, FromServerUpdate) { // thing about them is that they don't have specifics, so it can be hard to // detect their type. Fortunately, this class doesn't care about types in // received updates. -TEST_F(ModelThreadSyncEntityTest, TombstoneUpdate) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::FromServerUpdate( - kServerId, - kClientTagHash, - kClientTag, // As non-unique name. - 10, - sync_pb::EntitySpecifics(), - true, - kCtime, - kMtime)); +TEST_F(ModelTypeEntityTest, TombstoneUpdate) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::FromServerUpdate(kServerId, + kClientTagHash, + kClientTag, // As non-unique name. + 10, + sync_pb::EntitySpecifics(), + true, + kCtime, + kMtime)); EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_FALSE(entity->IsUnsynced()); @@ -100,17 +98,16 @@ TEST_F(ModelThreadSyncEntityTest, TombstoneUpdate) { } // Apply a deletion update. -TEST_F(ModelThreadSyncEntityTest, ApplyUpdate) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::FromServerUpdate( - kServerId, - kClientTagHash, - kClientTag, // As non-unique name. - 10, - specifics, - false, - kCtime, - kMtime)); +TEST_F(ModelTypeEntityTest, ApplyUpdate) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::FromServerUpdate(kServerId, + kClientTagHash, + kClientTag, // As non-unique name. + 10, + specifics, + false, + kCtime, + kMtime)); // A deletion update one version later. entity->ApplyUpdateFromServer(11, @@ -124,17 +121,16 @@ TEST_F(ModelThreadSyncEntityTest, ApplyUpdate) { EXPECT_FALSE(entity->UpdateIsReflection(12)); } -TEST_F(ModelThreadSyncEntityTest, LocalChange) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::FromServerUpdate( - kServerId, - kClientTagHash, - kClientTag, // As non-unique name. - 10, - specifics, - false, - kCtime, - kMtime)); +TEST_F(ModelTypeEntityTest, LocalChange) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::FromServerUpdate(kServerId, + kClientTagHash, + kClientTag, // As non-unique name. + 10, + specifics, + false, + kCtime, + kMtime)); sync_pb::EntitySpecifics specifics2; specifics2.CopyFrom(specifics); @@ -151,17 +147,16 @@ TEST_F(ModelThreadSyncEntityTest, LocalChange) { EXPECT_TRUE(entity->UpdateIsInConflict(11)); } -TEST_F(ModelThreadSyncEntityTest, LocalDeletion) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::FromServerUpdate( - kServerId, - kClientTagHash, - kClientTag, // As non-unique name. - 10, - specifics, - false, - kCtime, - kMtime)); +TEST_F(ModelTypeEntityTest, LocalDeletion) { + scoped_ptr<ModelTypeEntity> entity( + ModelTypeEntity::FromServerUpdate(kServerId, + kClientTagHash, + kClientTag, // As non-unique name. + 10, + specifics, + false, + kCtime, + kMtime)); entity->Delete(); diff --git a/sync/internal_api/sync_core_proxy.cc b/sync/engine/model_type_sync_proxy.cc index 4e6f7f6..974dc61 100644 --- a/sync/internal_api/sync_core_proxy.cc +++ b/sync/engine/model_type_sync_proxy.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/engine/model_type_sync_proxy.h" namespace syncer { -SyncCoreProxy::SyncCoreProxy() {} +ModelTypeSyncProxy::ModelTypeSyncProxy() { +} -SyncCoreProxy::~SyncCoreProxy() {} +ModelTypeSyncProxy::~ModelTypeSyncProxy() { +} } // namespace syncer diff --git a/sync/engine/non_blocking_type_processor_interface.h b/sync/engine/model_type_sync_proxy.h index bafd141..2851a09 100644 --- a/sync/engine/non_blocking_type_processor_interface.h +++ b/sync/engine/model_type_sync_proxy.h @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_INTERFACE_H_ -#define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_INTERFACE_H_ +#ifndef SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_H_ +#define SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_H_ #include "sync/base/sync_export.h" #include "sync/engine/non_blocking_sync_common.h" namespace syncer { -class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessorInterface { +// Interface used by sync backend to issue requests to a synced data type. +class SYNC_EXPORT_PRIVATE ModelTypeSyncProxy { public: - NonBlockingTypeProcessorInterface(); - virtual ~NonBlockingTypeProcessorInterface(); + ModelTypeSyncProxy(); + virtual ~ModelTypeSyncProxy(); virtual void ReceiveCommitResponse( const DataTypeState& type_state, @@ -25,4 +26,4 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessorInterface { } // namespace syncer -#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_INTERFACE_H_ +#endif // SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_H_ diff --git a/sync/engine/non_blocking_type_processor.cc b/sync/engine/model_type_sync_proxy_impl.cc index 9b80543..d865998 100644 --- a/sync/engine/non_blocking_type_processor.cc +++ b/sync/engine/model_type_sync_proxy_impl.cc @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/non_blocking_type_processor.h" +#include "sync/engine/model_type_sync_proxy_impl.h" #include "base/bind.h" #include "base/location.h" #include "base/message_loop/message_loop_proxy.h" -#include "sync/engine/model_thread_sync_entity.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/engine/model_type_entity.h" +#include "sync/engine/model_type_sync_worker.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/syncable/syncable_util.h" namespace syncer { -NonBlockingTypeProcessor::NonBlockingTypeProcessor(ModelType type) +ModelTypeSyncProxyImpl::ModelTypeSyncProxyImpl(ModelType type) : type_(type), is_preferred_(false), is_connected_(false), @@ -23,26 +23,26 @@ NonBlockingTypeProcessor::NonBlockingTypeProcessor(ModelType type) weak_ptr_factory_for_sync_(this) { } -NonBlockingTypeProcessor::~NonBlockingTypeProcessor() { +ModelTypeSyncProxyImpl::~ModelTypeSyncProxyImpl() { } -bool NonBlockingTypeProcessor::IsPreferred() const { +bool ModelTypeSyncProxyImpl::IsPreferred() const { DCHECK(CalledOnValidThread()); return is_preferred_; } -bool NonBlockingTypeProcessor::IsConnected() const { +bool ModelTypeSyncProxyImpl::IsConnected() const { DCHECK(CalledOnValidThread()); return is_connected_; } -ModelType NonBlockingTypeProcessor::GetModelType() const { +ModelType ModelTypeSyncProxyImpl::GetModelType() const { DCHECK(CalledOnValidThread()); return type_; } -void NonBlockingTypeProcessor::Enable( - scoped_ptr<SyncCoreProxy> sync_core_proxy) { +void ModelTypeSyncProxyImpl::Enable( + scoped_ptr<SyncContextProxy> sync_context_proxy) { DCHECK(CalledOnValidThread()); DVLOG(1) << "Asked to enable " << ModelTypeToString(type_); @@ -52,13 +52,14 @@ void NonBlockingTypeProcessor::Enable( data_type_state_.progress_marker.set_data_type_id( GetSpecificsFieldNumberFromModelType(type_)); - sync_core_proxy_ = sync_core_proxy.Pass(); - sync_core_proxy_->ConnectTypeToCore(GetModelType(), - data_type_state_, - weak_ptr_factory_for_sync_.GetWeakPtr()); + sync_context_proxy_ = sync_context_proxy.Pass(); + sync_context_proxy_->ConnectTypeToSync( + GetModelType(), + data_type_state_, + weak_ptr_factory_for_sync_.GetWeakPtr()); } -void NonBlockingTypeProcessor::Disable() { +void ModelTypeSyncProxyImpl::Disable() { DCHECK(CalledOnValidThread()); is_preferred_ = false; Disconnect(); @@ -66,41 +67,39 @@ void NonBlockingTypeProcessor::Disable() { ClearSyncState(); } -void NonBlockingTypeProcessor::Disconnect() { +void ModelTypeSyncProxyImpl::Disconnect() { DCHECK(CalledOnValidThread()); DVLOG(1) << "Asked to disconnect " << ModelTypeToString(type_); is_connected_ = false; - if (sync_core_proxy_) { - sync_core_proxy_->Disconnect(GetModelType()); - sync_core_proxy_.reset(); + if (sync_context_proxy_) { + sync_context_proxy_->Disconnect(GetModelType()); + sync_context_proxy_.reset(); } weak_ptr_factory_for_sync_.InvalidateWeakPtrs(); - core_interface_.reset(); + worker_.reset(); ClearTransientSyncState(); } -base::WeakPtr<NonBlockingTypeProcessor> -NonBlockingTypeProcessor::AsWeakPtrForUI() { +base::WeakPtr<ModelTypeSyncProxyImpl> ModelTypeSyncProxyImpl::AsWeakPtrForUI() { DCHECK(CalledOnValidThread()); return weak_ptr_factory_for_ui_.GetWeakPtr(); } -void NonBlockingTypeProcessor::OnConnect( - scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface) { +void ModelTypeSyncProxyImpl::OnConnect(scoped_ptr<ModelTypeSyncWorker> worker) { DCHECK(CalledOnValidThread()); DVLOG(1) << "Successfully connected " << ModelTypeToString(type_); is_connected_ = true; - core_interface_ = core_interface.Pass(); + worker_ = worker.Pass(); FlushPendingCommitRequests(); } -void NonBlockingTypeProcessor::Put(const std::string& client_tag, - const sync_pb::EntitySpecifics& specifics) { +void ModelTypeSyncProxyImpl::Put(const std::string& client_tag, + const sync_pb::EntitySpecifics& specifics) { DCHECK_EQ(type_, GetModelTypeFromSpecifics(specifics)); const std::string client_tag_hash( @@ -108,19 +107,18 @@ void NonBlockingTypeProcessor::Put(const std::string& client_tag, EntityMap::iterator it = entities_.find(client_tag_hash); if (it == entities_.end()) { - scoped_ptr<ModelThreadSyncEntity> entity( - ModelThreadSyncEntity::NewLocalItem( - client_tag, specifics, base::Time::Now())); + scoped_ptr<ModelTypeEntity> entity(ModelTypeEntity::NewLocalItem( + client_tag, specifics, base::Time::Now())); entities_.insert(std::make_pair(client_tag_hash, entity.release())); } else { - ModelThreadSyncEntity* entity = it->second; + ModelTypeEntity* entity = it->second; entity->MakeLocalChange(specifics); } FlushPendingCommitRequests(); } -void NonBlockingTypeProcessor::Delete(const std::string& client_tag) { +void ModelTypeSyncProxyImpl::Delete(const std::string& client_tag) { const std::string client_tag_hash( syncable::GenerateSyncableHash(type_, client_tag)); @@ -131,14 +129,14 @@ void NonBlockingTypeProcessor::Delete(const std::string& client_tag) { DLOG(WARNING) << "Attempted to delete missing item." << " client tag: " << client_tag; } else { - ModelThreadSyncEntity* entity = it->second; + ModelTypeEntity* entity = it->second; entity->Delete(); } FlushPendingCommitRequests(); } -void NonBlockingTypeProcessor::FlushPendingCommitRequests() { +void ModelTypeSyncProxyImpl::FlushPendingCommitRequests() { CommitRequestDataList commit_requests; // Don't bother sending anything if there's no one to send to. @@ -161,10 +159,10 @@ void NonBlockingTypeProcessor::FlushPendingCommitRequests() { } if (!commit_requests.empty()) - core_interface_->RequestCommits(commit_requests); + worker_->RequestCommits(commit_requests); } -void NonBlockingTypeProcessor::OnCommitCompletion( +void ModelTypeSyncProxyImpl::OnCommitCompletion( const DataTypeState& type_state, const CommitResponseDataList& response_list) { data_type_state_ = type_state; @@ -188,7 +186,7 @@ void NonBlockingTypeProcessor::OnCommitCompletion( } } -void NonBlockingTypeProcessor::OnUpdateReceived( +void ModelTypeSyncProxyImpl::OnUpdateReceived( const DataTypeState& data_type_state, const UpdateResponseDataList& response_list) { bool initial_sync_just_finished = @@ -204,19 +202,18 @@ void NonBlockingTypeProcessor::OnUpdateReceived( EntityMap::iterator it = entities_.find(client_tag_hash); if (it == entities_.end()) { - scoped_ptr<ModelThreadSyncEntity> entity = - ModelThreadSyncEntity::FromServerUpdate( - response_data.id, - response_data.client_tag_hash, - response_data.non_unique_name, - response_data.response_version, - response_data.specifics, - response_data.deleted, - response_data.ctime, - response_data.mtime); + scoped_ptr<ModelTypeEntity> entity = + ModelTypeEntity::FromServerUpdate(response_data.id, + response_data.client_tag_hash, + response_data.non_unique_name, + response_data.response_version, + response_data.specifics, + response_data.deleted, + response_data.ctime, + response_data.mtime); entities_.insert(std::make_pair(client_tag_hash, entity.release())); } else { - ModelThreadSyncEntity* entity = it->second; + ModelTypeEntity* entity = it->second; entity->ApplyUpdateFromServer(response_data.response_version, response_data.deleted, response_data.specifics, @@ -231,14 +228,14 @@ void NonBlockingTypeProcessor::OnUpdateReceived( // TODO: Inform the model of the new or updated data. } -void NonBlockingTypeProcessor::ClearTransientSyncState() { +void ModelTypeSyncProxyImpl::ClearTransientSyncState() { for (EntityMap::iterator it = entities_.begin(); it != entities_.end(); ++it) { it->second->ClearTransientSyncState(); } } -void NonBlockingTypeProcessor::ClearSyncState() { +void ModelTypeSyncProxyImpl::ClearSyncState() { for (EntityMap::iterator it = entities_.begin(); it != entities_.end(); ++it) { it->second->ClearSyncState(); diff --git a/sync/engine/non_blocking_type_processor.h b/sync/engine/model_type_sync_proxy_impl.h index da680f1..0091112 100644 --- a/sync/engine/non_blocking_type_processor.h +++ b/sync/engine/model_type_sync_proxy_impl.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_ -#define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_ +#ifndef SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_IMPL_H_ +#define SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_IMPL_H_ #include "base/memory/weak_ptr.h" #include "base/stl_util.h" @@ -15,16 +15,16 @@ namespace syncer { -class SyncCoreProxy; -class ModelThreadSyncEntity; -class NonBlockingTypeProcessorCoreInterface; +class SyncContextProxy; +class ModelTypeEntity; +class ModelTypeSyncWorker; // 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 NonBlockingTypeProcessor : base::NonThreadSafe { +class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe { public: - NonBlockingTypeProcessor(ModelType type); - virtual ~NonBlockingTypeProcessor(); + ModelTypeSyncProxyImpl(ModelType type); + virtual ~ModelTypeSyncProxyImpl(); // Returns true if this object believes that sync is preferred for this type. // @@ -41,11 +41,11 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { // Returns true if the handshake with sync thread is complete. bool IsConnected() const; - // Returns the model type handled by this processor. + // Returns the model type handled by this type sync proxy. ModelType GetModelType() const; // Starts the handshake with the sync thread. - void Enable(scoped_ptr<SyncCoreProxy> core_proxy); + void Enable(scoped_ptr<SyncContextProxy> context_proxy); // Severs all ties to the sync thread and may delete local sync state. // Another call to Enable() can be used to re-establish this connection. @@ -56,8 +56,7 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { void Disconnect(); // Callback used to process the handshake response. - void OnConnect( - scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface); + void OnConnect(scoped_ptr<ModelTypeSyncWorker> worker); // Requests that an item be stored in sync. void Put(const std::string& client_tag, @@ -78,17 +77,17 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { // Returns the long-lived WeakPtr that is intended to be registered with the // ProfileSyncService. - base::WeakPtr<NonBlockingTypeProcessor> AsWeakPtrForUI(); + base::WeakPtr<ModelTypeSyncProxyImpl> AsWeakPtrForUI(); private: - typedef std::map<std::string, ModelThreadSyncEntity*> EntityMap; + typedef std::map<std::string, ModelTypeEntity*> EntityMap; // Sends all commit requests that are due to be sent to the sync thread. void FlushPendingCommitRequests(); // Clears any state related to outstanding communications with the - // NonBlockingTypeProcessorCore. Used when we want to disconnect from - // the current core. + // ModelTypeSyncWorker. Used when we want to disconnect from + // the current worker. void ClearTransientSyncState(); // Clears any state related to our communications with the current sync @@ -103,7 +102,7 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { bool is_preferred_; // Whether or not this object has completed its initial handshake with the - // SyncCoreProxy. + // SyncContextProxy. bool is_connected_; // Our link to data type management on the sync thread. @@ -111,14 +110,14 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { // // Beware of NULL pointers: This object is uninitialized when we are not // connected to sync. - scoped_ptr<SyncCoreProxy> sync_core_proxy_; + scoped_ptr<SyncContextProxy> sync_context_proxy_; - // Reference to the NonBlockingTypeProcessorCore. + // Reference to the ModelTypeSyncWorker. // // The interface hides the posting of tasks across threads as well as the - // NonBlockingTypeProcessorCore's implementation. Both of these features are + // ModelTypeSyncWorker's implementation. Both of these features are // useful in tests. - scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface_; + scoped_ptr<ModelTypeSyncWorker> worker_; // The set of sync entities known to this object. EntityMap entities_; @@ -129,10 +128,10 @@ class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessor : base::NonThreadSafe { // thread, we want to make sure that no tasks generated as part of the // now-obsolete connection to affect us. But we also want the WeakPtr we // sent to the UI thread to remain valid. - base::WeakPtrFactory<NonBlockingTypeProcessor> weak_ptr_factory_for_ui_; - base::WeakPtrFactory<NonBlockingTypeProcessor> weak_ptr_factory_for_sync_; + base::WeakPtrFactory<ModelTypeSyncProxyImpl> weak_ptr_factory_for_ui_; + base::WeakPtrFactory<ModelTypeSyncProxyImpl> weak_ptr_factory_for_sync_; }; } // namespace syncer -#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_H_ +#endif // SYNC_ENGINE_MODEL_TYPE_SYNC_PROXY_IMPL_H_ diff --git a/sync/engine/non_blocking_type_processor_unittest.cc b/sync/engine/model_type_sync_proxy_impl_unittest.cc index 2c42afc..810c6b6 100644 --- a/sync/engine/non_blocking_type_processor_unittest.cc +++ b/sync/engine/model_type_sync_proxy_impl_unittest.cc @@ -2,33 +2,33 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/non_blocking_type_processor.h" +#include "sync/engine/model_type_sync_proxy_impl.h" +#include "sync/engine/model_type_sync_worker.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/protocol/sync.pb.h" #include "sync/syncable/syncable_util.h" -#include "sync/test/engine/injectable_sync_core_proxy.h" -#include "sync/test/engine/mock_non_blocking_type_processor_core.h" +#include "sync/test/engine/injectable_sync_context_proxy.h" +#include "sync/test/engine/mock_model_type_sync_worker.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { static const ModelType kModelType = PREFERENCES; -// Tests the sync engine parts of NonBlockingTypeProcessor. +// Tests the sync engine parts of ModelTypeSyncProxyImpl. // -// The NonBlockingTypeProcessor contains a non-trivial amount of code dedicated +// The ModelTypeSyncProxyImpl contains a non-trivial amount of code dedicated // to turning the sync engine on and off again. That code is fairly well // tested in the NonBlockingDataTypeController unit tests and it doesn't need // to be re-tested here. // // These tests skip past initialization and focus on steady state sync engine -// behvior. This is where we test how the processor responds to the model's -// requests to make changes to its data, the messages incoming fro the sync -// server, and what happens when the two conflict. +// behvior. This is where we test how the type sync proxy responds to the +// model's requests to make changes to its data, the messages incoming from the +// sync server, and what happens when the two conflict. // // Inputs: // - Initial state from permanent storage. (TODO) @@ -38,25 +38,24 @@ static const ModelType kModelType = PREFERENCES; // Outputs: // - Writes to permanent storage. (TODO) // - Callbacks into the model. (TODO) -// - Requests to the sync thread. Tested with MockNonBlockingTypeProcessorCore. -class NonBlockingTypeProcessorTest : public ::testing::Test { +// - Requests to the sync thread. Tested with MockModelTypeSyncWorker. +class ModelTypeSyncProxyImplTest : public ::testing::Test { public: - NonBlockingTypeProcessorTest(); - virtual ~NonBlockingTypeProcessorTest(); + ModelTypeSyncProxyImplTest(); + virtual ~ModelTypeSyncProxyImplTest(); - // Initialize with no local state. The processor will be unable to commit - // until it receives notification that initial sync has completed. + // Initialize with no local state. The type sync proxy will be unable to + // commit until it receives notification that initial sync has completed. void FirstTimeInitialize(); // Initialize to a "ready-to-commit" state. void InitializeToReadyState(); - // Disconnect the NonBlockingTypeProcessorCore from our - // NonBlockingTypeProcessor. + // Disconnect the ModelTypeSyncWorker from our ModelTypeSyncProxyImpl. void Disconnect(); - // Disable sync for this NonBlockingTypeProcessor. Should cause sync state - // to be discarded. + // Disable sync for this ModelTypeSyncProxyImpl. Should cause sync state to + // be discarded. void Disable(); // Re-enable sync after Disconnect() or Disable(). @@ -67,7 +66,7 @@ class NonBlockingTypeProcessorTest : public ::testing::Test { void DeleteItem(const std::string& tag); // Emulates an "initial sync done" message from the - // NonBlockingTypeProcessorCore. + // ModelTypeSyncWorker. void OnInitialSyncDone(); // Emulate updates from the server. @@ -86,7 +85,7 @@ class NonBlockingTypeProcessorTest : public ::testing::Test { bool HasCommitRequestForTag(const std::string& tag); CommitRequestData GetLatestCommitRequestForTag(const std::string& tag); - // Sends the processor a successful commit response. + // Sends the type sync proxy a successful commit response. void SuccessfulCommitResponse(const CommitRequestData& request_data); private: @@ -97,116 +96,116 @@ class NonBlockingTypeProcessorTest : public ::testing::Test { int64 GetServerVersion(const std::string& tag); void SetServerVersion(const std::string& tag, int64 version); - MockNonBlockingTypeProcessorCore* mock_processor_core_; - scoped_ptr<InjectableSyncCoreProxy> injectable_sync_core_proxy_; - scoped_ptr<NonBlockingTypeProcessor> processor_; + MockModelTypeSyncWorker* mock_worker_; + scoped_ptr<InjectableSyncContextProxy> injectable_sync_context_proxy_; + scoped_ptr<ModelTypeSyncProxyImpl> type_sync_proxy_; DataTypeState data_type_state_; }; -NonBlockingTypeProcessorTest::NonBlockingTypeProcessorTest() - : mock_processor_core_(new MockNonBlockingTypeProcessorCore()), - injectable_sync_core_proxy_( - new InjectableSyncCoreProxy(mock_processor_core_)), - processor_(new NonBlockingTypeProcessor(kModelType)) { +ModelTypeSyncProxyImplTest::ModelTypeSyncProxyImplTest() + : mock_worker_(new MockModelTypeSyncWorker()), + injectable_sync_context_proxy_( + new InjectableSyncContextProxy(mock_worker_)), + type_sync_proxy_(new ModelTypeSyncProxyImpl(kModelType)) { } -NonBlockingTypeProcessorTest::~NonBlockingTypeProcessorTest() { +ModelTypeSyncProxyImplTest::~ModelTypeSyncProxyImplTest() { } -void NonBlockingTypeProcessorTest::FirstTimeInitialize() { - processor_->Enable(injectable_sync_core_proxy_->Clone()); +void ModelTypeSyncProxyImplTest::FirstTimeInitialize() { + type_sync_proxy_->Enable(injectable_sync_context_proxy_->Clone()); } -void NonBlockingTypeProcessorTest::InitializeToReadyState() { +void ModelTypeSyncProxyImplTest::InitializeToReadyState() { // TODO(rlarocque): This should be updated to inject on-disk state. // At the time this code was written, there was no support for on-disk // state so this was the only way to inject a data_type_state into - // the |processor_|. + // the |type_sync_proxy_|. FirstTimeInitialize(); OnInitialSyncDone(); } -void NonBlockingTypeProcessorTest::Disconnect() { - processor_->Disconnect(); - injectable_sync_core_proxy_.reset(); - mock_processor_core_ = NULL; +void ModelTypeSyncProxyImplTest::Disconnect() { + type_sync_proxy_->Disconnect(); + injectable_sync_context_proxy_.reset(); + mock_worker_ = NULL; } -void NonBlockingTypeProcessorTest::Disable() { - processor_->Disable(); - injectable_sync_core_proxy_.reset(); - mock_processor_core_ = NULL; +void ModelTypeSyncProxyImplTest::Disable() { + type_sync_proxy_->Disable(); + injectable_sync_context_proxy_.reset(); + mock_worker_ = NULL; } -void NonBlockingTypeProcessorTest::ReEnable() { - DCHECK(!processor_->IsConnected()); +void ModelTypeSyncProxyImplTest::ReEnable() { + DCHECK(!type_sync_proxy_->IsConnected()); // Prepare a new NonBlockingTypeProcesorCore instance, just as we would // if this happened in the real world. - mock_processor_core_ = new MockNonBlockingTypeProcessorCore(); - injectable_sync_core_proxy_.reset( - new InjectableSyncCoreProxy(mock_processor_core_)); + mock_worker_ = new MockModelTypeSyncWorker(); + injectable_sync_context_proxy_.reset( + new InjectableSyncContextProxy(mock_worker_)); - // Re-enable sync with the new NonBlockingTypeProcessorCore. - processor_->Enable(injectable_sync_core_proxy_->Clone()); + // Re-enable sync with the new ModelTypeSyncWorker. + type_sync_proxy_->Enable(injectable_sync_context_proxy_->Clone()); } -void NonBlockingTypeProcessorTest::WriteItem(const std::string& tag, - const std::string& value) { +void ModelTypeSyncProxyImplTest::WriteItem(const std::string& tag, + const std::string& value) { const std::string tag_hash = GenerateTagHash(tag); - processor_->Put(tag, GenerateSpecifics(tag, value)); + type_sync_proxy_->Put(tag, GenerateSpecifics(tag, value)); } -void NonBlockingTypeProcessorTest::DeleteItem(const std::string& tag) { - processor_->Delete(tag); +void ModelTypeSyncProxyImplTest::DeleteItem(const std::string& tag) { + type_sync_proxy_->Delete(tag); } -void NonBlockingTypeProcessorTest::OnInitialSyncDone() { +void ModelTypeSyncProxyImplTest::OnInitialSyncDone() { data_type_state_.initial_sync_done = true; UpdateResponseDataList empty_update_list; - processor_->OnUpdateReceived(data_type_state_, empty_update_list); + type_sync_proxy_->OnUpdateReceived(data_type_state_, empty_update_list); } -void NonBlockingTypeProcessorTest::UpdateFromServer(int64 version_offset, - const std::string& tag, - const std::string& value) { +void ModelTypeSyncProxyImplTest::UpdateFromServer(int64 version_offset, + const std::string& tag, + const std::string& value) { const std::string tag_hash = GenerateTagHash(tag); - UpdateResponseData data = mock_processor_core_->UpdateFromServer( + UpdateResponseData data = mock_worker_->UpdateFromServer( version_offset, tag_hash, GenerateSpecifics(tag, value)); UpdateResponseDataList list; list.push_back(data); - processor_->OnUpdateReceived(data_type_state_, list); + type_sync_proxy_->OnUpdateReceived(data_type_state_, list); } -void NonBlockingTypeProcessorTest::TombstoneFromServer(int64 version_offset, - const std::string& tag) { +void ModelTypeSyncProxyImplTest::TombstoneFromServer(int64 version_offset, + const std::string& tag) { // Overwrite the existing server version if this is the new highest version. std::string tag_hash = GenerateTagHash(tag); UpdateResponseData data = - mock_processor_core_->TombstoneFromServer(version_offset, tag_hash); + mock_worker_->TombstoneFromServer(version_offset, tag_hash); UpdateResponseDataList list; list.push_back(data); - processor_->OnUpdateReceived(data_type_state_, list); + type_sync_proxy_->OnUpdateReceived(data_type_state_, list); } -void NonBlockingTypeProcessorTest::SuccessfulCommitResponse( +void ModelTypeSyncProxyImplTest::SuccessfulCommitResponse( const CommitRequestData& request_data) { CommitResponseDataList list; - list.push_back(mock_processor_core_->SuccessfulCommitResponse(request_data)); - processor_->OnCommitCompletion(data_type_state_, list); + list.push_back(mock_worker_->SuccessfulCommitResponse(request_data)); + type_sync_proxy_->OnCommitCompletion(data_type_state_, list); } -std::string NonBlockingTypeProcessorTest::GenerateTagHash( +std::string ModelTypeSyncProxyImplTest::GenerateTagHash( const std::string& tag) { return syncable::GenerateSyncableHash(kModelType, tag); } -sync_pb::EntitySpecifics NonBlockingTypeProcessorTest::GenerateSpecifics( +sync_pb::EntitySpecifics ModelTypeSyncProxyImplTest::GenerateSpecifics( const std::string& tag, const std::string& value) { sync_pb::EntitySpecifics specifics; @@ -215,30 +214,30 @@ sync_pb::EntitySpecifics NonBlockingTypeProcessorTest::GenerateSpecifics( return specifics; } -size_t NonBlockingTypeProcessorTest::GetNumCommitRequestLists() { - return mock_processor_core_->GetNumCommitRequestLists(); +size_t ModelTypeSyncProxyImplTest::GetNumCommitRequestLists() { + return mock_worker_->GetNumCommitRequestLists(); } -CommitRequestDataList NonBlockingTypeProcessorTest::GetNthCommitRequestList( +CommitRequestDataList ModelTypeSyncProxyImplTest::GetNthCommitRequestList( size_t n) { - return mock_processor_core_->GetNthCommitRequestList(n); + return mock_worker_->GetNthCommitRequestList(n); } -bool NonBlockingTypeProcessorTest::HasCommitRequestForTag( +bool ModelTypeSyncProxyImplTest::HasCommitRequestForTag( const std::string& tag) { const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_core_->HasCommitRequestForTagHash(tag_hash); + return mock_worker_->HasCommitRequestForTagHash(tag_hash); } -CommitRequestData NonBlockingTypeProcessorTest::GetLatestCommitRequestForTag( +CommitRequestData ModelTypeSyncProxyImplTest::GetLatestCommitRequestForTag( const std::string& tag) { const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_core_->GetLatestCommitRequestForTagHash(tag_hash); + return mock_worker_->GetLatestCommitRequestForTagHash(tag_hash); } // Creates a new item locally. // Thoroughly tests the data generated by a local item creation. -TEST_F(NonBlockingTypeProcessorTest, CreateLocalItem) { +TEST_F(ModelTypeSyncProxyImplTest, CreateLocalItem) { InitializeToReadyState(); EXPECT_EQ(0U, GetNumCommitRequestLists()); @@ -261,7 +260,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateLocalItem) { // Creates a new local item then modifies it. // Thoroughly tests data generated by modification of server-unknown item. -TEST_F(NonBlockingTypeProcessorTest, CreateAndModifyLocalItem) { +TEST_F(ModelTypeSyncProxyImplTest, CreateAndModifyLocalItem) { InitializeToReadyState(); EXPECT_EQ(0U, GetNumCommitRequestLists()); @@ -293,7 +292,7 @@ TEST_F(NonBlockingTypeProcessorTest, CreateAndModifyLocalItem) { // Deletes an item we've never seen before. // Should have no effect and not crash. -TEST_F(NonBlockingTypeProcessorTest, DeleteUnknown) { +TEST_F(ModelTypeSyncProxyImplTest, DeleteUnknown) { InitializeToReadyState(); DeleteItem("tag1"); @@ -305,7 +304,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteUnknown) { // In this test, no commit responses are received, so the deleted item is // server-unknown as far as the model thread is concerned. That behavior // is race-dependent; other tests are used to test other races. -TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown) { +TEST_F(ModelTypeSyncProxyImplTest, DeleteServerUnknown) { InitializeToReadyState(); WriteItem("tag1", "value1"); @@ -330,7 +329,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown) { // The item is created locally then enqueued for commit. The sync thread // successfully commits it, but, before the commit response is picked up // by the model thread, the item is deleted by the model thread. -TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown_RacyCommitResponse) { +TEST_F(ModelTypeSyncProxyImplTest, DeleteServerUnknown_RacyCommitResponse) { InitializeToReadyState(); WriteItem("tag1", "value1"); @@ -354,7 +353,7 @@ TEST_F(NonBlockingTypeProcessorTest, DeleteServerUnknown_RacyCommitResponse) { // Creates two different sync items. // Verifies that the second has no effect on the first. -TEST_F(NonBlockingTypeProcessorTest, TwoIndependentItems) { +TEST_F(ModelTypeSyncProxyImplTest, TwoIndependentItems) { InitializeToReadyState(); EXPECT_EQ(0U, GetNumCommitRequestLists()); @@ -373,10 +372,10 @@ TEST_F(NonBlockingTypeProcessorTest, TwoIndependentItems) { ASSERT_TRUE(HasCommitRequestForTag("tag2")); } -// Starts the processor with no local state. +// Starts the type sync proxy with no local state. // Verify that it waits until initial sync is complete before requesting // commits. -TEST_F(NonBlockingTypeProcessorTest, NoCommitsUntilInitialSyncDone) { +TEST_F(ModelTypeSyncProxyImplTest, NoCommitsUntilInitialSyncDone) { FirstTimeInitialize(); WriteItem("tag1", "value1"); @@ -391,7 +390,7 @@ TEST_F(NonBlockingTypeProcessorTest, NoCommitsUntilInitialSyncDone) { // // Creates items in various states of commit and verifies they re-attempt to // commit on reconnect. -TEST_F(NonBlockingTypeProcessorTest, Disconnect) { +TEST_F(ModelTypeSyncProxyImplTest, Disconnect) { InitializeToReadyState(); // The first item is fully committed. @@ -427,7 +426,7 @@ TEST_F(NonBlockingTypeProcessorTest, Disconnect) { // // Creates items in various states of commit and verifies they re-attempt to // commit on re-enable. -TEST_F(NonBlockingTypeProcessorTest, Disable) { +TEST_F(ModelTypeSyncProxyImplTest, Disable) { InitializeToReadyState(); // The first item is fully committed. diff --git a/sync/engine/non_blocking_type_processor_interface.cc b/sync/engine/model_type_sync_worker.cc index b936239..6037a52 100644 --- a/sync/engine/non_blocking_type_processor_interface.cc +++ b/sync/engine/model_type_sync_worker.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/non_blocking_type_processor_interface.h" +#include "sync/engine/model_type_sync_worker.h" namespace syncer { -NonBlockingTypeProcessorInterface::NonBlockingTypeProcessorInterface() { +ModelTypeSyncWorker::ModelTypeSyncWorker() { } -NonBlockingTypeProcessorInterface::~NonBlockingTypeProcessorInterface() { +ModelTypeSyncWorker::~ModelTypeSyncWorker() { } } // namespace syncer diff --git a/sync/engine/model_type_sync_worker.h b/sync/engine/model_type_sync_worker.h new file mode 100644 index 0000000..9add845 --- /dev/null +++ b/sync/engine/model_type_sync_worker.h @@ -0,0 +1,23 @@ +// Copyright 2014 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_ENGINE_MODEL_TYPE_SYNC_WORKER_H_ +#define SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_H_ + +#include "sync/engine/non_blocking_sync_common.h" + +namespace syncer { + +// Interface used by a synced data type to issue requests to the sync backend. +class SYNC_EXPORT_PRIVATE ModelTypeSyncWorker { + public: + ModelTypeSyncWorker(); + virtual ~ModelTypeSyncWorker(); + + virtual void RequestCommits(const CommitRequestDataList& list) = 0; +}; + +} // namespace syncer + +#endif // SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_H_ diff --git a/sync/engine/non_blocking_type_processor_core.cc b/sync/engine/model_type_sync_worker_impl.cc index a14a8d0..0e2ade0 100644 --- a/sync/engine/non_blocking_type_processor_core.cc +++ b/sync/engine/model_type_sync_worker_impl.cc @@ -2,54 +2,54 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/non_blocking_type_processor_core.h" +#include "sync/engine/model_type_sync_worker_impl.h" #include "base/bind.h" #include "base/format_macros.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "sync/engine/commit_contribution.h" +#include "sync/engine/entity_tracker.h" +#include "sync/engine/model_type_sync_proxy.h" #include "sync/engine/non_blocking_type_commit_contribution.h" -#include "sync/engine/non_blocking_type_processor_interface.h" -#include "sync/engine/sync_thread_sync_entity.h" #include "sync/syncable/syncable_util.h" #include "sync/util/time.h" namespace syncer { -NonBlockingTypeProcessorCore::NonBlockingTypeProcessorCore( +ModelTypeSyncWorkerImpl::ModelTypeSyncWorkerImpl( ModelType type, const DataTypeState& initial_state, - scoped_ptr<NonBlockingTypeProcessorInterface> processor_interface) + scoped_ptr<ModelTypeSyncProxy> type_sync_proxy) : type_(type), data_type_state_(initial_state), - processor_interface_(processor_interface.Pass()), + type_sync_proxy_(type_sync_proxy.Pass()), entities_deleter_(&entities_), weak_ptr_factory_(this) { } -NonBlockingTypeProcessorCore::~NonBlockingTypeProcessorCore() { +ModelTypeSyncWorkerImpl::~ModelTypeSyncWorkerImpl() { } -ModelType NonBlockingTypeProcessorCore::GetModelType() const { +ModelType ModelTypeSyncWorkerImpl::GetModelType() const { DCHECK(CalledOnValidThread()); return type_; } // UpdateHandler implementation. -void NonBlockingTypeProcessorCore::GetDownloadProgress( +void ModelTypeSyncWorkerImpl::GetDownloadProgress( sync_pb::DataTypeProgressMarker* progress_marker) const { DCHECK(CalledOnValidThread()); progress_marker->CopyFrom(data_type_state_.progress_marker); } -void NonBlockingTypeProcessorCore::GetDataTypeContext( +void ModelTypeSyncWorkerImpl::GetDataTypeContext( sync_pb::DataTypeContext* context) const { DCHECK(CalledOnValidThread()); context->CopyFrom(data_type_state_.type_context); } -SyncerError NonBlockingTypeProcessorCore::ProcessGetUpdatesResponse( +SyncerError ModelTypeSyncWorkerImpl::ProcessGetUpdatesResponse( const sync_pb::DataTypeProgressMarker& progress_marker, const sync_pb::DataTypeContext& mutated_context, const SyncEntityList& applicable_updates, @@ -82,13 +82,13 @@ SyncerError NonBlockingTypeProcessorCore::ProcessGetUpdatesResponse( DCHECK(!client_tag_hash.empty()); EntityMap::const_iterator map_it = entities_.find(client_tag_hash); if (map_it == entities_.end()) { - SyncThreadSyncEntity* entity = - SyncThreadSyncEntity::FromServerUpdate(update_entity->id_string(), - client_tag_hash, - update_entity->version()); + EntityTracker* entity = + EntityTracker::FromServerUpdate(update_entity->id_string(), + client_tag_hash, + update_entity->version()); entities_.insert(std::make_pair(client_tag_hash, entity)); } else { - SyncThreadSyncEntity* entity = map_it->second; + EntityTracker* entity = map_it->second; entity->ReceiveUpdate(update_entity->version()); } @@ -108,35 +108,34 @@ SyncerError NonBlockingTypeProcessorCore::ProcessGetUpdatesResponse( } // Forward these updates to the model thread so it can do the rest. - processor_interface_->ReceiveUpdateResponse(data_type_state_, response_datas); + type_sync_proxy_->ReceiveUpdateResponse(data_type_state_, response_datas); return SYNCER_OK; } -void NonBlockingTypeProcessorCore::ApplyUpdates( - sessions::StatusController* status) { +void ModelTypeSyncWorkerImpl::ApplyUpdates(sessions::StatusController* status) { DCHECK(CalledOnValidThread()); // This function is called only when we've finished a download cycle, ie. we // got a response with changes_remaining == 0. If this is our first download - // cycle, we should update our state so the NonBlockingTypeProcessor knows - // that it's safe to commit items now. + // cycle, we should update our state so the ModelTypeSyncProxy knows that + // it's safe to commit items now. if (!data_type_state_.initial_sync_done) { data_type_state_.initial_sync_done = true; UpdateResponseDataList empty_update_list; - processor_interface_->ReceiveUpdateResponse(data_type_state_, - empty_update_list); + type_sync_proxy_->ReceiveUpdateResponse(data_type_state_, + empty_update_list); } } -void NonBlockingTypeProcessorCore::PassiveApplyUpdates( +void ModelTypeSyncWorkerImpl::PassiveApplyUpdates( sessions::StatusController* status) { NOTREACHED() << "Non-blocking types should never apply updates on sync thread. " << "ModelType is: " << ModelTypeToString(type_); } -void NonBlockingTypeProcessorCore::EnqueueForCommit( +void ModelTypeSyncWorkerImpl::EnqueueForCommit( const CommitRequestDataList& list) { DCHECK(CalledOnValidThread()); @@ -152,8 +151,8 @@ void NonBlockingTypeProcessorCore::EnqueueForCommit( } // CommitContributor implementation. -scoped_ptr<CommitContribution> -NonBlockingTypeProcessorCore::GetContribution(size_t max_entries) { +scoped_ptr<CommitContribution> ModelTypeSyncWorkerImpl::GetContribution( + size_t max_entries) { DCHECK(CalledOnValidThread()); size_t space_remaining = max_entries; @@ -167,7 +166,7 @@ NonBlockingTypeProcessorCore::GetContribution(size_t max_entries) { for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end() && space_remaining > 0; ++it) { - SyncThreadSyncEntity* entity = it->second; + EntityTracker* entity = it->second; if (entity->IsCommitPending()) { sync_pb::SyncEntity* commit_entity = commit_entities.Add(); int64 sequence_number = -1; @@ -187,7 +186,7 @@ NonBlockingTypeProcessorCore::GetContribution(size_t max_entries) { data_type_state_.type_context, commit_entities, sequence_numbers, this)); } -void NonBlockingTypeProcessorCore::StorePendingCommit( +void ModelTypeSyncWorkerImpl::StorePendingCommit( const CommitRequestData& request) { if (!request.deleted) { DCHECK_EQ(type_, GetModelTypeFromSpecifics(request.specifics)); @@ -195,19 +194,19 @@ void NonBlockingTypeProcessorCore::StorePendingCommit( EntityMap::iterator map_it = entities_.find(request.client_tag_hash); if (map_it == entities_.end()) { - SyncThreadSyncEntity* entity = - SyncThreadSyncEntity::FromCommitRequest(request.id, - request.client_tag_hash, - request.sequence_number, - request.base_version, - request.ctime, - request.mtime, - request.non_unique_name, - request.deleted, - request.specifics); + EntityTracker* entity = + EntityTracker::FromCommitRequest(request.id, + request.client_tag_hash, + request.sequence_number, + request.base_version, + request.ctime, + request.mtime, + request.non_unique_name, + request.deleted, + request.specifics); entities_.insert(std::make_pair(request.client_tag_hash, entity)); } else { - SyncThreadSyncEntity* entity = map_it->second; + EntityTracker* entity = map_it->second; entity->RequestCommit(request.id, request.client_tag_hash, request.sequence_number, @@ -222,7 +221,7 @@ void NonBlockingTypeProcessorCore::StorePendingCommit( // TODO: Nudge SyncScheduler. } -void NonBlockingTypeProcessorCore::OnCommitResponse( +void ModelTypeSyncWorkerImpl::OnCommitResponse( const CommitResponseDataList& response_list) { for (CommitResponseDataList::const_iterator response_it = response_list.begin(); @@ -239,7 +238,7 @@ void NonBlockingTypeProcessorCore::OnCommitResponse( continue; } - SyncThreadSyncEntity* entity = map_it->second; + EntityTracker* entity = map_it->second; entity->ReceiveCommitResponse(response_it->id, response_it->response_version, response_it->sequence_number); @@ -248,22 +247,21 @@ void NonBlockingTypeProcessorCore::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. - processor_interface_->ReceiveCommitResponse(data_type_state_, response_list); + type_sync_proxy_->ReceiveCommitResponse(data_type_state_, response_list); } -base::WeakPtr<NonBlockingTypeProcessorCore> -NonBlockingTypeProcessorCore::AsWeakPtr() { +base::WeakPtr<ModelTypeSyncWorkerImpl> ModelTypeSyncWorkerImpl::AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } -bool NonBlockingTypeProcessorCore::CanCommitItems() const { +bool ModelTypeSyncWorkerImpl::CanCommitItems() const { // We can't commit anything until we know the type's parent node. // We'll get it in the first update response. return !data_type_state_.type_root_id.empty() && data_type_state_.initial_sync_done; } -void NonBlockingTypeProcessorCore::HelpInitializeCommitEntity( +void ModelTypeSyncWorkerImpl::HelpInitializeCommitEntity( sync_pb::SyncEntity* sync_entity) { // Initial commits need our help to generate a client ID. if (!sync_entity->has_id_string()) { diff --git a/sync/engine/non_blocking_type_processor_core.h b/sync/engine/model_type_sync_worker_impl.h index 93d4215..a0e87b1 100644 --- a/sync/engine/non_blocking_type_processor_core.h +++ b/sync/engine/model_type_sync_worker_impl.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ -#define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ +#ifndef SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ +#define SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ #include "base/memory/weak_ptr.h" #include "base/stl_util.h" @@ -21,8 +21,8 @@ class SingleThreadTaskRunner; namespace syncer { -class NonBlockingTypeProcessorInterface; -class SyncThreadSyncEntity; +class ModelTypeSyncProxy; +class EntityTracker; // A smart cache for sync types that use message passing (rather than // transactions and the syncable::Directory) to communicate with the sync @@ -44,24 +44,22 @@ class SyncThreadSyncEntity; // example, if the sync server sends down an update for a sync entity that is // currently pending for commit, this object will detect this condition and // cancel the pending commit. -class SYNC_EXPORT NonBlockingTypeProcessorCore - : public UpdateHandler, - public CommitContributor, - public base::NonThreadSafe { +class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler, + public CommitContributor, + public base::NonThreadSafe { public: - NonBlockingTypeProcessorCore( - ModelType type, - const DataTypeState& initial_state, - scoped_ptr<NonBlockingTypeProcessorInterface> processor_interface); - virtual ~NonBlockingTypeProcessorCore(); + ModelTypeSyncWorkerImpl(ModelType type, + const DataTypeState& initial_state, + scoped_ptr<ModelTypeSyncProxy> type_sync_proxy); + virtual ~ModelTypeSyncWorkerImpl(); ModelType GetModelType() const; // UpdateHandler implementation. virtual void GetDownloadProgress( sync_pb::DataTypeProgressMarker* progress_marker) const OVERRIDE; - virtual void GetDataTypeContext(sync_pb::DataTypeContext* context) const - OVERRIDE; + virtual void GetDataTypeContext( + sync_pb::DataTypeContext* context) const OVERRIDE; virtual SyncerError ProcessGetUpdatesResponse( const sync_pb::DataTypeProgressMarker& progress_marker, const sync_pb::DataTypeContext& mutated_context, @@ -70,7 +68,7 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore virtual void ApplyUpdates(sessions::StatusController* status) OVERRIDE; virtual void PassiveApplyUpdates(sessions::StatusController* status) OVERRIDE; - // Entry point for NonBlockingTypeProcessor to send commit requests. + // Entry point for the ModelTypeSyncProxy to send commit requests. void EnqueueForCommit(const CommitRequestDataList& request_list); // CommitContributor implementation. @@ -80,10 +78,10 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore // Callback for when our contribution gets a response. void OnCommitResponse(const CommitResponseDataList& response_list); - base::WeakPtr<NonBlockingTypeProcessorCore> AsWeakPtr(); + base::WeakPtr<ModelTypeSyncWorkerImpl> AsWeakPtr(); private: - typedef std::map<std::string, SyncThreadSyncEntity*> EntityMap; + typedef std::map<std::string, EntityTracker*> EntityMap; // Stores a single commit request in this object's internal state. void StorePendingCommit(const CommitRequestData& request); @@ -94,7 +92,7 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore bool CanCommitItems() const; // Initializes the parts of a commit entity that are the responsibility of - // this class, and not the SyncThreadSyncEntity. Some fields, like the + // this class, and not the EntityTracker. Some fields, like the // client-assigned ID, can only be set by an entity with knowledge of the // entire data type's state. void HelpInitializeCommitEntity(sync_pb::SyncEntity* commit_entity); @@ -104,10 +102,9 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore // State that applies to the entire model type. DataTypeState data_type_state_; - // Abstraction around the NonBlockingTypeProcessor so this class - // doesn't need to know about its specific implementation or - // which thread it's on. This makes it easier to write tests. - scoped_ptr<NonBlockingTypeProcessorInterface> processor_interface_; + // Pointer to the ModelTypeSyncProxy associated with this worker. + // This is NULL when no proxy is connected.. + scoped_ptr<ModelTypeSyncProxy> type_sync_proxy_; // A map of per-entity information known to this object. // @@ -123,9 +120,9 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore EntityMap entities_; STLValueDeleter<EntityMap> entities_deleter_; - base::WeakPtrFactory<NonBlockingTypeProcessorCore> weak_ptr_factory_; + base::WeakPtrFactory<ModelTypeSyncWorkerImpl> weak_ptr_factory_; }; } // namespace syncer -#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ +#endif // SYNC_ENGINE_MODEL_TYPE_SYNC_WORKER_IMPL_H_ diff --git a/sync/engine/non_blocking_type_processor_core_unittest.cc b/sync/engine/model_type_sync_worker_impl_unittest.cc index c775a33..09b47ad 100644 --- a/sync/engine/non_blocking_type_processor_core_unittest.cc +++ b/sync/engine/model_type_sync_worker_impl_unittest.cc @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/non_blocking_type_processor_core.h" +#include "sync/engine/model_type_sync_worker_impl.h" #include "sync/engine/commit_contribution.h" +#include "sync/engine/model_type_sync_proxy.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor_interface.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/protocol/sync.pb.h" #include "sync/sessions/status_controller.h" #include "sync/syncable/syncable_util.h" -#include "sync/test/engine/mock_non_blocking_type_processor.h" +#include "sync/test/engine/mock_model_type_sync_proxy.h" #include "sync/test/engine/single_type_mock_server.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,7 +21,7 @@ static const syncer::ModelType kModelType = syncer::PREFERENCES; namespace syncer { -// Tests the NonBlockingTypeProcessorCore. +// Tests the ModelTypeSyncWorkerImpl. // // This class passes messages between the model thread and sync server. // As such, its code is subject to lots of different race conditions. This @@ -40,17 +40,17 @@ namespace syncer { // - Update responses to the model thread. // - Nudges to the sync scheduler. // -// We use the MockNonBlockingTypeProcessor to stub out all communication +// We use the MockModelTypeSyncProxy to stub out all communication // with the model thread. That interface is synchronous, which makes it // much easier to test races. // // The interface with the server is built around "pulling" data from this // class, so we don't have to mock out any of it. We wrap it with some // convenience functions to we can emulate server behavior. -class NonBlockingTypeProcessorCoreTest : public ::testing::Test { +class ModelTypeSyncWorkerImplTest : public ::testing::Test { public: - NonBlockingTypeProcessorCoreTest(); - virtual ~NonBlockingTypeProcessorCoreTest(); + ModelTypeSyncWorkerImplTest(); + virtual ~ModelTypeSyncWorkerImplTest(); // One of these Initialize functions should be called at the beginning of // each test. @@ -67,7 +67,7 @@ class NonBlockingTypeProcessorCoreTest : public ::testing::Test { // Initialize with a custom initial DataTypeState. void InitializeWithState(const DataTypeState& state); - // Modifications on the model thread that get sent to the core under test. + // Modifications on the model thread that get sent to the worker under test. void CommitRequest(const std::string& tag, const std::string& value); void DeleteRequest(const std::string& tag); @@ -82,20 +82,20 @@ class NonBlockingTypeProcessorCoreTest : public ::testing::Test { // thread are executed immediately. However, this is not necessarily true. // The model's TaskRunner has a queue, and the tasks we post to it could // linger there for a while. In the meantime, the model thread could - // continue posting tasks to the core based on its stale state. + // continue posting tasks to the worker based on its stale state. // // If you want to test those race cases, then these functions are for you. void SetModelThreadIsSynchronous(bool is_synchronous); void PumpModelThread(); - // Returns true if the |core_| is ready to commit something. + // Returns true if the |worker_| is ready to commit something. bool WillCommit(); // Pretend to successfully commit all outstanding unsynced items. // It is safe to call this only if WillCommit() returns true. void DoSuccessfulCommit(); - // Read commit messages the core_ sent to the emulated server. + // Read commit messages the worker_ sent to the emulated server. size_t GetNumCommitMessagesOnServer() const; sync_pb::ClientToServerMessage GetNthCommitMessageOnServer(size_t n) const; @@ -138,27 +138,27 @@ class NonBlockingTypeProcessorCoreTest : public ::testing::Test { const std::string& value); private: - // The NonBlockingTypeProcessorCore being tested. - scoped_ptr<NonBlockingTypeProcessorCore> core_; + // The ModelTypeSyncWorkerImpl being tested. + scoped_ptr<ModelTypeSyncWorkerImpl> worker_; // Non-owned, possibly NULL pointer. This object belongs to the - // NonBlockingTypeProcessorCore under test. - MockNonBlockingTypeProcessor* mock_processor_; + // ModelTypeSyncWorkerImpl under test. + MockModelTypeSyncProxy* mock_type_sync_proxy_; // A mock that emulates enough of the sync server that it can be used // a single UpdateHandler and CommitContributor pair. In this test - // harness, the |core_| is both of them. + // harness, the |worker_| is both of them. SingleTypeMockServer mock_server_; }; -NonBlockingTypeProcessorCoreTest::NonBlockingTypeProcessorCoreTest() - : mock_processor_(NULL), mock_server_(kModelType) { +ModelTypeSyncWorkerImplTest::ModelTypeSyncWorkerImplTest() + : mock_type_sync_proxy_(NULL), mock_server_(kModelType) { } -NonBlockingTypeProcessorCoreTest::~NonBlockingTypeProcessorCoreTest() { +ModelTypeSyncWorkerImplTest::~ModelTypeSyncWorkerImplTest() { } -void NonBlockingTypeProcessorCoreTest::FirstInitialize() { +void ModelTypeSyncWorkerImplTest::FirstInitialize() { DataTypeState initial_state; initial_state.progress_marker.set_data_type_id( GetSpecificsFieldNumberFromModelType(kModelType)); @@ -167,7 +167,7 @@ void NonBlockingTypeProcessorCoreTest::FirstInitialize() { InitializeWithState(initial_state); } -void NonBlockingTypeProcessorCoreTest::NormalInitialize() { +void ModelTypeSyncWorkerImplTest::NormalInitialize() { DataTypeState initial_state; initial_state.progress_marker.set_data_type_id( GetSpecificsFieldNumberFromModelType(kModelType)); @@ -180,51 +180,50 @@ void NonBlockingTypeProcessorCoreTest::NormalInitialize() { InitializeWithState(initial_state); } -void NonBlockingTypeProcessorCoreTest::InitializeWithState( +void ModelTypeSyncWorkerImplTest::InitializeWithState( const DataTypeState& state) { - DCHECK(!core_); + DCHECK(!worker_); - // We don't get to own this interace. The |core_| keeps a scoped_ptr to it. - mock_processor_ = new MockNonBlockingTypeProcessor(); - scoped_ptr<NonBlockingTypeProcessorInterface> interface(mock_processor_); + // We don't get to own this object. The |worker_| keeps a scoped_ptr to it. + mock_type_sync_proxy_ = new MockModelTypeSyncProxy(); + scoped_ptr<ModelTypeSyncProxy> proxy(mock_type_sync_proxy_); - core_.reset( - new NonBlockingTypeProcessorCore(kModelType, state, interface.Pass())); + worker_.reset(new ModelTypeSyncWorkerImpl(kModelType, state, proxy.Pass())); } -void NonBlockingTypeProcessorCoreTest::CommitRequest(const std::string& name, - const std::string& value) { +void ModelTypeSyncWorkerImplTest::CommitRequest(const std::string& name, + const std::string& value) { const std::string tag_hash = GenerateTagHash(name); - CommitRequestData data = - mock_processor_->CommitRequest(tag_hash, GenerateSpecifics(name, value)); + CommitRequestData data = mock_type_sync_proxy_->CommitRequest( + tag_hash, GenerateSpecifics(name, value)); CommitRequestDataList list; list.push_back(data); - core_->EnqueueForCommit(list); + worker_->EnqueueForCommit(list); } -void NonBlockingTypeProcessorCoreTest::DeleteRequest(const std::string& tag) { +void ModelTypeSyncWorkerImplTest::DeleteRequest(const std::string& tag) { const std::string tag_hash = GenerateTagHash(tag); - CommitRequestData data = mock_processor_->DeleteRequest(tag_hash); + CommitRequestData data = mock_type_sync_proxy_->DeleteRequest(tag_hash); CommitRequestDataList list; list.push_back(data); - core_->EnqueueForCommit(list); + worker_->EnqueueForCommit(list); } -void NonBlockingTypeProcessorCoreTest::TriggerTypeRootUpdateFromServer() { +void ModelTypeSyncWorkerImplTest::TriggerTypeRootUpdateFromServer() { sync_pb::SyncEntity entity = mock_server_.TypeRootUpdate(); SyncEntityList entity_list; entity_list.push_back(&entity); sessions::StatusController dummy_status; - core_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), - mock_server_.GetContext(), - entity_list, - &dummy_status); - core_->ApplyUpdates(&dummy_status); + worker_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), + mock_server_.GetContext(), + entity_list, + &dummy_status); + worker_->ApplyUpdates(&dummy_status); } -void NonBlockingTypeProcessorCoreTest::TriggerUpdateFromServer( +void ModelTypeSyncWorkerImplTest::TriggerUpdateFromServer( int64 version_offset, const std::string& tag, const std::string& value) { @@ -235,14 +234,14 @@ void NonBlockingTypeProcessorCoreTest::TriggerUpdateFromServer( sessions::StatusController dummy_status; - core_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), - mock_server_.GetContext(), - entity_list, - &dummy_status); - core_->ApplyUpdates(&dummy_status); + worker_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), + mock_server_.GetContext(), + entity_list, + &dummy_status); + worker_->ApplyUpdates(&dummy_status); } -void NonBlockingTypeProcessorCoreTest::TriggerTombstoneFromServer( +void ModelTypeSyncWorkerImplTest::TriggerTombstoneFromServer( int64 version_offset, const std::string& tag) { sync_pb::SyncEntity entity = @@ -252,24 +251,25 @@ void NonBlockingTypeProcessorCoreTest::TriggerTombstoneFromServer( sessions::StatusController dummy_status; - core_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), - mock_server_.GetContext(), - entity_list, - &dummy_status); - core_->ApplyUpdates(&dummy_status); + worker_->ProcessGetUpdatesResponse(mock_server_.GetProgress(), + mock_server_.GetContext(), + entity_list, + &dummy_status); + worker_->ApplyUpdates(&dummy_status); } -void NonBlockingTypeProcessorCoreTest::SetModelThreadIsSynchronous( +void ModelTypeSyncWorkerImplTest::SetModelThreadIsSynchronous( bool is_synchronous) { - mock_processor_->SetSynchronousExecution(is_synchronous); + mock_type_sync_proxy_->SetSynchronousExecution(is_synchronous); } -void NonBlockingTypeProcessorCoreTest::PumpModelThread() { - mock_processor_->RunQueuedTasks(); +void ModelTypeSyncWorkerImplTest::PumpModelThread() { + mock_type_sync_proxy_->RunQueuedTasks(); } -bool NonBlockingTypeProcessorCoreTest::WillCommit() { - scoped_ptr<CommitContribution> contribution(core_->GetContribution(INT_MAX)); +bool ModelTypeSyncWorkerImplTest::WillCommit() { + scoped_ptr<CommitContribution> contribution( + worker_->GetContribution(INT_MAX)); if (contribution) { contribution->CleanUp(); // Gracefully abort the commit. @@ -283,9 +283,10 @@ bool NonBlockingTypeProcessorCoreTest::WillCommit() { // remains blocked while the commit is in progress, so we don't need to worry // about other tasks being run between the time when the commit request is // issued and the time when the commit response is received. -void NonBlockingTypeProcessorCoreTest::DoSuccessfulCommit() { +void ModelTypeSyncWorkerImplTest::DoSuccessfulCommit() { DCHECK(WillCommit()); - scoped_ptr<CommitContribution> contribution(core_->GetContribution(INT_MAX)); + scoped_ptr<CommitContribution> contribution( + worker_->GetContribution(INT_MAX)); sync_pb::ClientToServerMessage message; contribution->AddToCommitMessage(&message); @@ -298,101 +299,94 @@ void NonBlockingTypeProcessorCoreTest::DoSuccessfulCommit() { contribution->CleanUp(); } -size_t NonBlockingTypeProcessorCoreTest::GetNumCommitMessagesOnServer() const { +size_t ModelTypeSyncWorkerImplTest::GetNumCommitMessagesOnServer() const { return mock_server_.GetNumCommitMessages(); } sync_pb::ClientToServerMessage -NonBlockingTypeProcessorCoreTest::GetNthCommitMessageOnServer(size_t n) const { +ModelTypeSyncWorkerImplTest::GetNthCommitMessageOnServer(size_t n) const { DCHECK_LT(n, GetNumCommitMessagesOnServer()); return mock_server_.GetNthCommitMessage(n); } -bool NonBlockingTypeProcessorCoreTest::HasCommitEntityOnServer( +bool ModelTypeSyncWorkerImplTest::HasCommitEntityOnServer( const std::string& tag) const { const std::string tag_hash = GenerateTagHash(tag); return mock_server_.HasCommitEntity(tag_hash); } -sync_pb::SyncEntity -NonBlockingTypeProcessorCoreTest::GetLatestCommitEntityOnServer( +sync_pb::SyncEntity ModelTypeSyncWorkerImplTest::GetLatestCommitEntityOnServer( const std::string& tag) const { DCHECK(HasCommitEntityOnServer(tag)); const std::string tag_hash = GenerateTagHash(tag); return mock_server_.GetLastCommittedEntity(tag_hash); } -size_t NonBlockingTypeProcessorCoreTest::GetNumModelThreadUpdateResponses() - const { - return mock_processor_->GetNumUpdateResponses(); +size_t ModelTypeSyncWorkerImplTest::GetNumModelThreadUpdateResponses() const { + return mock_type_sync_proxy_->GetNumUpdateResponses(); } UpdateResponseDataList -NonBlockingTypeProcessorCoreTest::GetNthModelThreadUpdateResponse( - size_t n) const { +ModelTypeSyncWorkerImplTest::GetNthModelThreadUpdateResponse(size_t n) const { DCHECK_LT(n, GetNumModelThreadUpdateResponses()); - return mock_processor_->GetNthUpdateResponse(n); + return mock_type_sync_proxy_->GetNthUpdateResponse(n); } -DataTypeState NonBlockingTypeProcessorCoreTest::GetNthModelThreadUpdateState( +DataTypeState ModelTypeSyncWorkerImplTest::GetNthModelThreadUpdateState( size_t n) const { DCHECK_LT(n, GetNumModelThreadUpdateResponses()); - return mock_processor_->GetNthTypeStateReceivedInUpdateResponse(n); + return mock_type_sync_proxy_->GetNthTypeStateReceivedInUpdateResponse(n); } -bool NonBlockingTypeProcessorCoreTest::HasUpdateResponseOnModelThread( +bool ModelTypeSyncWorkerImplTest::HasUpdateResponseOnModelThread( const std::string& tag) const { const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_->HasUpdateResponse(tag_hash); + return mock_type_sync_proxy_->HasUpdateResponse(tag_hash); } -UpdateResponseData -NonBlockingTypeProcessorCoreTest::GetUpdateResponseOnModelThread( +UpdateResponseData ModelTypeSyncWorkerImplTest::GetUpdateResponseOnModelThread( const std::string& tag) const { const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_->GetUpdateResponse(tag_hash); + return mock_type_sync_proxy_->GetUpdateResponse(tag_hash); } -size_t NonBlockingTypeProcessorCoreTest::GetNumModelThreadCommitResponses() - const { - return mock_processor_->GetNumCommitResponses(); +size_t ModelTypeSyncWorkerImplTest::GetNumModelThreadCommitResponses() const { + return mock_type_sync_proxy_->GetNumCommitResponses(); } CommitResponseDataList -NonBlockingTypeProcessorCoreTest::GetNthModelThreadCommitResponse( - size_t n) const { +ModelTypeSyncWorkerImplTest::GetNthModelThreadCommitResponse(size_t n) const { DCHECK_LT(n, GetNumModelThreadCommitResponses()); - return mock_processor_->GetNthCommitResponse(n); + return mock_type_sync_proxy_->GetNthCommitResponse(n); } -DataTypeState NonBlockingTypeProcessorCoreTest::GetNthModelThreadCommitState( +DataTypeState ModelTypeSyncWorkerImplTest::GetNthModelThreadCommitState( size_t n) const { DCHECK_LT(n, GetNumModelThreadCommitResponses()); - return mock_processor_->GetNthTypeStateReceivedInCommitResponse(n); + return mock_type_sync_proxy_->GetNthTypeStateReceivedInCommitResponse(n); } -bool NonBlockingTypeProcessorCoreTest::HasCommitResponseOnModelThread( +bool ModelTypeSyncWorkerImplTest::HasCommitResponseOnModelThread( const std::string& tag) const { const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_->HasCommitResponse(tag_hash); + return mock_type_sync_proxy_->HasCommitResponse(tag_hash); } -CommitResponseData -NonBlockingTypeProcessorCoreTest::GetCommitResponseOnModelThread( +CommitResponseData ModelTypeSyncWorkerImplTest::GetCommitResponseOnModelThread( const std::string& tag) const { DCHECK(HasCommitResponseOnModelThread(tag)); const std::string tag_hash = GenerateTagHash(tag); - return mock_processor_->GetCommitResponse(tag_hash); + return mock_type_sync_proxy_->GetCommitResponse(tag_hash); } -std::string NonBlockingTypeProcessorCoreTest::GenerateTagHash( +std::string ModelTypeSyncWorkerImplTest::GenerateTagHash( const std::string& tag) { const std::string& client_tag_hash = syncable::GenerateSyncableHash(kModelType, tag); return client_tag_hash; } -sync_pb::EntitySpecifics NonBlockingTypeProcessorCoreTest::GenerateSpecifics( +sync_pb::EntitySpecifics ModelTypeSyncWorkerImplTest::GenerateSpecifics( const std::string& tag, const std::string& value) { sync_pb::EntitySpecifics specifics; @@ -406,10 +400,10 @@ sync_pb::EntitySpecifics NonBlockingTypeProcessorCoreTest::GenerateSpecifics( // // This test performs sanity checks on most of the fields in these messages. // For the most part this is checking that the test code behaves as expected -// and the |core_| doesn't mess up its simple task of moving around these +// and the |worker_| doesn't mess up its simple task of moving around these // values. It makes sense to have one or two tests that are this thorough, but // we shouldn't be this verbose in all tests. -TEST_F(NonBlockingTypeProcessorCoreTest, SimpleCommit) { +TEST_F(ModelTypeSyncWorkerImplTest, SimpleCommit) { NormalInitialize(); EXPECT_FALSE(WillCommit()); @@ -454,7 +448,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, SimpleCommit) { EXPECT_LT(0, commit_response.response_version); } -TEST_F(NonBlockingTypeProcessorCoreTest, SimpleDelete) { +TEST_F(ModelTypeSyncWorkerImplTest, SimpleDelete) { NormalInitialize(); // We can't delete an entity that was never committed. @@ -502,7 +496,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, SimpleDelete) { // The server doesn't like it when we try to delete an entity it's never heard // of before. This test helps ensure we avoid that scenario. -TEST_F(NonBlockingTypeProcessorCoreTest, NoDeleteUncommitted) { +TEST_F(ModelTypeSyncWorkerImplTest, NoDeleteUncommitted) { NormalInitialize(); // Request the commit of a new, never-before-seen item. @@ -515,7 +509,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, NoDeleteUncommitted) { } // Verifies the sending of an "initial sync done" signal. -TEST_F(NonBlockingTypeProcessorCoreTest, SendInitialSyncDone) { +TEST_F(ModelTypeSyncWorkerImplTest, SendInitialSyncDone) { FirstInitialize(); // Initialize with no saved sync state. EXPECT_EQ(0U, GetNumModelThreadUpdateResponses()); @@ -524,7 +518,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, SendInitialSyncDone) { // Two updates: // - One triggered by process updates to forward the type root ID. - // - One triggered by apply updates, which the core interprets to mean + // - One triggered by apply updates, which the worker interprets to mean // "initial sync done". This triggers a model thread update, too. EXPECT_EQ(2U, GetNumModelThreadUpdateResponses()); @@ -539,7 +533,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, SendInitialSyncDone) { } // Commit two new entities in two separate commit messages. -TEST_F(NonBlockingTypeProcessorCoreTest, TwoNewItemsCommittedSeparately) { +TEST_F(ModelTypeSyncWorkerImplTest, TwoNewItemsCommittedSeparately) { NormalInitialize(); // Commit the first of two entities. @@ -564,7 +558,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, TwoNewItemsCommittedSeparately) { EXPECT_FALSE(WillCommit()); - // The IDs assigned by the |core_| should be unique. + // The IDs assigned by the |worker_| should be unique. EXPECT_NE(tag1_entity.id_string(), tag2_entity.id_string()); // Check that the committed specifics values are sane. @@ -576,7 +570,7 @@ TEST_F(NonBlockingTypeProcessorCoreTest, TwoNewItemsCommittedSeparately) { EXPECT_EQ(2U, GetNumModelThreadCommitResponses()); } -TEST_F(NonBlockingTypeProcessorCoreTest, ReceiveUpdates) { +TEST_F(ModelTypeSyncWorkerImplTest, ReceiveUpdates) { NormalInitialize(); const std::string& tag_hash = GenerateTagHash("tag1"); diff --git a/sync/engine/non_blocking_sync_common.h b/sync/engine/non_blocking_sync_common.h index d0e0f9d..cefccfe 100644 --- a/sync/engine/non_blocking_sync_common.h +++ b/sync/engine/non_blocking_sync_common.h @@ -47,7 +47,7 @@ struct SYNC_EXPORT_PRIVATE DataTypeState { int64 next_client_id; // This flag is set to true when the first download cycle is complete. The - // NonBlockingTypeProcessor should not attempt to commit any items until this + // ModelTypeSyncProxy should not attempt to commit any items until this // flag is set. bool initial_sync_done; }; diff --git a/sync/engine/non_blocking_type_commit_contribution.cc b/sync/engine/non_blocking_type_commit_contribution.cc index 9e48ad6..39823a5 100644 --- a/sync/engine/non_blocking_type_commit_contribution.cc +++ b/sync/engine/non_blocking_type_commit_contribution.cc @@ -4,8 +4,8 @@ #include "sync/engine/non_blocking_type_commit_contribution.h" +#include "sync/engine/model_type_sync_worker_impl.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor_core.h" #include "sync/protocol/proto_value_conversions.h" namespace syncer { @@ -14,8 +14,8 @@ NonBlockingTypeCommitContribution::NonBlockingTypeCommitContribution( const sync_pb::DataTypeContext& context, const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, const std::vector<int64>& sequence_numbers, - NonBlockingTypeProcessorCore* processor_core) - : processor_core_(processor_core), + ModelTypeSyncWorkerImpl* worker) + : worker_(worker), context_(context), entities_(entities), sequence_numbers_(sequence_numbers), @@ -90,7 +90,7 @@ SyncerError NonBlockingTypeCommitContribution::ProcessCommitResponse( // Send whatever successful responses we did get back to our parent. // It's the schedulers job to handle the failures. - processor_core_->OnCommitResponse(response_list); + worker_->OnCommitResponse(response_list); // Let the scheduler know about the failures. if (unknown_error) { diff --git a/sync/engine/non_blocking_type_commit_contribution.h b/sync/engine/non_blocking_type_commit_contribution.h index 4d415ca..d732130 100644 --- a/sync/engine/non_blocking_type_commit_contribution.h +++ b/sync/engine/non_blocking_type_commit_contribution.h @@ -13,19 +13,19 @@ namespace syncer { -class NonBlockingTypeProcessorCore; +class ModelTypeSyncWorkerImpl; // A non-blocking sync type's contribution to an outgoing commit message. // // Helps build a commit message and process its response. It collaborates -// closely with the NonBlockingTypeProcessorCore. +// closely with the ModelTypeSyncWorkerImpl. class NonBlockingTypeCommitContribution : public CommitContribution { public: NonBlockingTypeCommitContribution( const sync_pb::DataTypeContext& context, const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, const std::vector<int64>& sequence_numbers, - NonBlockingTypeProcessorCore* processor_core); + ModelTypeSyncWorkerImpl* worker); virtual ~NonBlockingTypeCommitContribution(); // Implementation of CommitContribution @@ -38,7 +38,7 @@ class NonBlockingTypeCommitContribution : public CommitContribution { private: // A non-owned pointer back to the object that created this contribution. - NonBlockingTypeProcessorCore* const processor_core_; + ModelTypeSyncWorkerImpl* const worker_; // The type-global context information. const sync_pb::DataTypeContext context_; diff --git a/sync/engine/non_blocking_type_processor_core_interface.cc b/sync/engine/non_blocking_type_processor_core_interface.cc deleted file mode 100644 index 6ce74cc..0000000 --- a/sync/engine/non_blocking_type_processor_core_interface.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 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/engine/non_blocking_type_processor_core_interface.h" - -namespace syncer { - -NonBlockingTypeProcessorCoreInterface::NonBlockingTypeProcessorCoreInterface() { -} - -NonBlockingTypeProcessorCoreInterface:: - ~NonBlockingTypeProcessorCoreInterface() { -} - -} // namespace syncer diff --git a/sync/engine/non_blocking_type_processor_core_interface.h b/sync/engine/non_blocking_type_processor_core_interface.h deleted file mode 100644 index 56675c2..0000000 --- a/sync/engine/non_blocking_type_processor_core_interface.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 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_ENGINE_NON_BLOCKING_TYPE_CORE_INTERFACE_H_ -#define SYNC_ENGINE_NON_BLOCKING_TYPE_CORE_INTERFACE_H_ - -#include "sync/engine/non_blocking_sync_common.h" - -namespace syncer { - -// An interface representing a NonBlockingTypeProcessorCore and its thread. -// This abstraction is useful in tests. -class SYNC_EXPORT_PRIVATE NonBlockingTypeProcessorCoreInterface { - public: - NonBlockingTypeProcessorCoreInterface(); - virtual ~NonBlockingTypeProcessorCoreInterface(); - - virtual void RequestCommits(const CommitRequestDataList& list) = 0; -}; - -} // namespace syncer - -#endif // SYNC_ENGINE_NON_BLOCKING_TYPE_CORE_INTERFACE_H_ diff --git a/sync/internal_api/public/sync_core_proxy.h b/sync/internal_api/public/sync_context_proxy.h index 099b5f9..14bf14f 100644 --- a/sync/internal_api/public/sync_core_proxy.h +++ b/sync/internal_api/public/sync_context_proxy.h @@ -2,32 +2,32 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_ -#define SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_ +#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_PROXY_H_ +#define SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_PROXY_H_ #include "base/memory/weak_ptr.h" #include "sync/internal_api/public/base/model_type.h" namespace syncer { -class NonBlockingTypeProcessor; +class ModelTypeSyncProxyImpl; struct DataTypeState; // Interface for the datatype integration logic from non-sync threads. // -// See SyncCoreProxyImpl for an actual implementation. -class SYNC_EXPORT_PRIVATE SyncCoreProxy { +// See SyncContextProxyImpl for an actual implementation. +class SYNC_EXPORT_PRIVATE SyncContextProxy { public: - SyncCoreProxy(); - virtual ~SyncCoreProxy(); + SyncContextProxy(); + virtual ~SyncContextProxy(); - // Attempts to connect a non-blocking type to the sync core. + // Attempts to connect a non-blocking type to the sync context. // // Must be called from the thread where the data type lives. - virtual void ConnectTypeToCore( + virtual void ConnectTypeToSync( syncer::ModelType type, const DataTypeState& data_type_state, - base::WeakPtr<NonBlockingTypeProcessor> type_processor) = 0; + const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0; // Tells the syncer that we're no longer interested in syncing this type. // @@ -36,10 +36,10 @@ class SYNC_EXPORT_PRIVATE SyncCoreProxy { // and applying updates for this type, too. virtual void Disconnect(syncer::ModelType type) = 0; - // Creates a clone of this SyncCoreProxy. - virtual scoped_ptr<SyncCoreProxy> Clone() const = 0; + // Creates a clone of this SyncContextProxy. + virtual scoped_ptr<SyncContextProxy> Clone() const = 0; }; } // namespace syncer -#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_PROXY_H_ +#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_PROXY_H_ diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h index 5c9f09f..2446b68 100644 --- a/sync/internal_api/public/sync_manager.h +++ b/sync/internal_api/public/sync_manager.h @@ -22,7 +22,7 @@ #include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/internal_api/public/engine/sync_status.h" #include "sync/internal_api/public/events/protocol_event.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_encryption_handler.h" #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" #include "sync/internal_api/public/util/unrecoverable_error_handler.h" @@ -46,7 +46,7 @@ class InternalComponentsFactory; class JsBackend; class JsEventHandler; class ProtocolEvent; -class SyncCoreProxy; +class SyncContextProxy; class SyncEncryptionHandler; class SyncScheduler; class TypeDebugInfoObserver; @@ -332,7 +332,7 @@ class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { virtual UserShare* GetUserShare() = 0; // Returns an instance of the main interface for non-blocking sync types. - virtual syncer::SyncCoreProxy* GetSyncCoreProxy() = 0; + virtual syncer::SyncContextProxy* GetSyncContextProxy() = 0; // Returns the cache_guid of the currently open database. // Requires that the SyncManager be initialized. diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h index 31f5d412..df14a52 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -10,7 +10,7 @@ #include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "sync/internal_api/public/sync_manager.h" -#include "sync/internal_api/public/test/null_sync_core_proxy.h" +#include "sync/internal_api/public/test/null_sync_context_proxy.h" #include "sync/internal_api/public/test/test_user_share.h" namespace base { @@ -118,7 +118,7 @@ class FakeSyncManager : public SyncManager { virtual void SaveChanges() OVERRIDE; virtual void ShutdownOnSyncThread() OVERRIDE; virtual UserShare* GetUserShare() OVERRIDE; - virtual syncer::SyncCoreProxy* GetSyncCoreProxy() OVERRIDE; + virtual syncer::SyncContextProxy* GetSyncContextProxy() OVERRIDE; virtual const std::string cache_guid() OVERRIDE; virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; virtual bool HasUnsyncedItems() OVERRIDE; @@ -166,7 +166,7 @@ class FakeSyncManager : public SyncManager { TestUserShare test_user_share_; - NullSyncCoreProxy null_sync_core_proxy_; + NullSyncContextProxy null_sync_context_proxy_; DISALLOW_COPY_AND_ASSIGN(FakeSyncManager); }; diff --git a/sync/internal_api/public/test/null_sync_context_proxy.h b/sync/internal_api/public/test/null_sync_context_proxy.h new file mode 100644 index 0000000..808f664 --- /dev/null +++ b/sync/internal_api/public/test/null_sync_context_proxy.h @@ -0,0 +1,33 @@ +// Copyright 2014 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_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CONTEXT_PROXY_H_ +#define SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CONTEXT_PROXY_H_ + +#include "base/memory/weak_ptr.h" +#include "sync/internal_api/public/sync_context_proxy.h" + +namespace syncer { + +class ModelTypeSyncProxyImpl; + +// A non-functional implementation of SyncContextProxy. +// +// It supports Clone(), but not much else. Useful for testing. +class NullSyncContextProxy : public SyncContextProxy { + public: + NullSyncContextProxy(); + virtual ~NullSyncContextProxy(); + + virtual void ConnectTypeToSync( + syncer::ModelType type, + const DataTypeState& data_type_state, + const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) OVERRIDE; + virtual void Disconnect(syncer::ModelType type) OVERRIDE; + virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE; +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CONTEXT_PROXY_H_ diff --git a/sync/internal_api/public/test/null_sync_core_proxy.h b/sync/internal_api/public/test/null_sync_core_proxy.h deleted file mode 100644 index 4c8fc67..0000000 --- a/sync/internal_api/public/test/null_sync_core_proxy.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2014 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_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CORE_PROXY_H_ -#define SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CORE_PROXY_H_ - -#include "sync/internal_api/public/sync_core_proxy.h" -#include "base/memory/weak_ptr.h" - -namespace syncer { - -class NonBlockingTypeProcessor; - -// A non-functional implementation of SyncCoreProxy. -// -// It supports Clone(), but not much else. Useful for testing. -class NullSyncCoreProxy : public SyncCoreProxy { - public: - NullSyncCoreProxy(); - virtual ~NullSyncCoreProxy(); - - virtual void ConnectTypeToCore( - syncer::ModelType type, - const DataTypeState& data_type_state, - base::WeakPtr<NonBlockingTypeProcessor> processor) OVERRIDE; - virtual void Disconnect(syncer::ModelType type) OVERRIDE; - virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE; -}; - -} // namespace syncer - -#endif // SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CORE_PROXY_H_ diff --git a/sync/internal_api/sync_context.cc b/sync/internal_api/sync_context.cc new file mode 100644 index 0000000..a1e87e2 --- /dev/null +++ b/sync/internal_api/sync_context.cc @@ -0,0 +1,39 @@ +// Copyright 2014 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/internal_api/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() { +} + +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_core.h b/sync/internal_api/sync_context.h index 417a296..3dc2ae0 100644 --- a/sync/internal_api/sync_core.h +++ b/sync/internal_api/sync_context.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_H_ -#define SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_H_ +#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_H_ +#define SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_H_ #include "base/basictypes.h" #include "base/memory/weak_ptr.h" @@ -14,7 +14,7 @@ namespace syncer { class ModelTypeRegistry; -class NonBlockingTypeProcessor; +class ModelTypeSyncProxyImpl; struct DataTypeState; // An interface of the core parts of sync. @@ -25,40 +25,40 @@ struct DataTypeState; // functionality to other classes, and most of the interface is exposed not // directly here but instead through a per-ModelType class that this class helps // instantiate. -class SYNC_EXPORT_PRIVATE SyncCore { +class SYNC_EXPORT_PRIVATE SyncContext { public: - explicit SyncCore(ModelTypeRegistry* model_type_registry); - ~SyncCore(); + explicit SyncContext(ModelTypeRegistry* model_type_registry); + ~SyncContext(); - // Initializes the connection between the sync core and its delegate on the - // sync client's thread. - void ConnectSyncTypeToCore( + // 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( syncer::ModelType type, const DataTypeState& data_type_state, - scoped_refptr<base::SequencedTaskRunner> datatype_task_runner, - base::WeakPtr<NonBlockingTypeProcessor> sync_client); + const scoped_refptr<base::SequencedTaskRunner>& datatype_task_runner, + const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy); // Disconnects the syncer from the model and stops syncing the type. // // By the time this is called, the model thread should have already // invalidated the WeakPtr it sent to us in the connect request. Any - // messages sent to that NonBlockingTypeProcessor will not be recived. + // messages sent to that ModelTypeSyncProxy will not be recived. // // 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<SyncCore> AsWeakPtr(); + base::WeakPtr<SyncContext> AsWeakPtr(); private: ModelTypeRegistry* model_type_registry_; - base::WeakPtrFactory<SyncCore> weak_ptr_factory_; + base::WeakPtrFactory<SyncContext> weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(SyncCore); + DISALLOW_COPY_AND_ASSIGN(SyncContext); }; } // namespace syncer -#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_CORE_H_ - +#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_CONTEXT_H_ diff --git a/sync/internal_api/sync_context_proxy.cc b/sync/internal_api/sync_context_proxy.cc new file mode 100644 index 0000000..53c2bd3 --- /dev/null +++ b/sync/internal_api/sync_context_proxy.cc @@ -0,0 +1,15 @@ +// Copyright 2014 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/internal_api/public/sync_context_proxy.h" + +namespace syncer { + +SyncContextProxy::SyncContextProxy() { +} + +SyncContextProxy::~SyncContextProxy() { +} + +} // namespace syncer diff --git a/sync/internal_api/sync_context_proxy_impl.cc b/sync/internal_api/sync_context_proxy_impl.cc new file mode 100644 index 0000000..77f3d6a --- /dev/null +++ b/sync/internal_api/sync_context_proxy_impl.cc @@ -0,0 +1,48 @@ +// Copyright 2014 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/internal_api/sync_context_proxy_impl.h" + +#include "base/bind.h" +#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" + +namespace syncer { + +SyncContextProxyImpl::SyncContextProxyImpl( + const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, + const base::WeakPtr<SyncContext>& sync_context) + : sync_task_runner_(sync_task_runner), sync_context_(sync_context) { +} + +SyncContextProxyImpl::~SyncContextProxyImpl() { +} + +void SyncContextProxyImpl::ConnectTypeToSync( + ModelType type, + const DataTypeState& data_type_state, + const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) { + VLOG(1) << "ConnectTypeToSync: " << ModelTypeToString(type); + sync_task_runner_->PostTask(FROM_HERE, + base::Bind(&SyncContext::ConnectSyncTypeToWorker, + sync_context_, + type, + data_type_state, + base::MessageLoopProxy::current(), + type_sync_proxy)); +} + +void SyncContextProxyImpl::Disconnect(ModelType type) { + sync_task_runner_->PostTask( + FROM_HERE, base::Bind(&SyncContext::Disconnect, sync_context_, type)); +} + +scoped_ptr<SyncContextProxy> SyncContextProxyImpl::Clone() const { + return scoped_ptr<SyncContextProxy>( + new SyncContextProxyImpl(sync_task_runner_, sync_context_)); +} + +} // namespace syncer diff --git a/sync/internal_api/sync_core_proxy_impl.h b/sync/internal_api/sync_context_proxy_impl.h index 91061fe..fb7cd4f 100644 --- a/sync/internal_api/sync_core_proxy_impl.h +++ b/sync/internal_api/sync_context_proxy_impl.h @@ -2,59 +2,59 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ -#define SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ +#ifndef SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_ +#define SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/sequenced_task_runner.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" namespace syncer { -class SyncCore; -class NonBlockingTypeProcessor; +class SyncContext; +class ModelTypeSyncProxyImpl; struct DataTypeState; -// Encapsulates a reference to the sync core and the thread it's running on. -// Used by sync's data types to connect with the sync core. +// Encapsulates a reference to the sync context and the thread it's running on. +// Used by sync's data types to connect with the sync context. // -// It is epxected that this object will be copied to and used on many different +// It is expected that this object will be copied to and used on many different // threads. It is small and safe to pass by value. -class SYNC_EXPORT_PRIVATE SyncCoreProxyImpl : public SyncCoreProxy { +class SYNC_EXPORT_PRIVATE SyncContextProxyImpl : public SyncContextProxy { public: - SyncCoreProxyImpl( - scoped_refptr<base::SequencedTaskRunner> sync_task_runner, - base::WeakPtr<SyncCore> sync_core); - virtual ~SyncCoreProxyImpl(); + SyncContextProxyImpl( + const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner, + const base::WeakPtr<SyncContext>& sync_context); + virtual ~SyncContextProxyImpl(); - // Attempts to connect a non-blocking type to the sync core. + // Attempts to connect a non-blocking type to the sync context. // // This may fail under some unusual circumstances, like shutdown. Due to the // nature of WeakPtrs and cross-thread communication, the caller will be // unable to distinguish a slow success from failure. // // Must be called from the thread where the data type lives. - virtual void ConnectTypeToCore( + virtual void ConnectTypeToSync( syncer::ModelType type, const DataTypeState& data_type_state, - base::WeakPtr<NonBlockingTypeProcessor> type_processor) OVERRIDE; + const base::WeakPtr<ModelTypeSyncProxyImpl>& sync_proxy_impl) OVERRIDE; // Disables syncing for the given type on the sync thread. virtual void Disconnect(syncer::ModelType type) OVERRIDE; - virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE; + virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE; private: - // A SequencedTaskRunner representing the thread where the SyncCore lives. + // A SequencedTaskRunner representing the thread where the SyncContext lives. scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; - // The SyncCore this object is wrapping. - base::WeakPtr<SyncCore> sync_core_; + // The SyncContext this object is wrapping. + base::WeakPtr<SyncContext> sync_context_; }; } // namespace syncer -#endif // SYNC_INTERNAL_API_SYNC_CORE_PROXY_IMPL_H_ +#endif // SYNC_INTERNAL_API_SYNC_CONTEXT_PROXY_IMPL_H_ diff --git a/sync/internal_api/sync_context_proxy_impl_unittest.cc b/sync/internal_api/sync_context_proxy_impl_unittest.cc new file mode 100644 index 0000000..62edfec --- /dev/null +++ b/sync/internal_api/sync_context_proxy_impl_unittest.cc @@ -0,0 +1,89 @@ +// Copyright 2014 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 "base/message_loop/message_loop.h" +#include "base/message_loop/message_loop_proxy.h" +#include "base/run_loop.h" +#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/sync_context_proxy_impl.h" +#include "sync/sessions/model_type_registry.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { + +class SyncContextProxyImplTest : public ::testing::Test { + public: + SyncContextProxyImplTest() + : sync_task_runner_(base::MessageLoopProxy::current()), + type_task_runner_(base::MessageLoopProxy::current()), + context_(new SyncContext(®istry_)), + context_proxy_(sync_task_runner_, context_->AsWeakPtr()) {} + + // The sync thread could be shut down at any time without warning. This + // function simulates such an event. + void DisableSync() { context_.reset(); } + + scoped_ptr<SyncContextProxy> GetProxy() { return context_proxy_.Clone(); } + + private: + base::MessageLoop loop_; + scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; + scoped_refptr<base::SequencedTaskRunner> type_task_runner_; + ModelTypeRegistry registry_; + scoped_ptr<SyncContext> context_; + SyncContextProxyImpl context_proxy_; +}; + +// Try to connect a type to a SyncContext that has already shut down. +TEST_F(SyncContextProxyImplTest, FailToConnect1) { + ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); + DisableSync(); + themes_sync_proxy.Enable(GetProxy()); + + base::RunLoop run_loop_; + run_loop_.RunUntilIdle(); + EXPECT_FALSE(themes_sync_proxy.IsConnected()); +} + +// Try to connect a type to a SyncContext as it shuts down. +TEST_F(SyncContextProxyImplTest, FailToConnect2) { + ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); + themes_sync_proxy.Enable(GetProxy()); + DisableSync(); + + base::RunLoop run_loop_; + run_loop_.RunUntilIdle(); + EXPECT_FALSE(themes_sync_proxy.IsConnected()); +} + +// Tests the case where the type's sync proxy shuts down first. +TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { + scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( + new ModelTypeSyncProxyImpl(syncer::THEMES)); + themes_sync_proxy->Enable(GetProxy()); + + base::RunLoop run_loop_; + run_loop_.RunUntilIdle(); + + EXPECT_TRUE(themes_sync_proxy->IsConnected()); + themes_sync_proxy.reset(); +} + +// Tests the case where the sync thread shuts down first. +TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { + scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( + new ModelTypeSyncProxyImpl(syncer::THEMES)); + themes_sync_proxy->Enable(GetProxy()); + + base::RunLoop run_loop_; + run_loop_.RunUntilIdle(); + + EXPECT_TRUE(themes_sync_proxy->IsConnected()); + DisableSync(); +} + +} // namespace syncer diff --git a/sync/internal_api/sync_core.cc b/sync/internal_api/sync_core.cc deleted file mode 100644 index 6707176..0000000 --- a/sync/internal_api/sync_core.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 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/internal_api/sync_core.h" - -#include "sync/engine/non_blocking_type_processor_core.h" -#include "sync/sessions/model_type_registry.h" - -namespace syncer { - -SyncCore::SyncCore(ModelTypeRegistry* model_type_registry) - : model_type_registry_(model_type_registry), weak_ptr_factory_(this) {} - -SyncCore::~SyncCore() {} - -void SyncCore::ConnectSyncTypeToCore( - ModelType type, - const DataTypeState& data_type_state, - scoped_refptr<base::SequencedTaskRunner> task_runner, - base::WeakPtr<NonBlockingTypeProcessor> processor) { - // Initialize the processor's sync-thread sibling and the - // processor <-> processor_core (ie. model thread <-> sync thread) - // communication channel. - model_type_registry_->InitializeNonBlockingType( - type, data_type_state, task_runner, processor); -} - -void SyncCore::Disconnect(ModelType type) { - model_type_registry_->RemoveNonBlockingType(type); -} - -base::WeakPtr<SyncCore> SyncCore::AsWeakPtr() { - return weak_ptr_factory_.GetWeakPtr(); -} - -} // namespace syncer diff --git a/sync/internal_api/sync_core_proxy_impl.cc b/sync/internal_api/sync_core_proxy_impl.cc deleted file mode 100644 index 81c0fa2..0000000 --- a/sync/internal_api/sync_core_proxy_impl.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 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/internal_api/sync_core_proxy_impl.h" - -#include "base/bind.h" -#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_core.h" - -namespace syncer { - -SyncCoreProxyImpl::SyncCoreProxyImpl( - scoped_refptr<base::SequencedTaskRunner> sync_task_runner, - base::WeakPtr<SyncCore> sync_core) - : sync_task_runner_(sync_task_runner), - sync_core_(sync_core) {} - -SyncCoreProxyImpl::~SyncCoreProxyImpl() {} - -void SyncCoreProxyImpl::ConnectTypeToCore( - ModelType type, - const DataTypeState& data_type_state, - base::WeakPtr<NonBlockingTypeProcessor> type_processor) { - VLOG(1) << "ConnectTypeToCore: " << ModelTypeToString(type); - sync_task_runner_->PostTask(FROM_HERE, - base::Bind(&SyncCore::ConnectSyncTypeToCore, - sync_core_, - type, - data_type_state, - base::MessageLoopProxy::current(), - type_processor)); -} - -void SyncCoreProxyImpl::Disconnect(ModelType type) { - sync_task_runner_->PostTask( - FROM_HERE, base::Bind(&SyncCore::Disconnect, sync_core_, type)); -} - -scoped_ptr<SyncCoreProxy> SyncCoreProxyImpl::Clone() const { - return scoped_ptr<SyncCoreProxy>( - new SyncCoreProxyImpl(sync_task_runner_, sync_core_)); -} - -} // namespace syncer diff --git a/sync/internal_api/sync_core_proxy_impl_unittest.cc b/sync/internal_api/sync_core_proxy_impl_unittest.cc deleted file mode 100644 index 25b3d9e..0000000 --- a/sync/internal_api/sync_core_proxy_impl_unittest.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2014 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 "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_proxy.h" -#include "base/run_loop.h" -#include "base/sequenced_task_runner.h" -#include "sync/engine/non_blocking_type_processor.h" -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/sync_core.h" -#include "sync/internal_api/sync_core_proxy_impl.h" -#include "sync/sessions/model_type_registry.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { - -class SyncCoreProxyImplTest : public ::testing::Test { - public: - SyncCoreProxyImplTest() - : sync_task_runner_(base::MessageLoopProxy::current()), - type_task_runner_(base::MessageLoopProxy::current()), - core_(new SyncCore(®istry_)), - core_proxy_( - sync_task_runner_, - core_->AsWeakPtr()) {} - - // The sync thread could be shut down at any time without warning. This - // function simulates such an event. - void DisableSync() { - core_.reset(); - } - - scoped_ptr<SyncCoreProxy> GetProxy() { return core_proxy_.Clone(); } - - private: - base::MessageLoop loop_; - scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; - scoped_refptr<base::SequencedTaskRunner> type_task_runner_; - ModelTypeRegistry registry_; - scoped_ptr<SyncCore> core_; - SyncCoreProxyImpl core_proxy_; -}; - -// Try to connect a type to a SyncCore that has already shut down. -TEST_F(SyncCoreProxyImplTest, FailToConnect1) { - NonBlockingTypeProcessor themes_processor(syncer::THEMES); - DisableSync(); - themes_processor.Enable(GetProxy()); - - base::RunLoop run_loop_; - run_loop_.RunUntilIdle(); - EXPECT_FALSE(themes_processor.IsConnected()); -} - -// Try to connect a type to a SyncCore as it shuts down. -TEST_F(SyncCoreProxyImplTest, FailToConnect2) { - NonBlockingTypeProcessor themes_processor(syncer::THEMES); - themes_processor.Enable(GetProxy()); - DisableSync(); - - base::RunLoop run_loop_; - run_loop_.RunUntilIdle(); - EXPECT_FALSE(themes_processor.IsConnected()); -} - -// Tests the case where the type's processor shuts down first. -TEST_F(SyncCoreProxyImplTest, TypeDisconnectsFirst) { - scoped_ptr<NonBlockingTypeProcessor> themes_processor - (new NonBlockingTypeProcessor(syncer::THEMES)); - themes_processor->Enable(GetProxy()); - - base::RunLoop run_loop_; - run_loop_.RunUntilIdle(); - - EXPECT_TRUE(themes_processor->IsConnected()); - themes_processor.reset(); -} - -// Tests the case where the sync thread shuts down first. -TEST_F(SyncCoreProxyImplTest, SyncDisconnectsFirst) { - scoped_ptr<NonBlockingTypeProcessor> themes_processor - (new NonBlockingTypeProcessor(syncer::THEMES)); - themes_processor->Enable(GetProxy()); - - base::RunLoop run_loop_; - run_loop_.RunUntilIdle(); - - EXPECT_TRUE(themes_processor->IsConnected()); - DisableSync(); -} - -} // namespace syncer diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index a5f2de0..bf73315 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -28,13 +28,13 @@ #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_core_proxy.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_core.h" -#include "sync/internal_api/sync_core_proxy_impl.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" #include "sync/notifier/invalidation_util.h" @@ -390,15 +390,15 @@ void SyncManagerImpl::Init( model_type_registry_.reset(new ModelTypeRegistry(workers, directory())); - sync_core_.reset(new SyncCore(model_type_registry_.get())); + sync_context_.reset(new SyncContext(model_type_registry_.get())); - // Bind the SyncCore WeakPtr to this thread. This helps us crash earlier if - // the pointer is misused in debug mode. - base::WeakPtr<SyncCore> weak_core = sync_core_->AsWeakPtr(); + // 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(); weak_core.get(); - sync_core_proxy_.reset( - new SyncCoreProxyImpl(base::MessageLoopProxy::current(), weak_core)); + sync_context_proxy_.reset( + new SyncContextProxyImpl(base::MessageLoopProxy::current(), weak_core)); // Build a SyncSessionContext and store the worker in it. DVLOG(1) << "Sync is bringing up SyncSessionContext."; @@ -1022,9 +1022,9 @@ UserShare* SyncManagerImpl::GetUserShare() { return &share_; } -syncer::SyncCoreProxy* SyncManagerImpl::GetSyncCoreProxy() { +syncer::SyncContextProxy* SyncManagerImpl::GetSyncContextProxy() { DCHECK(initialized_); - return sync_core_proxy_.get(); + return sync_context_proxy_.get(); } const std::string SyncManagerImpl::cache_guid() { diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index dd6e191..2ca5fd6 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -20,7 +20,7 @@ #include "sync/internal_api/js_sync_manager_observer.h" #include "sync/internal_api/protocol_event_buffer.h" #include "sync/internal_api/public/base/invalidator_state.h" -#include "sync/internal_api/public/sync_core_proxy.h" +#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_manager.h" #include "sync/internal_api/public/user_share.h" #include "sync/internal_api/sync_encryption_handler_impl.h" @@ -34,7 +34,7 @@ namespace syncer { class ModelTypeRegistry; class SyncAPIServerConnectionManager; -class SyncCore; +class SyncContext; class TypeDebugInfoObserver; class WriteNode; class WriteTransaction; @@ -112,7 +112,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : virtual void SaveChanges() OVERRIDE; virtual void ShutdownOnSyncThread() OVERRIDE; virtual UserShare* GetUserShare() OVERRIDE; - virtual syncer::SyncCoreProxy* GetSyncCoreProxy() OVERRIDE; + virtual syncer::SyncContextProxy* GetSyncContextProxy() OVERRIDE; virtual const std::string cache_guid() OVERRIDE; virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; virtual bool HasUnsyncedItems() OVERRIDE; @@ -308,8 +308,8 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : scoped_ptr<ModelTypeRegistry> model_type_registry_; // The main interface for non-blocking sync types and a thread-safe wrapper. - scoped_ptr<SyncCore> sync_core_; - scoped_ptr<SyncCoreProxy> sync_core_proxy_; + scoped_ptr<SyncContext> sync_context_; + scoped_ptr<SyncContextProxy> sync_context_proxy_; // A container of various bits of information used by the SyncScheduler to // create SyncSessions. Must outlive the SyncScheduler. diff --git a/sync/internal_api/sync_rollback_manager_base.cc b/sync/internal_api/sync_rollback_manager_base.cc index ade0422..5ce7a80 100644 --- a/sync/internal_api/sync_rollback_manager_base.cc +++ b/sync/internal_api/sync_rollback_manager_base.cc @@ -234,7 +234,7 @@ std::string SyncRollbackManagerBase::GetOwnerName() const { return ""; } -syncer::SyncCoreProxy* SyncRollbackManagerBase::GetSyncCoreProxy() { +syncer::SyncContextProxy* SyncRollbackManagerBase::GetSyncContextProxy() { return NULL; } diff --git a/sync/internal_api/sync_rollback_manager_base.h b/sync/internal_api/sync_rollback_manager_base.h index 6b4153e..17892a8e 100644 --- a/sync/internal_api/sync_rollback_manager_base.h +++ b/sync/internal_api/sync_rollback_manager_base.h @@ -86,7 +86,7 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase : virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE; virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; virtual std::string GetOwnerName() const OVERRIDE; - virtual SyncCoreProxy* GetSyncCoreProxy() OVERRIDE; + virtual SyncContextProxy* GetSyncContextProxy() OVERRIDE; virtual ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() OVERRIDE; virtual scoped_ptr<base::ListValue> GetAllNodesForType( diff --git a/sync/internal_api/test/fake_sync_manager.cc b/sync/internal_api/test/fake_sync_manager.cc index 7526795..7b5e32f 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -214,8 +214,8 @@ UserShare* FakeSyncManager::GetUserShare() { return test_user_share_.user_share(); } -syncer::SyncCoreProxy* FakeSyncManager::GetSyncCoreProxy() { - return &null_sync_core_proxy_; +syncer::SyncContextProxy* FakeSyncManager::GetSyncContextProxy() { + return &null_sync_context_proxy_; } const std::string FakeSyncManager::cache_guid() { diff --git a/sync/internal_api/test/null_sync_context_proxy.cc b/sync/internal_api/test/null_sync_context_proxy.cc new file mode 100644 index 0000000..e209c21 --- /dev/null +++ b/sync/internal_api/test/null_sync_context_proxy.cc @@ -0,0 +1,30 @@ +// Copyright 2014 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/internal_api/public/test/null_sync_context_proxy.h" + +namespace syncer { + +NullSyncContextProxy::NullSyncContextProxy() { +} + +NullSyncContextProxy::~NullSyncContextProxy() { +} + +void NullSyncContextProxy::ConnectTypeToSync( + syncer::ModelType type, + const DataTypeState& data_type_state, + const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) { + NOTREACHED() << "NullSyncContextProxy is not meant to be used"; +} + +void NullSyncContextProxy::Disconnect(syncer::ModelType type) { + NOTREACHED() << "NullSyncContextProxy is not meant to be used"; +} + +scoped_ptr<SyncContextProxy> NullSyncContextProxy::Clone() const { + return scoped_ptr<SyncContextProxy>(new NullSyncContextProxy()); +} + +} // namespace syncer diff --git a/sync/internal_api/test/null_sync_core_proxy.cc b/sync/internal_api/test/null_sync_core_proxy.cc deleted file mode 100644 index 14d9d65..0000000 --- a/sync/internal_api/test/null_sync_core_proxy.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 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/internal_api/public/test/null_sync_core_proxy.h" - -namespace syncer { - -NullSyncCoreProxy::NullSyncCoreProxy() {} - -NullSyncCoreProxy::~NullSyncCoreProxy() {} - -void NullSyncCoreProxy::ConnectTypeToCore( - syncer::ModelType type, - const DataTypeState& data_type_state, - base::WeakPtr<NonBlockingTypeProcessor> processor) { - NOTREACHED() << "NullSyncCoreProxy is not meant to be used"; -} - -void NullSyncCoreProxy::Disconnect(syncer::ModelType type) { - NOTREACHED() << "NullSyncCoreProxy is not meant to be used"; -} - -scoped_ptr<SyncCoreProxy> NullSyncCoreProxy::Clone() const { - return scoped_ptr<SyncCoreProxy>(new NullSyncCoreProxy()); -} - -} // namespace syncer diff --git a/sync/sessions/model_type_registry.cc b/sync/sessions/model_type_registry.cc index 9ceac74..b8ab74b 100644 --- a/sync/sessions/model_type_registry.cc +++ b/sync/sessions/model_type_registry.cc @@ -9,24 +9,23 @@ #include "base/observer_list.h" #include "sync/engine/directory_commit_contributor.h" #include "sync/engine/directory_update_handler.h" +#include "sync/engine/model_type_sync_proxy.h" +#include "sync/engine/model_type_sync_proxy_impl.h" +#include "sync/engine/model_type_sync_worker.h" +#include "sync/engine/model_type_sync_worker_impl.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor.h" -#include "sync/engine/non_blocking_type_processor_core.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" -#include "sync/engine/non_blocking_type_processor_interface.h" #include "sync/sessions/directory_type_debug_info_emitter.h" namespace syncer { namespace { -class NonBlockingTypeProcessorWrapper - : public NonBlockingTypeProcessorInterface { +class ModelTypeSyncProxyWrapper : public ModelTypeSyncProxy { public: - NonBlockingTypeProcessorWrapper( - base::WeakPtr<NonBlockingTypeProcessor> processor, - scoped_refptr<base::SequencedTaskRunner> processor_task_runner); - virtual ~NonBlockingTypeProcessorWrapper(); + ModelTypeSyncProxyWrapper( + const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy, + const scoped_refptr<base::SequencedTaskRunner>& processor_task_runner); + virtual ~ModelTypeSyncProxyWrapper(); virtual void ReceiveCommitResponse( const DataTypeState& type_state, @@ -36,70 +35,69 @@ class NonBlockingTypeProcessorWrapper const UpdateResponseDataList& response_list) OVERRIDE; private: - base::WeakPtr<NonBlockingTypeProcessor> processor_; + base::WeakPtr<ModelTypeSyncProxyImpl> processor_; scoped_refptr<base::SequencedTaskRunner> processor_task_runner_; }; -NonBlockingTypeProcessorWrapper::NonBlockingTypeProcessorWrapper( - base::WeakPtr<NonBlockingTypeProcessor> processor, - scoped_refptr<base::SequencedTaskRunner> processor_task_runner) - : processor_(processor), processor_task_runner_(processor_task_runner) { +ModelTypeSyncProxyWrapper::ModelTypeSyncProxyWrapper( + const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy, + const scoped_refptr<base::SequencedTaskRunner>& processor_task_runner) + : processor_(proxy), processor_task_runner_(processor_task_runner) { } -NonBlockingTypeProcessorWrapper::~NonBlockingTypeProcessorWrapper() { +ModelTypeSyncProxyWrapper::~ModelTypeSyncProxyWrapper() { } -void NonBlockingTypeProcessorWrapper::ReceiveCommitResponse( +void ModelTypeSyncProxyWrapper::ReceiveCommitResponse( const DataTypeState& type_state, const CommitResponseDataList& response_list) { processor_task_runner_->PostTask( FROM_HERE, - base::Bind(&NonBlockingTypeProcessor::OnCommitCompletion, + base::Bind(&ModelTypeSyncProxyImpl::OnCommitCompletion, processor_, type_state, response_list)); } -void NonBlockingTypeProcessorWrapper::ReceiveUpdateResponse( +void ModelTypeSyncProxyWrapper::ReceiveUpdateResponse( const DataTypeState& type_state, const UpdateResponseDataList& response_list) { processor_task_runner_->PostTask( FROM_HERE, - base::Bind(&NonBlockingTypeProcessor::OnUpdateReceived, + base::Bind(&ModelTypeSyncProxyImpl::OnUpdateReceived, processor_, type_state, response_list)); } -class NonBlockingTypeProcessorCoreWrapper - : public NonBlockingTypeProcessorCoreInterface { +class ModelTypeSyncWorkerWrapper : public ModelTypeSyncWorker { public: - NonBlockingTypeProcessorCoreWrapper( - base::WeakPtr<NonBlockingTypeProcessorCore> core, - scoped_refptr<base::SequencedTaskRunner> sync_thread); - virtual ~NonBlockingTypeProcessorCoreWrapper(); + ModelTypeSyncWorkerWrapper( + const base::WeakPtr<ModelTypeSyncWorkerImpl>& worker, + const scoped_refptr<base::SequencedTaskRunner>& sync_thread); + virtual ~ModelTypeSyncWorkerWrapper(); virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE; private: - base::WeakPtr<NonBlockingTypeProcessorCore> core_; + base::WeakPtr<ModelTypeSyncWorkerImpl> worker_; scoped_refptr<base::SequencedTaskRunner> sync_thread_; }; -NonBlockingTypeProcessorCoreWrapper::NonBlockingTypeProcessorCoreWrapper( - base::WeakPtr<NonBlockingTypeProcessorCore> core, - scoped_refptr<base::SequencedTaskRunner> sync_thread) - : core_(core), sync_thread_(sync_thread) { +ModelTypeSyncWorkerWrapper::ModelTypeSyncWorkerWrapper( + const base::WeakPtr<ModelTypeSyncWorkerImpl>& worker, + const scoped_refptr<base::SequencedTaskRunner>& sync_thread) + : worker_(worker), sync_thread_(sync_thread) { } -NonBlockingTypeProcessorCoreWrapper::~NonBlockingTypeProcessorCoreWrapper() { +ModelTypeSyncWorkerWrapper::~ModelTypeSyncWorkerWrapper() { } -void NonBlockingTypeProcessorCoreWrapper::RequestCommits( +void ModelTypeSyncWorkerWrapper::RequestCommits( const CommitRequestDataList& list) { sync_thread_->PostTask( FROM_HERE, - base::Bind(&NonBlockingTypeProcessorCore::EnqueueForCommit, core_, list)); + base::Bind(&ModelTypeSyncWorkerImpl::EnqueueForCommit, worker_, list)); } } // namespace @@ -186,36 +184,34 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes( void ModelTypeRegistry::InitializeNonBlockingType( ModelType type, const DataTypeState& data_type_state, - scoped_refptr<base::SequencedTaskRunner> type_task_runner, - base::WeakPtr<NonBlockingTypeProcessor> processor) { + const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, + const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) { DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); - // Initialize CoreProcessor -> Processor communication channel. - scoped_ptr<NonBlockingTypeProcessorInterface> processor_interface( - new NonBlockingTypeProcessorWrapper(processor, type_task_runner)); - scoped_ptr<NonBlockingTypeProcessorCore> core( - new NonBlockingTypeProcessorCore( - type, data_type_state, processor_interface.Pass())); - - // Initialize Processor -> CoreProcessor communication channel. - scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface( - new NonBlockingTypeProcessorCoreWrapper( - core->AsWeakPtr(), - scoped_refptr<base::SequencedTaskRunner>( - base::MessageLoopProxy::current()))); + // Initialize Worker -> Proxy communication channel. + scoped_ptr<ModelTypeSyncProxy> proxy( + new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); + scoped_ptr<ModelTypeSyncWorkerImpl> worker( + new ModelTypeSyncWorkerImpl(type, data_type_state, proxy.Pass())); + + // Initialize Proxy -> Worker communication channel. + scoped_ptr<ModelTypeSyncWorker> wrapped_worker( + new ModelTypeSyncWorkerWrapper(worker->AsWeakPtr(), + scoped_refptr<base::SequencedTaskRunner>( + base::MessageLoopProxy::current()))); type_task_runner->PostTask(FROM_HERE, - base::Bind(&NonBlockingTypeProcessor::OnConnect, - processor, - base::Passed(&core_interface))); + base::Bind(&ModelTypeSyncProxyImpl::OnConnect, + proxy_impl, + base::Passed(&wrapped_worker))); DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); - update_handler_map_.insert(std::make_pair(type, core.get())); - commit_contributor_map_.insert(std::make_pair(type, core.get())); + update_handler_map_.insert(std::make_pair(type, worker.get())); + commit_contributor_map_.insert(std::make_pair(type, worker.get())); // The container takes ownership. - non_blocking_type_processor_cores_.push_back(core.release()); + model_type_sync_workers_.push_back(worker.release()); DCHECK(Intersection(GetEnabledDirectoryTypes(), GetEnabledNonBlockingTypes()).Empty()); @@ -232,12 +228,13 @@ void ModelTypeRegistry::RemoveNonBlockingType(ModelType type) { DCHECK_EQ(1U, updaters_erased); DCHECK_EQ(1U, committers_erased); - // Remove from the ScopedVector, deleting the core in the process. - for (ScopedVector<NonBlockingTypeProcessorCore>::iterator it = - non_blocking_type_processor_cores_.begin(); - it != non_blocking_type_processor_cores_.end(); ++it) { + // Remove from the ScopedVector, deleting the worker in the process. + for (ScopedVector<ModelTypeSyncWorkerImpl>::iterator it = + model_type_sync_workers_.begin(); + it != model_type_sync_workers_.end(); + ++it) { if ((*it)->GetModelType() == type) { - non_blocking_type_processor_cores_.erase(it); + model_type_sync_workers_.erase(it); break; } } @@ -292,9 +289,10 @@ ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { ModelTypeSet enabled_off_thread_types; - for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = - non_blocking_type_processor_cores_.begin(); - it != non_blocking_type_processor_cores_.end(); ++it) { + for (ScopedVector<ModelTypeSyncWorkerImpl>::const_iterator it = + model_type_sync_workers_.begin(); + it != model_type_sync_workers_.end(); + ++it) { enabled_off_thread_types.Put((*it)->GetModelType()); } return enabled_off_thread_types; diff --git a/sync/sessions/model_type_registry.h b/sync/sessions/model_type_registry.h index 6d05dfc..255a841 100644 --- a/sync/sessions/model_type_registry.h +++ b/sync/sessions/model_type_registry.h @@ -25,8 +25,8 @@ class CommitContributor; class DirectoryCommitContributor; class DirectoryUpdateHandler; class DirectoryTypeDebugInfoEmitter; -class NonBlockingTypeProcessorCore; -class NonBlockingTypeProcessor; +class ModelTypeSyncWorkerImpl; +class ModelTypeSyncProxyImpl; class UpdateHandler; struct DataTypeState; @@ -51,20 +51,20 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry { // Sets the set of enabled types. void SetEnabledDirectoryTypes(const ModelSafeRoutingInfo& routing_info); - // Enables an off-thread type for syncing. Connects the given processor - // and its task_runner to the newly created processor core. + // Enables an off-thread type for syncing. Connects the given proxy + // and its task_runner to the newly created worker. // - // Expects that the processor's ModelType is not currently enabled. + // Expects that the proxy's ModelType is not currently enabled. void InitializeNonBlockingType( syncer::ModelType type, const DataTypeState& data_type_state, - scoped_refptr<base::SequencedTaskRunner> type_task_runner, - base::WeakPtr<NonBlockingTypeProcessor> processor); + const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, + const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy); // Disables the syncing of an off-thread type. // // Expects that the type is currently enabled. - // Deletes the processor core associated with the type. + // Deletes the worker associated with the type. void RemoveNonBlockingType(syncer::ModelType type); // Gets the set of enabled types. @@ -93,7 +93,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry { ScopedVector<DirectoryTypeDebugInfoEmitter> directory_type_debug_info_emitters_; - ScopedVector<NonBlockingTypeProcessorCore> non_blocking_type_processor_cores_; + ScopedVector<ModelTypeSyncWorkerImpl> model_type_sync_workers_; // Maps of UpdateHandlers and CommitContributors. // They do not own any of the objects they point to. diff --git a/sync/sessions/model_type_registry_unittest.cc b/sync/sessions/model_type_registry_unittest.cc index 2d42215..d9d314e 100644 --- a/sync/sessions/model_type_registry_unittest.cc +++ b/sync/sessions/model_type_registry_unittest.cc @@ -6,7 +6,7 @@ #include "base/deferred_sequenced_task_runner.h" #include "base/message_loop/message_loop.h" -#include "sync/engine/non_blocking_type_processor.h" +#include "sync/engine/model_type_sync_proxy_impl.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" @@ -140,8 +140,8 @@ TEST_F(ModelTypeRegistryTest, SetEnabledDirectoryTypes_OffAndOn) { } TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { - NonBlockingTypeProcessor themes_processor(syncer::THEMES); - NonBlockingTypeProcessor sessions_processor(syncer::SESSIONS); + ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); + ModelTypeSyncProxyImpl sessions_sync_proxy(syncer::SESSIONS); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner(base::MessageLoopProxy::current()); @@ -150,14 +150,14 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { registry()->InitializeNonBlockingType(syncer::THEMES, MakeInitialDataTypeState(THEMES), task_runner, - themes_processor.AsWeakPtrForUI()); + themes_sync_proxy.AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( ModelTypeSet(syncer::THEMES))); registry()->InitializeNonBlockingType(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), task_runner, - sessions_processor.AsWeakPtrForUI()); + sessions_sync_proxy.AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( ModelTypeSet(syncer::THEMES, syncer::SESSIONS))); @@ -166,12 +166,12 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { ModelTypeSet(syncer::SESSIONS))); // Allow ModelTypeRegistry destruction to delete the - // Sessions' NonBlockingTypeProcessorCore. + // Sessions' ModelTypeSyncWorker. } TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { - NonBlockingTypeProcessor themes_processor(syncer::THEMES); - NonBlockingTypeProcessor sessions_processor(syncer::SESSIONS); + ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); + ModelTypeSyncProxyImpl sessions_sync_proxy(syncer::SESSIONS); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner(base::MessageLoopProxy::current()); @@ -187,7 +187,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { registry()->InitializeNonBlockingType(syncer::THEMES, MakeInitialDataTypeState(THEMES), task_runner, - themes_processor.AsWeakPtrForUI()); + themes_sync_proxy.AsWeakPtrForUI()); current_types.Put(syncer::THEMES); EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types)); @@ -200,7 +200,7 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { registry()->InitializeNonBlockingType(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), task_runner, - sessions_processor.AsWeakPtrForUI()); + sessions_sync_proxy.AsWeakPtrForUI()); current_types.Put(syncer::SESSIONS); EXPECT_TRUE(registry()->GetEnabledTypes().Equals(current_types)); @@ -217,10 +217,10 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { } TEST_F(ModelTypeRegistryTest, DeletionOrdering) { - scoped_ptr<NonBlockingTypeProcessor> themes_processor( - new NonBlockingTypeProcessor(syncer::THEMES)); - scoped_ptr<NonBlockingTypeProcessor> sessions_processor( - new NonBlockingTypeProcessor(syncer::SESSIONS)); + scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( + new ModelTypeSyncProxyImpl(syncer::THEMES)); + scoped_ptr<ModelTypeSyncProxyImpl> sessions_sync_proxy( + new ModelTypeSyncProxyImpl(syncer::SESSIONS)); scoped_refptr<base::DeferredSequencedTaskRunner> task_runner = new base::DeferredSequencedTaskRunner(base::MessageLoopProxy::current()); @@ -229,20 +229,20 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) { registry()->InitializeNonBlockingType(syncer::THEMES, MakeInitialDataTypeState(THEMES), task_runner, - themes_processor->AsWeakPtrForUI()); + themes_sync_proxy->AsWeakPtrForUI()); registry()->InitializeNonBlockingType(syncer::SESSIONS, MakeInitialDataTypeState(SESSIONS), task_runner, - sessions_processor->AsWeakPtrForUI()); + sessions_sync_proxy->AsWeakPtrForUI()); EXPECT_TRUE(registry()->GetEnabledTypes().Equals( ModelTypeSet(syncer::THEMES, syncer::SESSIONS))); - // Tear down themes processing, starting with the ProcessorCore. + // Tear down themes processing, starting with the worker. registry()->RemoveNonBlockingType(syncer::THEMES); - themes_processor.reset(); + themes_sync_proxy.reset(); - // Tear down sessions processing, starting with the Processor. - sessions_processor.reset(); + // Tear down sessions processing, starting with the type sync proxy. + sessions_sync_proxy.reset(); registry()->RemoveNonBlockingType(syncer::SESSIONS); EXPECT_TRUE(registry()->GetEnabledTypes().Empty()); diff --git a/sync/sync_core.gypi b/sync/sync_core.gypi index 8772d43..5205208 100644 --- a/sync/sync_core.gypi +++ b/sync/sync_core.gypi @@ -35,11 +35,11 @@ 'engine/backoff_delay_provider.cc', 'engine/backoff_delay_provider.h', 'engine/commit.cc', - 'engine/commit.h', 'engine/commit_contribution.cc', 'engine/commit_contribution.h', 'engine/commit_contributor.cc', 'engine/commit_contributor.h', + 'engine/commit.h', 'engine/commit_processor.cc', 'engine/commit_processor.h', 'engine/commit_util.cc', @@ -54,14 +54,24 @@ 'engine/directory_commit_contributor.h', 'engine/directory_update_handler.cc', 'engine/directory_update_handler.h', + 'engine/entity_tracker.cc', + 'engine/entity_tracker.h', 'engine/get_commit_ids.cc', 'engine/get_commit_ids.h', 'engine/get_updates_delegate.cc', 'engine/get_updates_delegate.h', 'engine/get_updates_processor.cc', 'engine/get_updates_processor.h', - 'engine/model_thread_sync_entity.cc', - 'engine/model_thread_sync_entity.h', + 'engine/model_type_entity.cc', + 'engine/model_type_entity.h', + 'engine/model_type_sync_proxy.cc', + 'engine/model_type_sync_proxy.h', + 'engine/model_type_sync_proxy_impl.cc', + 'engine/model_type_sync_proxy_impl.h', + 'engine/model_type_sync_worker.cc', + 'engine/model_type_sync_worker.h', + 'engine/model_type_sync_worker_impl.cc', + 'engine/model_type_sync_worker_impl.h', 'engine/net/server_connection_manager.cc', 'engine/net/server_connection_manager.h', 'engine/net/url_translator.cc', @@ -70,14 +80,6 @@ 'engine/non_blocking_sync_common.h', 'engine/non_blocking_type_commit_contribution.cc', 'engine/non_blocking_type_commit_contribution.h', - 'engine/non_blocking_type_processor.cc', - 'engine/non_blocking_type_processor.h', - 'engine/non_blocking_type_processor_core.cc', - 'engine/non_blocking_type_processor_core.h', - 'engine/non_blocking_type_processor_core_interface.cc', - 'engine/non_blocking_type_processor_core_interface.h', - 'engine/non_blocking_type_processor_interface.cc', - 'engine/non_blocking_type_processor_interface.h', 'engine/nudge_source.cc', 'engine/nudge_source.h', 'engine/process_updates_util.cc', @@ -86,12 +88,6 @@ 'engine/sync_cycle_event.h', 'engine/sync_engine_event_listener.cc', 'engine/sync_engine_event_listener.h', - 'engine/sync_scheduler.cc', - 'engine/sync_scheduler.h', - 'engine/sync_scheduler_impl.cc', - 'engine/sync_scheduler_impl.h', - 'engine/sync_thread_sync_entity.cc', - 'engine/sync_thread_sync_entity.h', 'engine/syncer.cc', 'engine/syncer.h', 'engine/syncer_proto_util.cc', @@ -99,6 +95,10 @@ 'engine/syncer_types.h', 'engine/syncer_util.cc', 'engine/syncer_util.h', + 'engine/sync_scheduler.cc', + 'engine/sync_scheduler.h', + 'engine/sync_scheduler_impl.cc', + 'engine/sync_scheduler_impl.h', 'engine/traffic_logger.cc', 'engine/traffic_logger.h', 'engine/update_applicator.cc', diff --git a/sync/sync_internal_api.gypi b/sync/sync_internal_api.gypi index f0ae375..fc49a48f 100644 --- a/sync/sync_internal_api.gypi +++ b/sync/sync_internal_api.gypi @@ -120,7 +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_core_proxy.h', + 'internal_api/public/sync_context_proxy.h', 'internal_api/public/sync_encryption_handler.cc', 'internal_api/public/sync_encryption_handler.h', 'internal_api/public/sync_manager.cc', @@ -145,20 +145,20 @@ 'internal_api/read_transaction.cc', 'internal_api/sync_backup_manager.cc', 'internal_api/sync_backup_manager.h', - 'internal_api/sync_core.cc', - 'internal_api/sync_core.h', - 'internal_api/sync_core_proxy.cc', - 'internal_api/sync_core_proxy_impl.cc', - 'internal_api/sync_core_proxy_impl.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', 'internal_api/sync_encryption_handler_impl.cc', 'internal_api/sync_encryption_handler_impl.h', 'internal_api/sync_manager_factory.cc', 'internal_api/sync_manager_impl.cc', 'internal_api/sync_manager_impl.h', - 'internal_api/sync_rollback_manager.cc', - 'internal_api/sync_rollback_manager.h', 'internal_api/sync_rollback_manager_base.cc', 'internal_api/sync_rollback_manager_base.h', + 'internal_api/sync_rollback_manager.cc', + 'internal_api/sync_rollback_manager.h', 'internal_api/syncapi_internal.cc', 'internal_api/syncapi_internal.h', 'internal_api/syncapi_server_connection_manager.cc', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index 6212dd4..5ba457b 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -38,12 +38,14 @@ 'test/engine/fake_model_worker.h', 'test/engine/fake_sync_scheduler.cc', 'test/engine/fake_sync_scheduler.h', + 'test/engine/injectable_sync_context_proxy.cc', + 'test/engine/injectable_sync_context_proxy.h', 'test/engine/mock_connection_manager.cc', 'test/engine/mock_connection_manager.h', - 'test/engine/mock_non_blocking_type_processor_core.cc', - 'test/engine/mock_non_blocking_type_processor_core.h', - 'test/engine/mock_non_blocking_type_processor.cc', - 'test/engine/mock_non_blocking_type_processor.h', + 'test/engine/mock_model_type_sync_proxy.cc', + 'test/engine/mock_model_type_sync_proxy.h', + 'test/engine/mock_model_type_sync_worker.cc', + 'test/engine/mock_model_type_sync_worker.h', 'test/engine/mock_update_handler.cc', 'test/engine/mock_update_handler.h', 'test/engine/single_type_mock_server.cc', @@ -53,8 +55,6 @@ 'test/engine/test_id_factory.h', 'test/engine/test_syncable_utils.cc', 'test/engine/test_syncable_utils.h', - 'test/engine/injectable_sync_core_proxy.cc', - 'test/engine/injectable_sync_core_proxy.h', 'test/fake_encryptor.cc', 'test/fake_encryptor.h', 'test/fake_sync_encryption_handler.cc', @@ -200,13 +200,13 @@ 'internal_api/public/base/invalidation_test_util.cc', 'internal_api/public/base/invalidation_test_util.h', 'internal_api/public/test/fake_sync_manager.h', - 'internal_api/public/test/null_sync_core_proxy.h', + 'internal_api/public/test/null_sync_context_proxy.h', 'internal_api/public/test/sync_manager_factory_for_profile_sync_test.h', 'internal_api/public/test/test_entry_factory.h', 'internal_api/public/test/test_internal_components_factory.h', 'internal_api/public/test/test_user_share.h', 'internal_api/test/fake_sync_manager.cc', - 'internal_api/test/null_sync_core_proxy.cc', + 'internal_api/test/null_sync_context_proxy.cc', 'internal_api/test/sync_manager_factory_for_profile_sync_test.cc', 'internal_api/test/sync_manager_for_profile_sync_test.cc', 'internal_api/test/sync_manager_for_profile_sync_test.h', @@ -298,12 +298,12 @@ 'engine/backoff_delay_provider_unittest.cc', 'engine/directory_commit_contribution_unittest.cc', 'engine/directory_update_handler_unittest.cc', + 'engine/entity_tracker_unittest.cc', 'engine/get_updates_processor_unittest.cc', - 'engine/model_thread_sync_entity_unittest.cc', - 'engine/non_blocking_type_processor_core_unittest.cc', - 'engine/non_blocking_type_processor_unittest.cc', + 'engine/model_type_entity_unittest.cc', + 'engine/model_type_sync_proxy_impl_unittest.cc', + 'engine/model_type_sync_worker_impl_unittest.cc', 'engine/sync_scheduler_unittest.cc', - 'engine/sync_thread_sync_entity_unittest.cc', 'engine/syncer_proto_util_unittest.cc', 'engine/syncer_unittest.cc', 'engine/syncer_util_unittest.cc', @@ -435,7 +435,7 @@ 'internal_api/public/change_record_unittest.cc', 'internal_api/public/sessions/sync_session_snapshot_unittest.cc', 'internal_api/sync_backup_manager_unittest.cc', - 'internal_api/sync_core_proxy_impl_unittest.cc', + 'internal_api/sync_context_proxy_impl_unittest.cc', 'internal_api/sync_encryption_handler_impl_unittest.cc', 'internal_api/sync_manager_impl_unittest.cc', 'internal_api/sync_rollback_manager_base_unittest.cc', diff --git a/sync/test/engine/injectable_sync_context_proxy.cc b/sync/test/engine/injectable_sync_context_proxy.cc new file mode 100644 index 0000000..27de880 --- /dev/null +++ b/sync/test/engine/injectable_sync_context_proxy.cc @@ -0,0 +1,49 @@ +// Copyright 2014 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/test/engine/injectable_sync_context_proxy.h" + +#include "sync/engine/model_type_sync_proxy_impl.h" +#include "sync/engine/model_type_sync_worker.h" + +namespace syncer { + +InjectableSyncContextProxy::InjectableSyncContextProxy( + ModelTypeSyncWorker* worker) + : is_worker_connected_(false), worker_(worker) { +} + +InjectableSyncContextProxy::~InjectableSyncContextProxy() { +} + +void InjectableSyncContextProxy::ConnectTypeToSync( + syncer::ModelType type, + const DataTypeState& data_type_state, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) { + // This class is allowed to participate in only one connection. + DCHECK(!is_worker_connected_); + is_worker_connected_ = true; + + // Hands off ownership of our member to the type_sync_proxy, while keeping + // an unsafe pointer to it. This is why we can only connect once. + scoped_ptr<ModelTypeSyncWorker> worker(worker_); + + type_sync_proxy->OnConnect(worker.Pass()); +} + +void InjectableSyncContextProxy::Disconnect(syncer::ModelType type) { + // This should delete the worker, but we don't own it. + worker_ = NULL; +} + +scoped_ptr<SyncContextProxy> InjectableSyncContextProxy::Clone() const { + // This confuses ownership. We trust that our callers are well-behaved. + return scoped_ptr<SyncContextProxy>(new InjectableSyncContextProxy(worker_)); +} + +ModelTypeSyncWorker* InjectableSyncContextProxy::GetWorker() { + return worker_; +} + +} // namespace syncer diff --git a/sync/test/engine/injectable_sync_context_proxy.h b/sync/test/engine/injectable_sync_context_proxy.h new file mode 100644 index 0000000..7c9f48d --- /dev/null +++ b/sync/test/engine/injectable_sync_context_proxy.h @@ -0,0 +1,48 @@ +// Copyright 2014 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_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ +#define SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ + +#include "sync/internal_api/public/base/model_type.h" +#include "sync/internal_api/public/sync_context_proxy.h" + +namespace syncer { + +struct DataTypeState; +class ModelTypeSyncProxyImpl; +class ModelTypeSyncWorker; + +// A SyncContextProxy implementation that, when a connection request is made, +// initalizes a connection to a previously injected ModelTypeSyncProxyImpl. +class InjectableSyncContextProxy : public syncer::SyncContextProxy { + public: + explicit InjectableSyncContextProxy(ModelTypeSyncWorker* worker); + virtual ~InjectableSyncContextProxy(); + + virtual void ConnectTypeToSync( + syncer::ModelType type, + const DataTypeState& data_type_state, + const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) + OVERRIDE; + virtual void Disconnect(syncer::ModelType type) OVERRIDE; + virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE; + + ModelTypeSyncWorker* GetWorker(); + + private: + // A flag to ensure ConnectTypeToSync is called at most once. + bool is_worker_connected_; + + // The ModelTypeSyncProxy's contract expects that it gets to own this object, + // so we can retain only a non-owned pointer to it. + // + // This is very unsafe, but we can get away with it since these tests are not + // exercising the proxy <-> worker connection code. + ModelTypeSyncWorker* worker_; +}; + +} // namespace syncer + +#endif // SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ diff --git a/sync/test/engine/injectable_sync_core_proxy.cc b/sync/test/engine/injectable_sync_core_proxy.cc deleted file mode 100644 index 4041736..0000000 --- a/sync/test/engine/injectable_sync_core_proxy.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 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/test/engine/injectable_sync_core_proxy.h" - -#include "sync/engine/non_blocking_type_processor.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" - -namespace syncer { - -InjectableSyncCoreProxy::InjectableSyncCoreProxy( - NonBlockingTypeProcessorCoreInterface* core) - : is_core_connected_(false), processor_core_(core) { -} - -InjectableSyncCoreProxy::~InjectableSyncCoreProxy() { -} - -void InjectableSyncCoreProxy::ConnectTypeToCore( - syncer::ModelType type, - const DataTypeState& data_type_state, - base::WeakPtr<syncer::NonBlockingTypeProcessor> type_processor) { - // This class is allowed to participate in only one connection. - DCHECK(!is_core_connected_); - is_core_connected_ = true; - - // Hands off ownership of our member to the type_processor, while keeping - // an unsafe pointer to it. This is why we can only connect once. - scoped_ptr<NonBlockingTypeProcessorCoreInterface> core(processor_core_); - - type_processor->OnConnect(core.Pass()); -} - -void InjectableSyncCoreProxy::Disconnect(syncer::ModelType type) { - // This should delete the core, but we don't own it. - processor_core_ = NULL; -} - -scoped_ptr<SyncCoreProxy> InjectableSyncCoreProxy::Clone() const { - // This confuses ownership. We trust that our callers are well-behaved. - return scoped_ptr<SyncCoreProxy>( - new InjectableSyncCoreProxy(processor_core_)); -} - -NonBlockingTypeProcessorCoreInterface* -InjectableSyncCoreProxy::GetProcessorCore() { - return processor_core_; -} - -} // namespace syncer diff --git a/sync/test/engine/injectable_sync_core_proxy.h b/sync/test/engine/injectable_sync_core_proxy.h deleted file mode 100644 index 2dc273d..0000000 --- a/sync/test/engine/injectable_sync_core_proxy.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 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_TEST_ENGINE_INJECTABLE_SYNC_CORE_PROXY_H_ -#define SYNC_TEST_ENGINE_INJECTABLE_SYNC_CORE_PROXY_H_ - -#include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/sync_core_proxy.h" - -namespace syncer { - -struct DataTypeState; -class NonBlockingTypeProcessor; -class NonBlockingTypeProcessorCoreInterface; - -// A SyncCoreProxy implementation that, when a connection request is made, -// initalizes a connection to a previously injected NonBlockingTypeProcessor. -class InjectableSyncCoreProxy : public syncer::SyncCoreProxy { - public: - explicit InjectableSyncCoreProxy(NonBlockingTypeProcessorCoreInterface* core); - virtual ~InjectableSyncCoreProxy(); - - virtual void ConnectTypeToCore( - syncer::ModelType type, - const DataTypeState& data_type_state, - base::WeakPtr<syncer::NonBlockingTypeProcessor> type_processor) OVERRIDE; - virtual void Disconnect(syncer::ModelType type) OVERRIDE; - virtual scoped_ptr<SyncCoreProxy> Clone() const OVERRIDE; - - NonBlockingTypeProcessorCoreInterface* GetProcessorCore(); - - private: - // A flag to ensure ConnectTypeToCore is called at most once. - bool is_core_connected_; - - // The NonBlockingTypeProcessor's contract expects that it gets to own this - // object, so we can retain only a non-owned pointer to it. - // - // This is very unsafe, but we can get away with it since these tests are not - // exercising the processor <-> processor_core connection code. - NonBlockingTypeProcessorCoreInterface* processor_core_; -}; - -} // namespace syncer - -#endif // SYNC_TEST_ENGINE_INJECTABLE_SYNC_CORE_PROXY_H_ diff --git a/sync/test/engine/mock_non_blocking_type_processor.cc b/sync/test/engine/mock_model_type_sync_proxy.cc index 0c3d8c9..440269d 100644 --- a/sync/test/engine/mock_non_blocking_type_processor.cc +++ b/sync/test/engine/mock_model_type_sync_proxy.cc @@ -2,24 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/test/engine/mock_non_blocking_type_processor.h" +#include "sync/test/engine/mock_model_type_sync_proxy.h" #include "base/bind.h" namespace syncer { -MockNonBlockingTypeProcessor::MockNonBlockingTypeProcessor() - : is_synchronous_(true) { +MockModelTypeSyncProxy::MockModelTypeSyncProxy() : is_synchronous_(true) { } -MockNonBlockingTypeProcessor::~MockNonBlockingTypeProcessor() { +MockModelTypeSyncProxy::~MockModelTypeSyncProxy() { } -void MockNonBlockingTypeProcessor::ReceiveCommitResponse( +void MockModelTypeSyncProxy::ReceiveCommitResponse( const DataTypeState& type_state, const CommitResponseDataList& response_list) { base::Closure task = - base::Bind(&MockNonBlockingTypeProcessor::ReceiveCommitResponseImpl, + base::Bind(&MockModelTypeSyncProxy::ReceiveCommitResponseImpl, base::Unretained(this), type_state, response_list); @@ -28,11 +27,11 @@ void MockNonBlockingTypeProcessor::ReceiveCommitResponse( RunQueuedTasks(); } -void MockNonBlockingTypeProcessor::ReceiveUpdateResponse( +void MockModelTypeSyncProxy::ReceiveUpdateResponse( const DataTypeState& type_state, const UpdateResponseDataList& response_list) { base::Closure task = - base::Bind(&MockNonBlockingTypeProcessor::ReceiveUpdateResponseImpl, + base::Bind(&MockModelTypeSyncProxy::ReceiveUpdateResponseImpl, base::Unretained(this), type_state, response_list); @@ -41,12 +40,11 @@ void MockNonBlockingTypeProcessor::ReceiveUpdateResponse( RunQueuedTasks(); } -void MockNonBlockingTypeProcessor::SetSynchronousExecution( - bool is_synchronous) { +void MockModelTypeSyncProxy::SetSynchronousExecution(bool is_synchronous) { is_synchronous_ = is_synchronous; } -void MockNonBlockingTypeProcessor::RunQueuedTasks() { +void MockModelTypeSyncProxy::RunQueuedTasks() { for (std::vector<base::Closure>::iterator it = pending_tasks_.begin(); it != pending_tasks_.end(); ++it) { @@ -55,7 +53,7 @@ void MockNonBlockingTypeProcessor::RunQueuedTasks() { pending_tasks_.clear(); } -CommitRequestData MockNonBlockingTypeProcessor::CommitRequest( +CommitRequestData MockModelTypeSyncProxy::CommitRequest( const std::string& tag_hash, const sync_pb::EntitySpecifics& specifics) { const int64 base_version = GetBaseVersion(tag_hash); @@ -81,7 +79,7 @@ CommitRequestData MockNonBlockingTypeProcessor::CommitRequest( return data; } -CommitRequestData MockNonBlockingTypeProcessor::DeleteRequest( +CommitRequestData MockModelTypeSyncProxy::DeleteRequest( const std::string& tag_hash) { const int64 base_version = GetBaseVersion(tag_hash); CommitRequestData data; @@ -104,48 +102,46 @@ CommitRequestData MockNonBlockingTypeProcessor::DeleteRequest( return data; } -size_t MockNonBlockingTypeProcessor::GetNumUpdateResponses() const { +size_t MockModelTypeSyncProxy::GetNumUpdateResponses() const { return received_update_responses_.size(); } -UpdateResponseDataList MockNonBlockingTypeProcessor::GetNthUpdateResponse( +UpdateResponseDataList MockModelTypeSyncProxy::GetNthUpdateResponse( size_t n) const { DCHECK_LT(n, GetNumUpdateResponses()); return received_update_responses_[n]; } -DataTypeState -MockNonBlockingTypeProcessor::GetNthTypeStateReceivedInUpdateResponse( +DataTypeState MockModelTypeSyncProxy::GetNthTypeStateReceivedInUpdateResponse( size_t n) const { DCHECK_LT(n, GetNumUpdateResponses()); return type_states_received_on_update_[n]; } -size_t MockNonBlockingTypeProcessor::GetNumCommitResponses() const { +size_t MockModelTypeSyncProxy::GetNumCommitResponses() const { return received_commit_responses_.size(); } -CommitResponseDataList MockNonBlockingTypeProcessor::GetNthCommitResponse( +CommitResponseDataList MockModelTypeSyncProxy::GetNthCommitResponse( size_t n) const { DCHECK_LT(n, GetNumCommitResponses()); return received_commit_responses_[n]; } -DataTypeState -MockNonBlockingTypeProcessor::GetNthTypeStateReceivedInCommitResponse( +DataTypeState MockModelTypeSyncProxy::GetNthTypeStateReceivedInCommitResponse( size_t n) const { DCHECK_LT(n, GetNumCommitResponses()); return type_states_received_on_commit_[n]; } -bool MockNonBlockingTypeProcessor::HasUpdateResponse( +bool MockModelTypeSyncProxy::HasUpdateResponse( const std::string& tag_hash) const { std::map<const std::string, UpdateResponseData>::const_iterator it = update_response_items_.find(tag_hash); return it != update_response_items_.end(); } -UpdateResponseData MockNonBlockingTypeProcessor::GetUpdateResponse( +UpdateResponseData MockModelTypeSyncProxy::GetUpdateResponse( const std::string& tag_hash) const { DCHECK(HasUpdateResponse(tag_hash)); std::map<const std::string, UpdateResponseData>::const_iterator it = @@ -153,14 +149,14 @@ UpdateResponseData MockNonBlockingTypeProcessor::GetUpdateResponse( return it->second; } -bool MockNonBlockingTypeProcessor::HasCommitResponse( +bool MockModelTypeSyncProxy::HasCommitResponse( const std::string& tag_hash) const { std::map<const std::string, CommitResponseData>::const_iterator it = commit_response_items_.find(tag_hash); return it != commit_response_items_.end(); } -CommitResponseData MockNonBlockingTypeProcessor::GetCommitResponse( +CommitResponseData MockModelTypeSyncProxy::GetCommitResponse( const std::string& tag_hash) const { DCHECK(HasCommitResponse(tag_hash)); std::map<const std::string, CommitResponseData>::const_iterator it = @@ -168,7 +164,7 @@ CommitResponseData MockNonBlockingTypeProcessor::GetCommitResponse( return it->second; } -void MockNonBlockingTypeProcessor::ReceiveCommitResponseImpl( +void MockModelTypeSyncProxy::ReceiveCommitResponseImpl( const DataTypeState& type_state, const CommitResponseDataList& response_list) { received_commit_responses_.push_back(response_list); @@ -184,7 +180,7 @@ void MockNonBlockingTypeProcessor::ReceiveCommitResponseImpl( } } -void MockNonBlockingTypeProcessor::ReceiveUpdateResponseImpl( +void MockModelTypeSyncProxy::ReceiveUpdateResponseImpl( const DataTypeState& type_state, const UpdateResponseDataList& response_list) { received_update_responses_.push_back(response_list); @@ -201,7 +197,7 @@ void MockNonBlockingTypeProcessor::ReceiveUpdateResponseImpl( } // Fetches the sequence number as of the most recent update request. -int64 MockNonBlockingTypeProcessor::GetCurrentSequenceNumber( +int64 MockModelTypeSyncProxy::GetCurrentSequenceNumber( const std::string& tag_hash) const { std::map<const std::string, int64>::const_iterator it = sequence_numbers_.find(tag_hash); @@ -214,7 +210,7 @@ int64 MockNonBlockingTypeProcessor::GetCurrentSequenceNumber( // The model thread should be sending us items with strictly increasing // sequence numbers. Here's where we emulate that behavior. -int64 MockNonBlockingTypeProcessor::GetNextSequenceNumber( +int64 MockModelTypeSyncProxy::GetNextSequenceNumber( const std::string& tag_hash) { int64 sequence_number = GetCurrentSequenceNumber(tag_hash); sequence_number++; @@ -222,7 +218,7 @@ int64 MockNonBlockingTypeProcessor::GetNextSequenceNumber( return sequence_number; } -int64 MockNonBlockingTypeProcessor::GetBaseVersion( +int64 MockModelTypeSyncProxy::GetBaseVersion( const std::string& tag_hash) const { std::map<const std::string, int64>::const_iterator it = base_versions_.find(tag_hash); @@ -233,25 +229,24 @@ int64 MockNonBlockingTypeProcessor::GetBaseVersion( } } -void MockNonBlockingTypeProcessor::SetBaseVersion(const std::string& tag_hash, - int64 version) { +void MockModelTypeSyncProxy::SetBaseVersion(const std::string& tag_hash, + int64 version) { base_versions_[tag_hash] = version; } -bool MockNonBlockingTypeProcessor::HasServerAssignedId( +bool MockModelTypeSyncProxy::HasServerAssignedId( const std::string& tag_hash) const { return assigned_ids_.find(tag_hash) != assigned_ids_.end(); } -const std::string& MockNonBlockingTypeProcessor::GetServerAssignedId( +const std::string& MockModelTypeSyncProxy::GetServerAssignedId( const std::string& tag_hash) const { DCHECK(HasServerAssignedId(tag_hash)); return assigned_ids_.find(tag_hash)->second; } -void MockNonBlockingTypeProcessor::SetServerAssignedId( - const std::string& tag_hash, - const std::string& id) { +void MockModelTypeSyncProxy::SetServerAssignedId(const std::string& tag_hash, + const std::string& id) { assigned_ids_[tag_hash] = id; } diff --git a/sync/test/engine/mock_non_blocking_type_processor.h b/sync/test/engine/mock_model_type_sync_proxy.h index 30e7670..54283d0 100644 --- a/sync/test/engine/mock_non_blocking_type_processor.h +++ b/sync/test/engine/mock_model_type_sync_proxy.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_H_ -#define SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_H_ +#ifndef SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_PROXY_H_ +#define SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_PROXY_H_ #include <vector> #include "base/callback.h" #include "base/macros.h" +#include "sync/engine/model_type_sync_proxy.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor_interface.h" namespace syncer { -// Mocks the NonBlockingTypeProcessor. +// Mocks the ModelTypeSyncProxy. // // This mock is made simpler by not using any threads. It does still have the // ability to defer execution if we need to test race conditions, though. @@ -25,12 +25,12 @@ namespace syncer { // // It keeps a log of all received messages so tests can make assertions based // on their value. -class MockNonBlockingTypeProcessor : public NonBlockingTypeProcessorInterface { +class MockModelTypeSyncProxy : public ModelTypeSyncProxy { public: - MockNonBlockingTypeProcessor(); - virtual ~MockNonBlockingTypeProcessor(); + MockModelTypeSyncProxy(); + virtual ~MockModelTypeSyncProxy(); - // Implementation of NonBlockingTypeProcessorInterface. + // Implementation of ModelTypeSyncProxy. virtual void ReceiveCommitResponse( const DataTypeState& type_state, const CommitResponseDataList& response_list) OVERRIDE; @@ -52,8 +52,8 @@ class MockNonBlockingTypeProcessor : public NonBlockingTypeProcessorInterface { // Generate commit or deletion requests to be sent to the server. // These functions update local state to keep sequence numbers consistent. // - // A real NonBlockingTypeProcessor would forward these kinds of messages - // directly to its attached NonBlockingTypeProcessorCore. These methods + // A real ModelTypeSyncProxy would forward these kinds of messages + // directly to its attached ModelTypeSyncWorker. These methods // return the value to the caller so the test framework can handle them as it // sees fit. CommitRequestData CommitRequest(const std::string& tag_hash, @@ -128,9 +128,9 @@ class MockNonBlockingTypeProcessor : public NonBlockingTypeProcessorInterface { std::map<const std::string, int64> base_versions_; std::map<const std::string, std::string> assigned_ids_; - DISALLOW_COPY_AND_ASSIGN(MockNonBlockingTypeProcessor); + DISALLOW_COPY_AND_ASSIGN(MockModelTypeSyncProxy); }; } // namespace syncer -#endif // SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_H_ +#endif // SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_PROXY_H_ diff --git a/sync/test/engine/mock_non_blocking_type_processor_core.cc b/sync/test/engine/mock_model_type_sync_worker.cc index b164c2a..66c8242 100644 --- a/sync/test/engine/mock_non_blocking_type_processor_core.cc +++ b/sync/test/engine/mock_model_type_sync_worker.cc @@ -2,34 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/test/engine/mock_non_blocking_type_processor_core.h" +#include "sync/test/engine/mock_model_type_sync_worker.h" #include "base/logging.h" namespace syncer { -MockNonBlockingTypeProcessorCore::MockNonBlockingTypeProcessorCore() { +MockModelTypeSyncWorker::MockModelTypeSyncWorker() { } -MockNonBlockingTypeProcessorCore::~MockNonBlockingTypeProcessorCore() { +MockModelTypeSyncWorker::~MockModelTypeSyncWorker() { } -void MockNonBlockingTypeProcessorCore::RequestCommits( +void MockModelTypeSyncWorker::RequestCommits( const CommitRequestDataList& list) { commit_request_lists_.push_back(list); } -size_t MockNonBlockingTypeProcessorCore::GetNumCommitRequestLists() const { +size_t MockModelTypeSyncWorker::GetNumCommitRequestLists() const { return commit_request_lists_.size(); } -CommitRequestDataList MockNonBlockingTypeProcessorCore::GetNthCommitRequestList( +CommitRequestDataList MockModelTypeSyncWorker::GetNthCommitRequestList( size_t n) const { DCHECK_LT(n, GetNumCommitRequestLists()); return commit_request_lists_[n]; } -bool MockNonBlockingTypeProcessorCore::HasCommitRequestForTagHash( +bool MockModelTypeSyncWorker::HasCommitRequestForTagHash( const std::string& tag_hash) const { // Iterate backward through the sets of commit requests to find the most // recent one that applies to the specified tag_hash. @@ -49,8 +49,7 @@ bool MockNonBlockingTypeProcessorCore::HasCommitRequestForTagHash( return false; } -CommitRequestData -MockNonBlockingTypeProcessorCore::GetLatestCommitRequestForTagHash( +CommitRequestData MockModelTypeSyncWorker::GetLatestCommitRequestForTagHash( const std::string& tag_hash) const { // Iterate backward through the sets of commit requests to find the most // recent one that applies to the specified tag_hash. @@ -71,7 +70,7 @@ MockNonBlockingTypeProcessorCore::GetLatestCommitRequestForTagHash( return CommitRequestData(); } -UpdateResponseData MockNonBlockingTypeProcessorCore::UpdateFromServer( +UpdateResponseData MockModelTypeSyncWorker::UpdateFromServer( int64 version_offset, const std::string& tag_hash, const sync_pb::EntitySpecifics& specifics) { @@ -98,7 +97,7 @@ UpdateResponseData MockNonBlockingTypeProcessorCore::UpdateFromServer( return data; } -UpdateResponseData MockNonBlockingTypeProcessorCore::TombstoneFromServer( +UpdateResponseData MockModelTypeSyncWorker::TombstoneFromServer( int64 version_offset, const std::string& tag_hash) { int64 old_version = GetServerVersion(tag_hash); @@ -122,7 +121,7 @@ UpdateResponseData MockNonBlockingTypeProcessorCore::TombstoneFromServer( return data; } -CommitResponseData MockNonBlockingTypeProcessorCore::SuccessfulCommitResponse( +CommitResponseData MockModelTypeSyncWorker::SuccessfulCommitResponse( const CommitRequestData& request_data) { const std::string& client_tag_hash = request_data.client_tag_hash; @@ -150,13 +149,11 @@ CommitResponseData MockNonBlockingTypeProcessorCore::SuccessfulCommitResponse( return response_data; } -std::string MockNonBlockingTypeProcessorCore::GenerateId( - const std::string& tag_hash) { +std::string MockModelTypeSyncWorker::GenerateId(const std::string& tag_hash) { return "FakeId:" + tag_hash; } -int64 MockNonBlockingTypeProcessorCore::GetServerVersion( - const std::string& tag_hash) { +int64 MockModelTypeSyncWorker::GetServerVersion(const std::string& tag_hash) { std::map<const std::string, int64>::const_iterator it; it = server_versions_.find(tag_hash); if (it == server_versions_.end()) { @@ -166,9 +163,8 @@ int64 MockNonBlockingTypeProcessorCore::GetServerVersion( } } -void MockNonBlockingTypeProcessorCore::SetServerVersion( - const std::string& tag_hash, - int64 version) { +void MockModelTypeSyncWorker::SetServerVersion(const std::string& tag_hash, + int64 version) { server_versions_[tag_hash] = version; } diff --git a/sync/test/engine/mock_non_blocking_type_processor_core.h b/sync/test/engine/mock_model_type_sync_worker.h index 2ee73a4..deb675e9 100644 --- a/sync/test/engine/mock_non_blocking_type_processor_core.h +++ b/sync/test/engine/mock_model_type_sync_worker.h @@ -2,30 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ -#define SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ +#ifndef SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_WORKER_H_ +#define SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_WORKER_H_ #include <vector> #include "base/macros.h" +#include "sync/engine/model_type_sync_worker.h" #include "sync/engine/non_blocking_sync_common.h" -#include "sync/engine/non_blocking_type_processor_core_interface.h" namespace syncer { -// Receives and records commit requests sent through the -// NonBlockingTypeProcessorCoreInterface. +// Receives and records commit requests sent through the ModelTypeSyncWorker. // // This class also includes features intended to help mock out server behavior. // It has some basic functionality to keep track of server state and generate // plausible UpdateResponseData and CommitResponseData messages. -class MockNonBlockingTypeProcessorCore - : public NonBlockingTypeProcessorCoreInterface { +class MockModelTypeSyncWorker : public ModelTypeSyncWorker { public: - MockNonBlockingTypeProcessorCore(); - virtual ~MockNonBlockingTypeProcessorCore(); + MockModelTypeSyncWorker(); + virtual ~MockModelTypeSyncWorker(); - // Implementation of NonBlockingTypeProcessorCoreInterface. + // Implementation of ModelTypeSyncWorker. virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE; // Getters to inspect the requests sent to this object. @@ -36,7 +34,7 @@ class MockNonBlockingTypeProcessorCore const std::string& tag_hash) const; // Functions to produce state as though it came from a real server and had - // been filtered through a real NonBlockinTypeProcessorCore. + // been filtered through a real ModelTypeSyncWorker. // Returns an UpdateResponseData representing an update received from // the server. Updates server state accordingly. @@ -74,9 +72,9 @@ class MockNonBlockingTypeProcessorCore // This is an essential part of the mocked server state. std::map<const std::string, int64> server_versions_; - DISALLOW_COPY_AND_ASSIGN(MockNonBlockingTypeProcessorCore); + DISALLOW_COPY_AND_ASSIGN(MockModelTypeSyncWorker); }; } // namespace syncer -#endif // SYNC_TEST_ENGINE_MOCK_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ +#endif // SYNC_TEST_ENGINE_MOCK_MODEL_TYPE_SYNC_WORKER_H_ |