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>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/time/time.h"
16 #include "chrome/browser/password_manager/password_store_factory.h"
17 #include "chrome/browser/password_manager/password_store_x.h"
18 #include "chrome/browser/profiles/profile.h"
24 class LibsecretLoader
{
26 static decltype(&::secret_password_store_sync
) secret_password_store_sync
;
27 static decltype(&::secret_service_search_sync
) secret_service_search_sync
;
28 static decltype(&::secret_password_clear_sync
) secret_password_clear_sync
;
29 static decltype(&::secret_item_get_secret
) secret_item_get_secret
;
30 static decltype(&::secret_value_get_text
) secret_value_get_text
;
31 static decltype(&::secret_item_get_attributes
) secret_item_get_attributes
;
32 static decltype(&::secret_item_load_secret_sync
) secret_item_load_secret_sync
;
33 static decltype(&::secret_value_unref
) secret_value_unref
;
36 static bool LoadLibsecret();
37 static bool LibsecretIsAvailable();
39 static bool libsecret_loaded
;
47 static const FunctionInfo functions
[];
50 class NativeBackendLibsecret
: public PasswordStoreX::NativeBackend
,
51 public LibsecretLoader
{
53 explicit NativeBackendLibsecret(LocalProfileId id
);
55 ~NativeBackendLibsecret() override
;
59 // Implements NativeBackend interface.
60 password_manager::PasswordStoreChangeList
AddLogin(
61 const autofill::PasswordForm
& form
) override
;
62 bool UpdateLogin(const autofill::PasswordForm
& form
,
63 password_manager::PasswordStoreChangeList
* changes
) override
;
64 bool RemoveLogin(const autofill::PasswordForm
& form
) override
;
65 bool RemoveLoginsCreatedBetween(
66 base::Time delete_begin
,
67 base::Time delete_end
,
68 password_manager::PasswordStoreChangeList
* changes
) override
;
69 bool RemoveLoginsSyncedBetween(
70 base::Time delete_begin
,
71 base::Time delete_end
,
72 password_manager::PasswordStoreChangeList
* changes
) override
;
73 bool GetLogins(const autofill::PasswordForm
& form
,
74 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
75 bool GetAutofillableLogins(
76 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
77 bool GetBlacklistLogins(ScopedVector
<autofill::PasswordForm
>* forms
) override
;
80 enum TimestampToCompare
{
85 enum AddUpdateLoginSearchOptions
{
90 // Returns credentials matching |lookup_form| and |options|.
91 ScopedVector
<autofill::PasswordForm
> AddUpdateLoginSearch(
92 const autofill::PasswordForm
& lookup_form
,
93 AddUpdateLoginSearchOptions options
);
95 // Adds a login form without checking for one to replace first.
96 bool RawAddLogin(const autofill::PasswordForm
& form
);
98 enum GetLoginsListOptions
{
104 // Retrieves credentials matching |options| from the keyring into |forms|,
105 // overwriting the original contents of |forms|. If |lookup_form| is not NULL,
106 // only retrieves credentials PSL-matching it. Returns true on success.
107 bool GetLoginsList(const autofill::PasswordForm
* lookup_form
,
108 GetLoginsListOptions options
,
109 ScopedVector
<autofill::PasswordForm
>* forms
)
112 // Retrieves password created/synced in the time interval into |forms|,
113 // overwriting the original contents of |forms|. Returns true on success.
114 bool GetLoginsBetween(base::Time get_begin
,
116 TimestampToCompare date_to_compare
,
117 ScopedVector
<autofill::PasswordForm
>* forms
)
120 // Removes password created/synced in the time interval. Returns |true| if the
121 // operation succeeded. |changes| will contain the changes applied.
122 bool RemoveLoginsBetween(base::Time get_begin
,
124 TimestampToCompare date_to_compare
,
125 password_manager::PasswordStoreChangeList
* changes
);
127 // convert data get from Libsecret to Passwordform
128 ScopedVector
<autofill::PasswordForm
> ConvertFormList(
130 const autofill::PasswordForm
* lookup_form
);
132 // The app string, possibly based on the local profile id.
133 std::string app_string_
;
135 DISALLOW_COPY_AND_ASSIGN(NativeBackendLibsecret
);
138 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_LIBSECRET_H_