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

Unified Diff: chrome/browser/sync/glue/password_data_type_controller.cc

Issue 6811003: [Sync] Make generic non-frontend thread datatype controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Copy paste :( Created 9 years, 8 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: chrome/browser/sync/glue/password_data_type_controller.cc
diff --git a/chrome/browser/sync/glue/password_data_type_controller.cc b/chrome/browser/sync/glue/password_data_type_controller.cc
index 2589861be229814d23c22b4a77f3117de34fb444..69b1d89fe5f082fe2decd910ea14158856a6f223 100644
--- a/chrome/browser/sync/glue/password_data_type_controller.cc
+++ b/chrome/browser/sync/glue/password_data_type_controller.cc
@@ -5,105 +5,66 @@
#include "chrome/browser/sync/glue/password_data_type_controller.h"
#include "base/metrics/histogram.h"
-#include "base/logging.h"
#include "base/task.h"
-#include "base/time.h"
#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/glue/password_change_processor.h"
-#include "chrome/browser/sync/glue/password_model_associator.h"
-#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_factory.h"
+#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/browser/webdata/web_data_service.h"
#include "content/browser/browser_thread.h"
namespace browser_sync {
PasswordDataTypeController::PasswordDataTypeController(
ProfileSyncFactory* profile_sync_factory,
- Profile* profile,
- ProfileSyncService* sync_service)
- : profile_sync_factory_(profile_sync_factory),
- profile_(profile),
- sync_service_(sync_service),
- state_(NOT_RUNNING),
- abort_association_(false),
- abort_association_complete_(false, false),
- datatype_stopped_(false, false) {
- DCHECK(profile_sync_factory);
- DCHECK(profile);
- DCHECK(sync_service);
+ Profile* profile)
+ : NonFrontendDataTypeController(profile_sync_factory,
+ profile) {
}
PasswordDataTypeController::~PasswordDataTypeController() {
}
-void PasswordDataTypeController::Start(StartCallback* start_callback) {
+bool PasswordDataTypeController::StartModels() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(start_callback);
- if (state_ != NOT_RUNNING) {
- start_callback->Run(BUSY, FROM_HERE);
- delete start_callback;
- return;
- }
-
- password_store_ = profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
+ DCHECK_EQ(state(), MODEL_STARTING);
+ password_store_ = profile()->GetPasswordStore(Profile::EXPLICIT_ACCESS);
if (!password_store_.get()) {
LOG(ERROR) << "PasswordStore not initialized, password datatype controller"
<< " aborting.";
- state_ = NOT_RUNNING;
- start_callback->Run(ABORTED, FROM_HERE);
- delete start_callback;
- return;
+ StartDoneImpl(ABORTED, NOT_RUNNING, FROM_HERE);
+ return false;
}
-
- start_callback_.reset(start_callback);
- abort_association_ = false;
- set_state(ASSOCIATING);
- password_store_->ScheduleTask(
- NewRunnableMethod(this, &PasswordDataTypeController::StartImpl));
+ return true;
}
-// TODO(sync): Blocking the UI thread at shutdown is bad. If we had a way of
-// distinguishing chrome shutdown from sync shutdown, we should be able to avoid
-// this (http://crbug.com/55662). Further, all this functionality should be
-// abstracted to a higher layer, where we could ensure all datatypes are doing
-// the same thing (http://crbug.com/76232).
-void PasswordDataTypeController::Stop() {
+bool PasswordDataTypeController::StartAssociationAsync() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- // If Stop() is called while Start() is waiting for association to
- // complete, we need to abort the association and wait for the PASSWORD
- // thread to finish the StartImpl() task.
- if (state_ == ASSOCIATING) {
- {
- base::AutoLock lock(abort_association_lock_);
- abort_association_ = true;
- if (model_associator_.get())
- model_associator_->AbortAssociation();
- }
- // Wait for the model association to abort.
- abort_association_complete_.Wait();
- StartDoneImpl(ABORTED, STOPPING);
- }
-
- // If Stop() is called while Start() is waiting for another service to load,
- // abort the start.
- if (state_ == MODEL_STARTING)
- StartDoneImpl(ABORTED, STOPPING);
-
- DCHECK(!start_callback_.get());
-
- if (change_processor_ != NULL)
- sync_service_->DeactivateDataType(this, change_processor_.get());
-
- set_state(NOT_RUNNING);
+ DCHECK_EQ(state(), ASSOCIATING);
DCHECK(password_store_.get());
password_store_->ScheduleTask(
- NewRunnableMethod(this, &PasswordDataTypeController::StopImpl));
- datatype_stopped_.Wait();
+ NewRunnableMethod(this, &PasswordDataTypeController::StartAssociation));
+ return true;
+}
+
+void PasswordDataTypeController::CreateSyncComponents() {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_EQ(state(), ASSOCIATING);
+ ProfileSyncFactory::SyncComponents sync_components =
+ profile_sync_factory()->CreatePasswordSyncComponents(
+ profile_sync_service(),
+ password_store_.get(),
+ this);
+ set_model_associator(sync_components.model_associator);
+ set_change_processor(sync_components.change_processor);
}
-bool PasswordDataTypeController::enabled() {
+bool PasswordDataTypeController::StopAssociationAsync() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_EQ(state(), STOPPING);
+ DCHECK(password_store_.get());
+ password_store_->ScheduleTask(
+ NewRunnableMethod(this, &PasswordDataTypeController::StopAssociation));
return true;
}
@@ -116,111 +77,23 @@ browser_sync::ModelSafeGroup PasswordDataTypeController::model_safe_group()
return browser_sync::GROUP_PASSWORD;
}
-std::string PasswordDataTypeController::name() const {
- // For logging only.
- return "password";
-}
-
-DataTypeController::State PasswordDataTypeController::state() const {
- return state_;
-}
-
-void PasswordDataTypeController::StartImpl() {
- // No additional services need to be started before we can proceed
- // with model association.
- {
- base::AutoLock lock(abort_association_lock_);
- if (abort_association_) {
- abort_association_complete_.Signal();
- return;
- }
- ProfileSyncFactory::SyncComponents sync_components =
- profile_sync_factory_->CreatePasswordSyncComponents(
- sync_service_,
- password_store_.get(),
- this);
- model_associator_.reset(sync_components.model_associator);
- change_processor_.reset(sync_components.change_processor);
- }
-
- if (!model_associator_->CryptoReadyIfNecessary()) {
- StartFailed(NEEDS_CRYPTO);
- return;
- }
-
- bool sync_has_nodes = false;
- if (!model_associator_->SyncModelHasUserCreatedNodes(&sync_has_nodes)) {
- StartFailed(UNRECOVERABLE_ERROR);
- return;
- }
-
- base::TimeTicks start_time = base::TimeTicks::Now();
- bool merge_success = model_associator_->AssociateModels();
- UMA_HISTOGRAM_TIMES("Sync.PasswordAssociationTime",
- base::TimeTicks::Now() - start_time);
- if (!merge_success) {
- StartFailed(ASSOCIATION_FAILED);
- return;
- }
-
- sync_service_->ActivateDataType(this, change_processor_.get());
- StartDone(!sync_has_nodes ? OK_FIRST_RUN : OK, RUNNING);
-}
-
-void PasswordDataTypeController::StartDone(
- DataTypeController::StartResult result,
- DataTypeController::State new_state) {
- abort_association_complete_.Signal();
- base::AutoLock lock(abort_association_lock_);
- if (!abort_association_) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(
- this,
- &PasswordDataTypeController::StartDoneImpl,
- result,
- new_state));
- }
-}
-
-void PasswordDataTypeController::StartDoneImpl(
- DataTypeController::StartResult result,
- DataTypeController::State new_state) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- set_state(new_state);
- start_callback_->Run(result, FROM_HERE);
- start_callback_.reset();
-}
-
-void PasswordDataTypeController::StopImpl() {
- if (model_associator_ != NULL)
- model_associator_->DisassociateModels();
-
- change_processor_.reset();
- model_associator_.reset();
-
- datatype_stopped_.Signal();
-}
-
-void PasswordDataTypeController::StartFailed(StartResult result) {
- change_processor_.reset();
- model_associator_.reset();
- StartDone(result, NOT_RUNNING);
+void PasswordDataTypeController::RecordUnrecoverableError(
+ const tracked_objects::Location& from_here,
+ const std::string& message) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ UMA_HISTOGRAM_COUNTS("Sync.PasswordRunFailures", 1);
}
-void PasswordDataTypeController::OnUnrecoverableError(
- const tracked_objects::Location& from_here, const std::string& message) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this,
- &PasswordDataTypeController::OnUnrecoverableErrorImpl,
- from_here, message));
+void PasswordDataTypeController::RecordAssociationTime(base::TimeDelta time) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ UMA_HISTOGRAM_TIMES("Sync.PasswordAssociationTime", time);
}
-void PasswordDataTypeController::OnUnrecoverableErrorImpl(
- const tracked_objects::Location& from_here,
- const std::string& message) {
+void PasswordDataTypeController::RecordStartFailure(StartResult result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- sync_service_->OnUnrecoverableError(from_here, message);
+ UMA_HISTOGRAM_ENUMERATION("Sync.PasswordStartFailures",
+ result,
+ MAX_START_RESULT);
}
} // namespace browser_sync
« no previous file with comments | « chrome/browser/sync/glue/password_data_type_controller.h ('k') | chrome/browser/sync/glue/typed_url_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698