- add sources.
[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 "chrome/browser/password_manager/login_database.h"
14 #include "chrome/browser/password_manager/password_store.h"
15
16 namespace content {
17 class NotificationService;
18 }
19
20 namespace crypto {
21 class AppleKeychain;
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 PasswordStore {
30  public:
31   // Takes ownership of |keychain| and |login_db|, both of which must be
32   // non-NULL.
33   PasswordStoreMac(crypto::AppleKeychain* keychain, LoginDatabase* login_db);
34
35   // Initializes |thread_| and |notification_service_|.
36   virtual bool Init() OVERRIDE;
37
38   virtual void ShutdownOnUIThread() OVERRIDE;
39
40  protected:
41   virtual ~PasswordStoreMac();
42
43   virtual bool ScheduleTask(const base::Closure& task) OVERRIDE;
44
45  private:
46   virtual void ReportMetricsImpl() OVERRIDE;
47   virtual void AddLoginImpl(const autofill::PasswordForm& form) OVERRIDE;
48   virtual void UpdateLoginImpl(
49       const autofill::PasswordForm& form) OVERRIDE;
50   virtual void RemoveLoginImpl(
51       const autofill::PasswordForm& form) OVERRIDE;
52   virtual void RemoveLoginsCreatedBetweenImpl(
53       const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
54   virtual void GetLoginsImpl(
55       const autofill::PasswordForm& form,
56       const ConsumerCallbackRunner& callback_runner) OVERRIDE;
57   virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) OVERRIDE;
58   virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) OVERRIDE;
59   virtual bool FillAutofillableLogins(
60       std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
61   virtual bool FillBlacklistLogins(
62       std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
63
64   // Adds the given form to the Keychain if it's something we want to store
65   // there (i.e., not a blacklist entry). Returns true if the operation
66   // succeeded (either we added successfully, or we didn't need to).
67   bool AddToKeychainIfNecessary(const autofill::PasswordForm& form);
68
69   // Returns true if our database contains a form that exactly matches the given
70   // keychain form.
71   bool DatabaseHasFormMatchingKeychainForm(
72       const autofill::PasswordForm& form);
73
74   // Returns all the Keychain entries that we own but no longer have
75   // corresponding metadata for in our database.
76   // Caller is responsible for deleting the forms.
77   std::vector<autofill::PasswordForm*> GetUnusedKeychainForms();
78
79   // Removes the given forms from the database.
80   void RemoveDatabaseForms(
81       const std::vector<autofill::PasswordForm*>& forms);
82
83   // Removes the given forms from the Keychain.
84   void RemoveKeychainForms(
85       const std::vector<autofill::PasswordForm*>& forms);
86
87   // Allows the creation of |notification_service_| to be scheduled on the right
88   // thread.
89   void CreateNotificationService();
90
91   scoped_ptr<crypto::AppleKeychain> keychain_;
92   scoped_ptr<LoginDatabase> login_metadata_db_;
93
94   // Thread that the synchronous methods are run on.
95   scoped_ptr<base::Thread> thread_;
96
97   // Since we aren't running on a well-known thread but still want to send out
98   // notifications, we need to run our own service.
99   scoped_ptr<content::NotificationService> notification_service_;
100
101   DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
102 };
103
104 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_