Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Unified Diff: components/sync/driver/non_ui_data_type_controller.h

Issue 2511703004: [Sync] Remove UIDataTypeController (Closed)
Patch Set: Rebase. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync/driver/non_ui_data_type_controller.h
diff --git a/components/sync/driver/non_ui_data_type_controller.h b/components/sync/driver/non_ui_data_type_controller.h
index 9e205db1d1fb98d721bf690c33111be2bc2168ee..e7ecc24a9f3d2376386c349eebf75e2e757787c6 100644
--- a/components/sync/driver/non_ui_data_type_controller.h
+++ b/components/sync/driver/non_ui_data_type_controller.h
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "base/sequenced_task_runner.h"
#include "components/sync/driver/directory_data_type_controller.h"
#include "components/sync/driver/shared_change_processor.h"
@@ -19,23 +20,34 @@ namespace syncer {
class SyncClient;
struct UserShare;
+// Implementation for datatypes that reside on non-UI thread. All interaction
+// with datatype controller happens on UI thread. Calls to SyncableService are
+// posted to model thread through PostTaskOnModelThread().
+// Note: RefCountedThreadSafe by way of DataTypeController.
class NonUIDataTypeController : public DirectoryDataTypeController {
public:
// |dump_stack| is called when an unrecoverable error occurs.
- NonUIDataTypeController(ModelType type,
- const base::Closure& dump_stack,
- SyncClient* sync_client);
+ NonUIDataTypeController(
+ ModelType type,
+ const base::Closure& dump_stack,
+ SyncClient* sync_client,
+ ModelSafeGroup model_safe_group,
+ scoped_refptr<base::SequencedTaskRunner> model_thread);
~NonUIDataTypeController() override;
// DataTypeController interface.
void LoadModels(const ModelLoadCallback& model_load_callback) override;
void StartAssociating(const StartCallback& start_callback) override;
void Stop() override;
- ModelSafeGroup model_safe_group() const override = 0;
ChangeProcessor* GetChangeProcessor() const override;
std::string name() const override;
State state() const override;
+ // Used by tests to override the factory used to create
+ // GenericChangeProcessors.
+ void SetGenericChangeProcessorFactoryForTest(
+ std::unique_ptr<GenericChangeProcessorFactory> factory);
+
protected:
// For testing only.
NonUIDataTypeController();
@@ -54,12 +66,12 @@ class NonUIDataTypeController : public DirectoryDataTypeController {
// Note: this is performed on the UI thread.
virtual void StopModels();
- // Posts the given task to the backend thread, i.e. the thread the
- // datatype lives on. Return value: True if task posted successfully,
- // false otherwise.
- virtual bool PostTaskOnBackendThread(
- const tracked_objects::Location& from_here,
- const base::Closure& task) = 0;
+ // Posts the given task to the model thread, i.e. the thread the datatype
+ // lives on. Return value: True if task posted successfully, false otherwise.
+ // Default implementation posts task to model_thread_. Types that don't use
+ // TaskRunner need to override this method.
+ virtual bool PostTaskOnModelThread(const tracked_objects::Location& from_here,
+ const base::Closure& task);
// Start up complete, update the state and invoke the callback.
virtual void StartDone(DataTypeController::ConfigureResult start_result,
@@ -106,6 +118,10 @@ class NonUIDataTypeController : public DirectoryDataTypeController {
// passed to SharedChangeProcessor::Connect on the model thread.
UserShare* user_share_;
+ // Factory is used by tests to inject custom implementation of
+ // GenericChangeProcessor.
+ std::unique_ptr<GenericChangeProcessorFactory> processor_factory_;
+
// State of this datatype controller.
State state_;
@@ -113,6 +129,10 @@ class NonUIDataTypeController : public DirectoryDataTypeController {
StartCallback start_callback_;
ModelLoadCallback model_load_callback_;
+ // Task runner of the model thread. Can be nullptr in which case datatype
+ // controller needs to override PostTaskOnModelThread().
+ scoped_refptr<base::SequencedTaskRunner> model_thread_;
+
// The shared change processor is the thread-safe interface to the
// datatype. We hold a reference to it from the UI thread so that
// we can call Disconnect() on it from Stop()/StartDoneImpl(). Most
« no previous file with comments | « components/sync/driver/frontend_data_type_controller_mock.h ('k') | components/sync/driver/non_ui_data_type_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698