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

Unified Diff: components/sync/driver/non_blocking_data_type_controller.cc

Issue 2254083002: [Sync] Convert NonBlockingDataTypeController to be single-thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dt
Patch Set: Update DeviceInfoService. Created 4 years, 4 months 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_blocking_data_type_controller.cc
diff --git a/components/sync/driver/non_blocking_data_type_controller.cc b/components/sync/driver/non_blocking_data_type_controller.cc
index 6f4a6c118e8dfc3286b5ffed6993320fb40ced95..4d293c8ff827c6d90b3dece83f8a9e518cf4d948 100644
--- a/components/sync/driver/non_blocking_data_type_controller.cc
+++ b/components/sync/driver/non_blocking_data_type_controller.cc
@@ -14,6 +14,7 @@
#include "components/sync/api/model_type_service.h"
#include "components/sync/api/sync_error.h"
#include "components/sync/api/sync_merge_result.h"
+#include "components/sync/base/bind_to_task_runner.h"
#include "components/sync/base/data_type_histogram.h"
#include "components/sync/core/activation_context.h"
#include "components/sync/driver/backend_data_type_configurer.h"
@@ -44,7 +45,7 @@ bool NonBlockingDataTypeController::ShouldLoadModelBeforeConfigure() const {
void NonBlockingDataTypeController::LoadModels(
const ModelLoadCallback& model_load_callback) {
- DCHECK(ui_thread()->BelongsToCurrentThread());
+ DCHECK(BelongsToUIThread());
DCHECK(!model_load_callback.is_null());
model_load_callback_ = model_load_callback;
@@ -58,11 +59,18 @@ void NonBlockingDataTypeController::LoadModels(
state_ = MODEL_STARTING;
+ // Callback that posts back to the UI thread.
+ syncer_v2::ModelTypeChangeProcessor::StartCallback callback =
+ syncer::BindToTaskRunner(
+ ui_thread(),
+ base::Bind(&NonBlockingDataTypeController::OnProcessorStarted, this));
+
// Start the type processor on the model thread.
if (!RunOnModelThread(
FROM_HERE,
- base::Bind(&NonBlockingDataTypeController::LoadModelsOnModelThread,
- this))) {
+ base::Bind(&syncer_v2::ModelTypeService::OnSyncStarting,
+ sync_client_->GetModelTypeServiceForType(type()),
+ base::Unretained(this), callback))) {
LoadModelsDone(
UNRECOVERABLE_ERROR,
syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
@@ -70,22 +78,6 @@ void NonBlockingDataTypeController::LoadModels(
}
}
-void NonBlockingDataTypeController::LoadModelsOnModelThread() {
- syncer_v2::ModelTypeService* model_type_service =
- sync_client_->GetModelTypeServiceForType(type());
- if (!model_type_service) {
- LOG(WARNING) << "ModelTypeService destroyed before "
- "ModelTypeController was started.";
- // TODO(gangwu): Add SyncError and then call start_callback with it. Also
- // set an error state to |state_|.
- return;
- }
-
- model_type_service->OnSyncStarting(
- this,
- base::Bind(&NonBlockingDataTypeController::OnProcessorStarted, this));
-}
-
void NonBlockingDataTypeController::LoadModelsDone(
ConfigureResult result,
const syncer::SyncError& error) {
@@ -113,15 +105,6 @@ void NonBlockingDataTypeController::LoadModelsDone(
void NonBlockingDataTypeController::OnProcessorStarted(
syncer::SyncError error,
std::unique_ptr<syncer_v2::ActivationContext> activation_context) {
- RunOnUIThread(
- FROM_HERE,
- base::Bind(&NonBlockingDataTypeController::OnProcessorStartedOnUIThread,
- this, error, base::Passed(std::move(activation_context))));
-}
-
-void NonBlockingDataTypeController::OnProcessorStartedOnUIThread(
- syncer::SyncError error,
- std::unique_ptr<syncer_v2::ActivationContext> activation_context) {
DCHECK(BelongsToUIThread());
// Hold on to the activation context until ActivateDataType is called.
if (state_ == MODEL_STARTING) {
@@ -173,7 +156,7 @@ void NonBlockingDataTypeController::DeactivateDataType(
}
void NonBlockingDataTypeController::Stop() {
- DCHECK(ui_thread()->BelongsToCurrentThread());
+ DCHECK(BelongsToUIThread());
if (state() == NOT_RUNNING)
return;
@@ -187,20 +170,13 @@ void NonBlockingDataTypeController::Stop() {
(!sync_prefs_.IsFirstSetupComplete() || !preferred_types.Has(type()))) {
RunOnModelThread(
FROM_HERE,
- base::Bind(&NonBlockingDataTypeController::DisableSyncOnModelThread,
- this));
+ base::Bind(&syncer_v2::ModelTypeService::DisableSync,
+ sync_client_->GetModelTypeServiceForType(type())));
}
state_ = NOT_RUNNING;
}
-void NonBlockingDataTypeController::DisableSyncOnModelThread() {
- syncer_v2::ModelTypeService* model_type_service =
- sync_client_->GetModelTypeServiceForType(type());
- DCHECK(model_type_service);
- model_type_service->DisableSync();
-}
-
std::string NonBlockingDataTypeController::name() const {
// For logging only.
return syncer::ModelTypeToString(type());

Powered by Google App Engine
This is Rietveld 408576698