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#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
6#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
7
8#include <vector>
9
10#include "base/memory/scoped_ptr.h"
11#include "components/password_manager/core/browser/login_database.h"
12#include "components/password_manager/core/browser/password_store.h"
13
14namespace password_manager {
15
16// Simple password store implementation that delegates everything to
17// the LoginDatabase.
18class PasswordStoreDefault : public PasswordStore {
19 public:
20  // Takes ownership of |login_db|.
21  PasswordStoreDefault(
22      scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
23      scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
24      LoginDatabase* login_db);
25
26 protected:
27  virtual ~PasswordStoreDefault();
28
29  // Implements PasswordStore interface.
30  virtual void ReportMetricsImpl(const std::string& sync_username) OVERRIDE;
31  virtual PasswordStoreChangeList AddLoginImpl(
32      const autofill::PasswordForm& form) OVERRIDE;
33  virtual PasswordStoreChangeList UpdateLoginImpl(
34      const autofill::PasswordForm& form) OVERRIDE;
35  virtual PasswordStoreChangeList RemoveLoginImpl(
36      const autofill::PasswordForm& form) OVERRIDE;
37  virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
38      base::Time delete_begin,
39      base::Time delete_end) OVERRIDE;
40  virtual PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
41      base::Time delete_begin,
42      base::Time delete_end) OVERRIDE;
43  virtual void GetLoginsImpl(
44      const autofill::PasswordForm& form,
45      AuthorizationPromptPolicy prompt_policy,
46      const ConsumerCallbackRunner& callback_runner) OVERRIDE;
47  virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) OVERRIDE;
48  virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) OVERRIDE;
49  virtual bool FillAutofillableLogins(
50      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
51  virtual bool FillBlacklistLogins(
52      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
53
54 protected:
55  inline bool DeleteAndRecreateDatabaseFile() {
56    return login_db_->DeleteAndRecreateDatabaseFile();
57  }
58
59 private:
60  scoped_ptr<LoginDatabase> login_db_;
61
62  DISALLOW_COPY_AND_ASSIGN(PasswordStoreDefault);
63};
64
65}  // namespace password_manager
66
67#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_STORE_DEFAULT_H_
68