Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / password_store_mac.h
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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
7
8 #include <vector>
9
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h"
13 #include "components/password_manager/core/browser/login_database.h"
14 #include "components/password_manager/core/browser/password_store.h"
15
16 namespace crypto {
17 class AppleKeychain;
18 }
19
20 namespace password_manager {
21 class LoginDatabase;
22 }
23
24 // Implements PasswordStore on top of the OS X Keychain, with an internal
25 // database for extra metadata. For an overview of the interactions with the
26 // Keychain, as well as the rationale for some of the behaviors, see the
27 // Keychain integration design doc:
28 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration
29 class PasswordStoreMac : public password_manager::PasswordStore {
30  public:
31   // Takes ownership of |keychain| and |login_db|, both of which must be
32   // non-NULL.
33   PasswordStoreMac(
34       scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
35       scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
36       crypto::AppleKeychain* keychain,
37       password_manager::LoginDatabase* login_db);
38
39   // Initializes |thread_|.
40   bool Init(const syncer::SyncableService::StartSyncFlare& flare) override;
41
42   // Stops |thread_|.
43   void Shutdown() override;
44
45  protected:
46   ~PasswordStoreMac() override;
47
48   scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()
49       override;
50
51  private:
52   void ReportMetricsImpl(const std::string& sync_username,
53                          bool custom_passphrase_sync_enabled) override;
54   password_manager::PasswordStoreChangeList AddLoginImpl(
55       const autofill::PasswordForm& form) override;
56   password_manager::PasswordStoreChangeList UpdateLoginImpl(
57       const autofill::PasswordForm& form) override;
58   password_manager::PasswordStoreChangeList RemoveLoginImpl(
59       const autofill::PasswordForm& form) override;
60   password_manager::PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
61       base::Time delete_begin,
62       base::Time delete_end) override;
63   password_manager::PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
64       base::Time delete_begin,
65       base::Time delete_end) override;
66   void GetLoginsImpl(const autofill::PasswordForm& form,
67                      AuthorizationPromptPolicy prompt_policy,
68                      const ConsumerCallbackRunner& callback_runner) override;
69   void GetAutofillableLoginsImpl(GetLoginsRequest* request) override;
70   void GetBlacklistLoginsImpl(GetLoginsRequest* request) override;
71   bool FillAutofillableLogins(
72       std::vector<autofill::PasswordForm*>* forms) override;
73   bool FillBlacklistLogins(
74       std::vector<autofill::PasswordForm*>* forms) override;
75
76   // Adds the given form to the Keychain if it's something we want to store
77   // there (i.e., not a blacklist entry). Returns true if the operation
78   // succeeded (either we added successfully, or we didn't need to).
79   bool AddToKeychainIfNecessary(const autofill::PasswordForm& form);
80
81   // Returns true if our database contains a form that exactly matches the given
82   // keychain form.
83   bool DatabaseHasFormMatchingKeychainForm(
84       const autofill::PasswordForm& form);
85
86   // Removes the given forms from the database.
87   void RemoveDatabaseForms(
88       const std::vector<autofill::PasswordForm*>& forms);
89
90   // Removes the given forms from the Keychain.
91   void RemoveKeychainForms(
92       const std::vector<autofill::PasswordForm*>& forms);
93
94   // Searches the database for forms without a corresponding entry in the
95   // keychain. Removes those forms from the database, and returns them in
96   // |forms|. Ownership of |forms| is passed to the caller.
97   void CleanOrphanedForms(std::vector<autofill::PasswordForm*>* forms);
98
99   scoped_ptr<crypto::AppleKeychain> keychain_;
100   scoped_ptr<password_manager::LoginDatabase> login_metadata_db_;
101
102   // Thread that the synchronous methods are run on.
103   scoped_ptr<base::Thread> thread_;
104
105   DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
106 };
107
108 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_