Chromium Code Reviews| Index: sync/engine/non_blocking_type_processor_core.h |
| diff --git a/sync/engine/non_blocking_type_processor_core.h b/sync/engine/non_blocking_type_processor_core.h |
| index e2263499562f82fe9515b0455ee40b79ac155636..9f3f34d74af8acccc1d99d1bd4248c18c50472e9 100644 |
| --- a/sync/engine/non_blocking_type_processor_core.h |
| +++ b/sync/engine/non_blocking_type_processor_core.h |
| @@ -6,6 +6,7 @@ |
| #define SYNC_ENGINE_NON_BLOCKING_TYPE_PROCESSOR_CORE_H_ |
| #include "base/memory/weak_ptr.h" |
| +#include "base/stl_util.h" |
| #include "base/threading/non_thread_safe.h" |
| #include "sync/base/sync_export.h" |
| #include "sync/engine/commit_contributor.h" |
| @@ -20,7 +21,8 @@ class SingleThreadTaskRunner; |
| namespace syncer { |
| -class NonBlockingTypeProcessor; |
| +class NonBlockingTypeProcessorInterface; |
| +class SyncThreadSyncEntity; |
| // A smart cache for sync types that use message passing (rather than |
| // transactions and the syncable::Directory) to communicate with the sync |
| @@ -28,9 +30,9 @@ class NonBlockingTypeProcessor; |
| // |
| // When the non-blocking sync type wants to talk with the sync server, it will |
| // send a message from its thread to this object on the sync thread. This |
| -// object is responsible for helping to ensure the appropriate sync server |
| -// communication gets scheduled and executed. The response, if any, will be |
| -// returned to the non-blocking sync type's thread eventually. |
| +// object ensures the appropriate sync server communication gets scheduled and |
| +// executed. The response, if any, will be returned to the non-blocking sync |
| +// type's thread eventually. |
| // |
| // This object also has a role to play in communications in the opposite |
| // direction. Sometimes the sync thread will receive changes from the sync |
| @@ -49,8 +51,8 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore |
| public: |
| NonBlockingTypeProcessorCore( |
| ModelType type, |
| - scoped_refptr<base::SequencedTaskRunner> processor_task_runner, |
| - base::WeakPtr<NonBlockingTypeProcessor> processor); |
| + const DataTypeState& initial_state, |
| + scoped_ptr<NonBlockingTypeProcessorInterface> processor_interface); |
| virtual ~NonBlockingTypeProcessorCore(); |
| ModelType GetModelType() const; |
| @@ -69,20 +71,47 @@ class SYNC_EXPORT NonBlockingTypeProcessorCore |
| virtual void PassiveApplyUpdates(sessions::StatusController* status) OVERRIDE; |
| // Entry point for NonBlockingTypeProcessor to send commit requests. |
| - void RequestCommits(const CommitRequestDataList& request_list); |
| + void EnqueueForCommit(const CommitRequestDataList& request_list); |
| // CommitContributor implementation. |
| virtual scoped_ptr<CommitContribution> GetContribution( |
| size_t max_entries) OVERRIDE; |
| + // Callback for when our contribution gets a response. |
| + void OnCommitResponse(const CommitResponseDataList& response_list); |
| + |
| base::WeakPtr<NonBlockingTypeProcessorCore> AsWeakPtr(); |
| private: |
| + typedef std::map<std::string, SyncThreadSyncEntity*> EntityMap; |
| + |
| + // Stores a single commit request in this object's internal state. |
| + void StorePendingCommit(const CommitRequestData& request); |
| + |
| + // Returns true if this object has access to enough state that it |
| + // can commit items. This will be false until the initial update |
| + // fetch is complete. |
|
Nicolas Zea
2014/06/02 20:27:17
Nit: I find "access to enough state" confusing. Ho
rlarocque
2014/06/02 21:39:14
Rewrote comment.
|
| + 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 |
| + // 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); |
| + |
| ModelType type_; |
| - sync_pb::DataTypeProgressMarker progress_marker_; |
| - scoped_refptr<base::SequencedTaskRunner> processor_task_runner_; |
| - base::WeakPtr<NonBlockingTypeProcessor> processor_; |
| + // 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_; |
| + |
| + // A map of per-entity information known to this object. |
| + EntityMap entities_; |
| + STLValueDeleter<EntityMap> entities_deleter_; |
| base::WeakPtrFactory<NonBlockingTypeProcessorCore> weak_ptr_factory_; |
| }; |