Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / password_manager / native_backend_libsecret.h
blob3acc55f61e169abf87abe69f20cb3ab090ec107c
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/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"
20 namespace autofill {
21 struct PasswordForm;
24 class LibsecretLoader {
25 public:
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;
35 protected:
36 static bool LoadLibsecret();
37 static bool LibsecretIsAvailable();
39 static bool libsecret_loaded;
41 private:
42 struct FunctionInfo {
43 const char* name;
44 void** pointer;
47 static const FunctionInfo functions[];
50 class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
51 public LibsecretLoader {
52 public:
53 explicit NativeBackendLibsecret(LocalProfileId id);
55 ~NativeBackendLibsecret() override;
57 bool Init() 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,
65 password_manager::PasswordStoreChangeList* changes) override;
66 bool RemoveLoginsCreatedBetween(
67 base::Time delete_begin,
68 base::Time delete_end,
69 password_manager::PasswordStoreChangeList* changes) override;
70 bool RemoveLoginsSyncedBetween(
71 base::Time delete_begin,
72 base::Time delete_end,
73 password_manager::PasswordStoreChangeList* changes) override;
74 bool GetLogins(const autofill::PasswordForm& form,
75 ScopedVector<autofill::PasswordForm>* forms) override;
76 bool GetAutofillableLogins(
77 ScopedVector<autofill::PasswordForm>* forms) override;
78 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
80 private:
81 enum TimestampToCompare {
82 CREATION_TIMESTAMP,
83 SYNC_TIMESTAMP,
86 // Returns credentials matching |lookup_form| via |forms|.
87 bool AddUpdateLoginSearch(
88 const autofill::PasswordForm& lookup_form,
89 ScopedVector<autofill::PasswordForm>* forms);
91 // Adds a login form without checking for one to replace first.
92 bool RawAddLogin(const autofill::PasswordForm& form);
94 enum GetLoginsListOptions {
95 ALL_LOGINS,
96 AUTOFILLABLE_LOGINS,
97 BLACKLISTED_LOGINS,
100 // Retrieves credentials matching |options| from the keyring into |forms|,
101 // overwriting the original contents of |forms|. If |lookup_form| is not NULL,
102 // only retrieves credentials PSL-matching it. Returns true on success.
103 bool GetLoginsList(const autofill::PasswordForm* lookup_form,
104 GetLoginsListOptions options,
105 ScopedVector<autofill::PasswordForm>* forms)
106 WARN_UNUSED_RESULT;
108 // Retrieves password created/synced in the time interval into |forms|,
109 // overwriting the original contents of |forms|. Returns true on success.
110 bool GetLoginsBetween(base::Time get_begin,
111 base::Time get_end,
112 TimestampToCompare date_to_compare,
113 ScopedVector<autofill::PasswordForm>* forms)
114 WARN_UNUSED_RESULT;
116 // Removes password created/synced in the time interval. Returns |true| if the
117 // operation succeeded. |changes| will contain the changes applied.
118 bool RemoveLoginsBetween(base::Time get_begin,
119 base::Time get_end,
120 TimestampToCompare date_to_compare,
121 password_manager::PasswordStoreChangeList* changes);
123 // convert data get from Libsecret to Passwordform
124 ScopedVector<autofill::PasswordForm> ConvertFormList(
125 GList* found,
126 const autofill::PasswordForm* lookup_form);
128 // The app string, possibly based on the local profile id.
129 std::string app_string_;
131 DISALLOW_COPY_AND_ASSIGN(NativeBackendLibsecret);
134 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_LIBSECRET_H_