| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..50f4e860bb332418e96d09fd9750a21e698b80a5
|
| --- /dev/null
|
| +++ b/chrome/browser/sync/glue/password_data_type_controller.cc
|
| @@ -0,0 +1,144 @@
|
| +// Copyright (c) 2010 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/histogram.h"
|
| +#include "base/logging.h"
|
| +#include "base/task.h"
|
| +#include "base/time.h"
|
| +#include "chrome/browser/chrome_thread.h"
|
| +#include "chrome/browser/password_manager/password_store.h"
|
| +#include "chrome/browser/profile.h"
|
| +#include "chrome/browser/sync/glue/password_change_processor.h"
|
| +#include "chrome/browser/sync/glue/password_data_type_controller.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"
|
| +
|
| +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) {
|
| + DCHECK(profile_sync_factory);
|
| + DCHECK(profile);
|
| + DCHECK(sync_service);
|
| +}
|
| +
|
| +PasswordDataTypeController::~PasswordDataTypeController() {
|
| +}
|
| +
|
| +void PasswordDataTypeController::Start(StartCallback* start_callback) {
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| + DCHECK(start_callback);
|
| + if (state_ != NOT_RUNNING) {
|
| + start_callback->Run(BUSY);
|
| + delete start_callback;
|
| + return;
|
| + }
|
| +
|
| + start_callback_.reset(start_callback);
|
| +
|
| + set_state(ASSOCIATING);
|
| + password_store_ = profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
|
| + DCHECK(password_store_.get());
|
| + password_store_->ScheduleTask(
|
| + NewRunnableMethod(this, &PasswordDataTypeController::StartImpl));
|
| +}
|
| +
|
| +void PasswordDataTypeController::Stop() {
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| +
|
| + if (change_processor_ != NULL)
|
| + sync_service_->DeactivateDataType(this, change_processor_.get());
|
| +
|
| + if (model_associator_ != NULL)
|
| + model_associator_->DisassociateModels();
|
| +
|
| + set_state(NOT_RUNNING);
|
| + DCHECK(password_store_.get());
|
| + password_store_->ScheduleTask(
|
| + NewRunnableMethod(this, &PasswordDataTypeController::StopImpl));
|
| +}
|
| +
|
| +void PasswordDataTypeController::StartImpl() {
|
| + // No additional services need to be started before we can proceed
|
| + // with model association.
|
| + 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);
|
| +
|
| + 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) {
|
| + ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
|
| + NewRunnableMethod(
|
| + this,
|
| + &PasswordDataTypeController::StartDoneImpl,
|
| + result,
|
| + new_state));
|
| +}
|
| +
|
| +void PasswordDataTypeController::StartDoneImpl(
|
| + DataTypeController::StartResult result,
|
| + DataTypeController::State new_state) {
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| + set_state(new_state);
|
| + start_callback_->Run(result);
|
| + start_callback_.reset();
|
| +}
|
| +
|
| +void PasswordDataTypeController::StopImpl() {
|
| + change_processor_.reset();
|
| + model_associator_.reset();
|
| +
|
| + state_ = NOT_RUNNING;
|
| +}
|
| +
|
| +void PasswordDataTypeController::StartFailed(StartResult result) {
|
| + change_processor_.reset();
|
| + model_associator_.reset();
|
| + StartDone(result, NOT_RUNNING);
|
| +}
|
| +
|
| +void PasswordDataTypeController::OnUnrecoverableError() {
|
| + ChromeThread::PostTask(
|
| + ChromeThread::UI, FROM_HERE,
|
| + NewRunnableMethod(this,
|
| + &PasswordDataTypeController::OnUnrecoverableErrorImpl));
|
| +}
|
| +
|
| +void PasswordDataTypeController::OnUnrecoverableErrorImpl() {
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| + sync_service_->OnUnrecoverableError();
|
| +}
|
| +
|
| +} // namespace browser_sync
|
|
|