Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / password_manager / native_backend_libsecret.h
blob15dfc3997b7d6ea99d07f35c64b69a0029213080
1 // Copyright (c) 2015 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_NATIVE_BACKEND_LIBSECRET_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_LIBSECRET_H_
8 #include <libsecret/secret.h>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/password_manager/password_store_factory.h"
16 #include "chrome/browser/password_manager/password_store_x.h"
17 #include "chrome/browser/profiles/profile.h"
19 namespace autofill {
20 struct PasswordForm;
23 class LibsecretLoader {
24 public:
25 static decltype(&::secret_password_store_sync) secret_password_store_sync;
26 static decltype(&::secret_service_search_sync) secret_service_search_sync;
27 static decltype(&::secret_password_clear_sync) secret_password_clear_sync;
28 static decltype(&::secret_item_get_secret) secret_item_get_secret;
29 static decltype(&::secret_value_get_text) secret_value_get_text;
30 static decltype(&::secret_item_get_attributes) secret_item_get_attributes;
31 static decltype(&::secret_item_load_secret_sync) secret_item_load_secret_sync;
32 static decltype(&::secret_value_unref) secret_value_unref;
34 protected:
35 static bool LoadLibsecret();
36 static bool LibsecretIsAvailable();
38 static bool libsecret_loaded;
40 private:
41 struct FunctionInfo {
42 const char* name;
43 void** pointer;
46 static const FunctionInfo functions[];
49 class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
50 public LibsecretLoader {
51 public:
52 explicit NativeBackendLibsecret(LocalProfileId id);
54 ~NativeBackendLibsecret() override;
56 bool Init() override;
58 // Implements NativeBackend interface.
59 password_manager::PasswordStoreChangeList AddLogin(
60 const autofill::PasswordForm& form) override;
61 bool UpdateLogin(const autofill::PasswordForm& form,
62 password_manager::PasswordStoreChangeList* changes) override;
63 bool RemoveLogin(const autofill::PasswordForm& form) override;
64 bool RemoveLoginsCreatedBetween(
65 base::Time delete_begin,
66 base::Time delete_end,
67 password_manager::PasswordStoreChangeList* changes) override;
68 bool RemoveLoginsSyncedBetween(
69 base::Time delete_begin,
70 base::Time delete_end,
71 password_manager::PasswordStoreChangeList* changes) override;
72 bool GetLogins(const autofill::PasswordForm& form,
73 ScopedVector<autofill::PasswordForm>* forms) override;
74 bool GetAutofillableLogins(
75 ScopedVector<autofill::PasswordForm>* forms) override;
76 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
78 private:
79 enum TimestampToCompare {
80 CREATION_TIMESTAMP,
81 SYNC_TIMESTAMP,
84 enum AddUpdateLoginSearchOptions {
85 SEARCH_USE_SUBMIT,
86 SEARCH_IGNORE_SUBMIT,
89 // Search that is used in AddLogin and UpdateLogin methods
90 void AddUpdateLoginSearch(const autofill::PasswordForm& lookup_form,
91 AddUpdateLoginSearchOptions options,
92 ScopedVector<autofill::PasswordForm>* forms);
94 // Adds a login form without checking for one to replace first.
95 bool RawAddLogin(const autofill::PasswordForm& form);
97 enum GetLoginsListOptions {
98 ALL_LOGINS,
99 AUTOFILLABLE_LOGINS,
100 BLACKLISTED_LOGINS,
103 // Reads PasswordForms from the keyring with the given autofillability state.
104 bool GetLoginsList(const autofill::PasswordForm* lookup_form,
105 GetLoginsListOptions options,
106 ScopedVector<autofill::PasswordForm>* forms);
108 // Helper for GetLoginsCreatedBetween().
109 bool GetAllLogins(ScopedVector<autofill::PasswordForm>* forms);
111 // Retrieves password created/synced in the time interval. Returns |true| if
112 // the operation succeeded.
113 bool GetLoginsBetween(base::Time get_begin,
114 base::Time get_end,
115 TimestampToCompare date_to_compare,
116 ScopedVector<autofill::PasswordForm>* forms);
118 // Removes password created/synced in the time interval. Returns |true| if the
119 // operation succeeded. |changes| will contain the changes applied.
120 bool RemoveLoginsBetween(base::Time get_begin,
121 base::Time get_end,
122 TimestampToCompare date_to_compare,
123 password_manager::PasswordStoreChangeList* changes);
125 // convert data get from Libsecret to Passwordform
126 bool ConvertFormList(GList* found,
127 const autofill::PasswordForm* lookup_form,
128 ScopedVector<autofill::PasswordForm>* forms);
130 // Generates a profile-specific app string based on profile_id_.
131 static std::string GetProfileSpecificAppString(LocalProfileId id);
133 // The app string, possibly based on the local profile id.
134 std::string app_string_;
136 DISALLOW_COPY_AND_ASSIGN(NativeBackendLibsecret);
139 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_LIBSECRET_H_