- add sources.
[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.h"
10 #include "chrome/browser/password_manager/password_store_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/glue/password_change_processor.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "sync/api/sync_error.h"
16
17 using content::BrowserThread;
18
19 namespace browser_sync {
20
21 PasswordDataTypeController::PasswordDataTypeController(
22     ProfileSyncComponentsFactory* profile_sync_factory,
23     Profile* profile,
24     ProfileSyncService* sync_service)
25     : NonFrontendDataTypeController(profile_sync_factory,
26                                     profile,
27                                     sync_service) {
28 }
29
30 syncer::ModelType PasswordDataTypeController::type() const {
31   return syncer::PASSWORDS;
32 }
33
34 syncer::ModelSafeGroup PasswordDataTypeController::model_safe_group()
35     const {
36   return syncer::GROUP_PASSWORD;
37 }
38
39 PasswordDataTypeController::~PasswordDataTypeController() {}
40
41 bool PasswordDataTypeController::PostTaskOnBackendThread(
42       const tracked_objects::Location& from_here,
43       const base::Closure& task) {
44   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45   if (!password_store_)
46     return false;
47   return password_store_->ScheduleTask(task);
48 }
49
50 bool PasswordDataTypeController::StartModels() {
51   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52   DCHECK_EQ(state(), MODEL_STARTING);
53   password_store_ = PasswordStoreFactory::GetForProfile(
54       profile(), Profile::EXPLICIT_ACCESS);
55   return password_store_.get() != NULL;
56 }
57
58 ProfileSyncComponentsFactory::SyncComponents
59 PasswordDataTypeController::CreateSyncComponents() {
60   DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
61   DCHECK_EQ(state(), ASSOCIATING);
62   return profile_sync_factory()->CreatePasswordSyncComponents(
63       profile_sync_service(),
64       password_store_.get(),
65       this);
66 }
67
68 void PasswordDataTypeController::DisconnectProcessor(
69     ChangeProcessor* processor) {
70   static_cast<PasswordChangeProcessor*>(processor)->Disconnect();
71 }
72
73 }  // namespace browser_sync