1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/glue/password_data_type_controller.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
12 #include "chrome/browser/sync/glue/password_change_processor.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "components/password_manager/core/browser/password_store.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "sync/api/sync_error.h"
18 using content::BrowserThread;
20 namespace browser_sync {
22 PasswordDataTypeController::PasswordDataTypeController(
23 ProfileSyncComponentsFactory* profile_sync_factory,
25 ProfileSyncService* sync_service)
26 : NonFrontendDataTypeController(
27 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
28 base::Bind(&ChromeReportUnrecoverableError),
34 syncer::ModelType PasswordDataTypeController::type() const {
35 return syncer::PASSWORDS;
38 syncer::ModelSafeGroup PasswordDataTypeController::model_safe_group()
40 return syncer::GROUP_PASSWORD;
43 PasswordDataTypeController::~PasswordDataTypeController() {}
45 bool PasswordDataTypeController::PostTaskOnBackendThread(
46 const tracked_objects::Location& from_here,
47 const base::Closure& task) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51 return password_store_->ScheduleTask(task);
54 bool PasswordDataTypeController::IsOnBackendThread() {
55 return password_store_->GetBackgroundTaskRunner()->RunsTasksOnCurrentThread();
58 bool PasswordDataTypeController::StartModels() {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 DCHECK_EQ(state(), MODEL_STARTING);
61 password_store_ = PasswordStoreFactory::GetForProfile(
62 profile(), Profile::EXPLICIT_ACCESS);
63 return password_store_.get() != NULL;
66 ProfileSyncComponentsFactory::SyncComponents
67 PasswordDataTypeController::CreateSyncComponents() {
68 DCHECK(IsOnBackendThread());
69 DCHECK_EQ(state(), ASSOCIATING);
70 return profile_sync_factory()->CreatePasswordSyncComponents(
71 profile_sync_service(),
72 password_store_.get(),
76 void PasswordDataTypeController::DisconnectProcessor(
77 ChangeProcessor* processor) {
78 static_cast<PasswordChangeProcessor*>(processor)->Disconnect();
81 } // namespace browser_sync