Upstream version 8.37.180.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   virtual bool Init(
41       const syncer::SyncableService::StartSyncFlare& flare) OVERRIDE;
42
43   // Stops |thread_|.
44   virtual void Shutdown() OVERRIDE;
45
46  protected:
47   virtual ~PasswordStoreMac();
48
49   virtual scoped_refptr<base::SingleThreadTaskRunner>
50       GetBackgroundTaskRunner() OVERRIDE;
51
52  private:
53   virtual void ReportMetricsImpl() OVERRIDE;
54   virtual password_manager::PasswordStoreChangeList AddLoginImpl(
55       const autofill::PasswordForm& form) OVERRIDE;
56   virtual password_manager::PasswordStoreChangeList UpdateLoginImpl(
57       const autofill::PasswordForm& form) OVERRIDE;
58   virtual password_manager::PasswordStoreChangeList RemoveLoginImpl(
59       const autofill::PasswordForm& form) OVERRIDE;
60   virtual password_manager::PasswordStoreChangeList
61       RemoveLoginsCreatedBetweenImpl(base::Time delete_begin,
62                                      base::Time delete_end) OVERRIDE;
63   virtual password_manager::PasswordStoreChangeList
64       RemoveLoginsSyncedBetweenImpl(base::Time delete_begin,
65                                     base::Time delete_end) OVERRIDE;
66   virtual void GetLoginsImpl(
67       const autofill::PasswordForm& form,
68       AuthorizationPromptPolicy prompt_policy,
69       const ConsumerCallbackRunner& callback_runner) OVERRIDE;
70   virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) OVERRIDE;
71   virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) OVERRIDE;
72   virtual bool FillAutofillableLogins(
73       std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
74   virtual bool FillBlacklistLogins(
75       std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
76
77   // Adds the given form to the Keychain if it's something we want to store
78   // there (i.e., not a blacklist entry). Returns true if the operation
79   // succeeded (either we added successfully, or we didn't need to).
80   bool AddToKeychainIfNecessary(const autofill::PasswordForm& form);
81
82   // Returns true if our database contains a form that exactly matches the given
83   // keychain form.
84   bool DatabaseHasFormMatchingKeychainForm(
85       const autofill::PasswordForm& form);
86
87   // Returns all the Keychain entries that we own but no longer have
88   // corresponding metadata for in our database.
89   // Caller is responsible for deleting the forms.
90   std::vector<autofill::PasswordForm*> GetUnusedKeychainForms();
91
92   // Removes the given forms from the database.
93   void RemoveDatabaseForms(
94       const std::vector<autofill::PasswordForm*>& forms);
95
96   // Removes the given forms from the Keychain.
97   void RemoveKeychainForms(
98       const std::vector<autofill::PasswordForm*>& forms);
99
100   scoped_ptr<crypto::AppleKeychain> keychain_;
101   scoped_ptr<password_manager::LoginDatabase> login_metadata_db_;
102
103   // Thread that the synchronous methods are run on.
104   scoped_ptr<base::Thread> thread_;
105
106   DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
107 };
108
109 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_