Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / password_manager / password_store_mac.h
blob0e1be3d4dd25bf56d43a90312e13c129da27c5e4
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.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
8 #include <vector>
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"
16 namespace crypto {
17 class AppleKeychain;
20 namespace password_manager {
21 class LoginDatabase;
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);
39 // Initializes |thread_|.
40 virtual bool Init(
41 const syncer::SyncableService::StartSyncFlare& flare,
42 const std::string& sync_username) override;
44 // Stops |thread_|.
45 virtual void Shutdown() override;
47 protected:
48 virtual ~PasswordStoreMac();
50 virtual scoped_refptr<base::SingleThreadTaskRunner>
51 GetBackgroundTaskRunner() override;
53 private:
54 virtual void ReportMetricsImpl(const std::string& sync_username) override;
55 virtual password_manager::PasswordStoreChangeList AddLoginImpl(
56 const autofill::PasswordForm& form) override;
57 virtual password_manager::PasswordStoreChangeList UpdateLoginImpl(
58 const autofill::PasswordForm& form) override;
59 virtual password_manager::PasswordStoreChangeList RemoveLoginImpl(
60 const autofill::PasswordForm& form) override;
61 virtual password_manager::PasswordStoreChangeList
62 RemoveLoginsCreatedBetweenImpl(base::Time delete_begin,
63 base::Time delete_end) override;
64 virtual password_manager::PasswordStoreChangeList
65 RemoveLoginsSyncedBetweenImpl(base::Time delete_begin,
66 base::Time delete_end) override;
67 virtual void GetLoginsImpl(
68 const autofill::PasswordForm& form,
69 AuthorizationPromptPolicy prompt_policy,
70 const ConsumerCallbackRunner& callback_runner) override;
71 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) override;
72 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) override;
73 virtual bool FillAutofillableLogins(
74 std::vector<autofill::PasswordForm*>* forms) override;
75 virtual bool FillBlacklistLogins(
76 std::vector<autofill::PasswordForm*>* forms) override;
78 // Adds the given form to the Keychain if it's something we want to store
79 // there (i.e., not a blacklist entry). Returns true if the operation
80 // succeeded (either we added successfully, or we didn't need to).
81 bool AddToKeychainIfNecessary(const autofill::PasswordForm& form);
83 // Returns true if our database contains a form that exactly matches the given
84 // keychain form.
85 bool DatabaseHasFormMatchingKeychainForm(
86 const autofill::PasswordForm& form);
88 // Removes the given forms from the database.
89 void RemoveDatabaseForms(
90 const std::vector<autofill::PasswordForm*>& forms);
92 // Removes the given forms from the Keychain.
93 void RemoveKeychainForms(
94 const std::vector<autofill::PasswordForm*>& forms);
96 // Searches the database for forms without a corresponding entry in the
97 // keychain. Removes those forms from the database, and returns them in
98 // |forms|. Ownership of |forms| is passed to the caller.
99 void CleanOrphanedForms(std::vector<autofill::PasswordForm*>* forms);
101 scoped_ptr<crypto::AppleKeychain> keychain_;
102 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_;
104 // Thread that the synchronous methods are run on.
105 scoped_ptr<base::Thread> thread_;
107 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
110 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_