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/profile_sync_components_factory.h"
13#include "components/password_manager/core/browser/password_store.h"
14#include "content/public/browser/browser_thread.h"
15
16using content::BrowserThread;
17
18namespace browser_sync {
19
20PasswordDataTypeController::PasswordDataTypeController(
21    ProfileSyncComponentsFactory* profile_sync_factory,
22    Profile* profile)
23    : NonUIDataTypeController(
24          BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
25          base::Bind(&ChromeReportUnrecoverableError),
26          profile_sync_factory),
27      profile_(profile) {
28}
29
30syncer::ModelType PasswordDataTypeController::type() const {
31  return syncer::PASSWORDS;
32}
33
34syncer::ModelSafeGroup PasswordDataTypeController::model_safe_group()
35    const {
36  return syncer::GROUP_PASSWORD;
37}
38
39PasswordDataTypeController::~PasswordDataTypeController() {}
40
41bool PasswordDataTypeController::PostTaskOnBackendThread(
42      const tracked_objects::Location& from_here,
43      const base::Closure& task) {
44  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45  if (!password_store_.get())
46    return false;
47  return password_store_->ScheduleTask(task);
48}
49
50bool PasswordDataTypeController::StartModels() {
51  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52  DCHECK_EQ(MODEL_STARTING, state());
53  password_store_ = PasswordStoreFactory::GetForProfile(
54      profile_, Profile::EXPLICIT_ACCESS);
55  return !!password_store_.get();
56}
57
58}  // namespace browser_sync
59