1// Copyright 2014 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 "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
6
7#include "base/bind.h"
8#include "base/message_loop/message_loop_proxy.h"
9#include "components/os_crypt/ie7_password_win.h"
10#include "components/password_manager/core/browser/webdata/logins_table.h"
11#include "components/webdata/common/web_database_service.h"
12
13PasswordWebDataService::PasswordWebDataService(
14    scoped_refptr<WebDatabaseService> wdbs,
15    scoped_refptr<base::MessageLoopProxy> ui_thread,
16    const ProfileErrorCallback& callback)
17    : WebDataServiceBase(wdbs, callback, ui_thread) {
18}
19
20void PasswordWebDataService::AddIE7Login(const IE7PasswordInfo& info) {
21  wdbs_->ScheduleDBTask(
22      FROM_HERE,
23      base::Bind(&PasswordWebDataService::AddIE7LoginImpl, this, info));
24}
25
26void PasswordWebDataService::RemoveIE7Login(const IE7PasswordInfo& info) {
27  wdbs_->ScheduleDBTask(
28      FROM_HERE,
29      base::Bind(&PasswordWebDataService::RemoveIE7LoginImpl, this, info));
30}
31
32PasswordWebDataService::Handle PasswordWebDataService::GetIE7Login(
33    const IE7PasswordInfo& info,
34    WebDataServiceConsumer* consumer) {
35  return wdbs_->ScheduleDBTaskWithResult(
36      FROM_HERE,
37      base::Bind(&PasswordWebDataService::GetIE7LoginImpl, this, info),
38      consumer);
39}
40
41WebDatabase::State PasswordWebDataService::AddIE7LoginImpl(
42    const IE7PasswordInfo& info,
43    WebDatabase* db) {
44  return LoginsTable::FromWebDatabase(db)->AddIE7Login(info) ?
45      WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED;
46}
47
48WebDatabase::State PasswordWebDataService::RemoveIE7LoginImpl(
49    const IE7PasswordInfo& info,
50    WebDatabase* db) {
51  return LoginsTable::FromWebDatabase(db)->RemoveIE7Login(info) ?
52      WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED;
53}
54
55scoped_ptr<WDTypedResult> PasswordWebDataService::GetIE7LoginImpl(
56    const IE7PasswordInfo& info,
57    WebDatabase* db) {
58  IE7PasswordInfo result;
59  LoginsTable::FromWebDatabase(db)->GetIE7Login(info, &result);
60  return scoped_ptr<WDTypedResult>(
61      new WDResult<IE7PasswordInfo>(PASSWORD_IE7_RESULT, result));
62}
63
64////////////////////////////////////////////////////////////////////////////////
65
66PasswordWebDataService::PasswordWebDataService(
67    scoped_refptr<base::MessageLoopProxy> ui_thread)
68    : WebDataServiceBase(NULL, ProfileErrorCallback(), ui_thread) {
69}
70
71PasswordWebDataService::~PasswordWebDataService() {
72}
73