Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / glue / password_data_type_controller.cc
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.
4
5 #include "chrome/browser/sync/glue/password_data_type_controller.h"
6
7 #include "base/bind.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"
17
18 using content::BrowserThread;
19
20 namespace browser_sync {
21
22 PasswordDataTypeController::PasswordDataTypeController(
23     ProfileSyncComponentsFactory* profile_sync_factory,
24     Profile* profile,
25     ProfileSyncService* sync_service)
26     : NonFrontendDataTypeController(
27           BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
28           base::Bind(&ChromeReportUnrecoverableError),
29           profile_sync_factory,
30           profile,
31           sync_service) {
32 }
33
34 syncer::ModelType PasswordDataTypeController::type() const {
35   return syncer::PASSWORDS;
36 }
37
38 syncer::ModelSafeGroup PasswordDataTypeController::model_safe_group()
39     const {
40   return syncer::GROUP_PASSWORD;
41 }
42
43 PasswordDataTypeController::~PasswordDataTypeController() {}
44
45 bool PasswordDataTypeController::PostTaskOnBackendThread(
46       const tracked_objects::Location& from_here,
47       const base::Closure& task) {
48   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49   if (!password_store_)
50     return false;
51   return password_store_->ScheduleTask(task);
52 }
53
54 bool PasswordDataTypeController::IsOnBackendThread() {
55   return password_store_->GetBackgroundTaskRunner()->RunsTasksOnCurrentThread();
56 }
57
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;
64 }
65
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(),
73       this);
74 }
75
76 void PasswordDataTypeController::DisconnectProcessor(
77     ChangeProcessor* processor) {
78   static_cast<PasswordChangeProcessor*>(processor)->Disconnect();
79 }
80
81 }  // namespace browser_sync