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/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"
23 class LibsecretLoader
{
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
;
35 static bool LoadLibsecret();
36 static bool LibsecretIsAvailable();
38 static bool libsecret_loaded
;
46 static const FunctionInfo functions
[];
49 class NativeBackendLibsecret
: public PasswordStoreX::NativeBackend
,
50 public LibsecretLoader
{
52 explicit NativeBackendLibsecret(LocalProfileId id
);
54 ~NativeBackendLibsecret() 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
;
79 enum TimestampToCompare
{
84 enum AddUpdateLoginSearchOptions
{
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
{
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
,
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
,
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_