| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ |
| 7 | 7 |
| 8 // libgnome-keyring has been deprecated in favor of libsecret. | |
| 9 // See: https://mail.gnome.org/archives/commits-list/2013-October/msg08876.html | |
| 10 // | |
| 11 // The define below turns off the deprecations, in order to avoid build | |
| 12 // failures with Gnome 3.12. When we move to libsecret, the define can be | |
| 13 // removed, together with the include below it. | |
| 14 // | |
| 15 // The porting is tracked in http://crbug.com/355223 | |
| 16 #define GNOME_KEYRING_DEPRECATED | |
| 17 #define GNOME_KEYRING_DEPRECATED_FOR(x) | |
| 18 #include <gnome-keyring.h> | |
| 19 | |
| 20 #include <string> | 8 #include <string> |
| 21 | 9 |
| 22 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 23 #include "base/macros.h" | 11 #include "base/macros.h" |
| 24 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 25 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 26 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
| 27 #include "chrome/browser/password_manager/password_store_x.h" | 15 #include "chrome/browser/password_manager/password_store_x.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "components/os_crypt/keyring_util_linux.h" |
| 29 | 18 |
| 30 namespace autofill { | 19 namespace autofill { |
| 31 struct PasswordForm; | 20 struct PasswordForm; |
| 32 } | 21 } |
| 33 | 22 |
| 34 // Many of the gnome_keyring_* functions use variable arguments, which makes | |
| 35 // them difficult if not impossible to truly wrap in C. Therefore, we use | |
| 36 // appropriately-typed function pointers and scoping to make the fact that we | |
| 37 // might be dynamically loading the library almost invisible. As a bonus, we | |
| 38 // also get a simple way to mock the library for testing. Classes that inherit | |
| 39 // from GnomeKeyringLoader will use its versions of the gnome_keyring_* | |
| 40 // functions. Note that it has only static fields. | |
| 41 class GnomeKeyringLoader { | |
| 42 protected: | |
| 43 static bool LoadGnomeKeyring(); | |
| 44 | |
| 45 // Declare the actual function pointers that we'll use in client code. | |
| 46 static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr; | |
| 47 static decltype( | |
| 48 &::gnome_keyring_store_password) gnome_keyring_store_password_ptr; | |
| 49 static decltype( | |
| 50 &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr; | |
| 51 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr; | |
| 52 static decltype( | |
| 53 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr; | |
| 54 static decltype(&::gnome_keyring_attribute_list_free) | |
| 55 gnome_keyring_attribute_list_free_ptr; | |
| 56 static decltype( | |
| 57 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr; | |
| 58 static decltype(&::gnome_keyring_attribute_list_append_string) | |
| 59 gnome_keyring_attribute_list_append_string_ptr; | |
| 60 static decltype(&::gnome_keyring_attribute_list_append_uint32) | |
| 61 gnome_keyring_attribute_list_append_uint32_ptr; | |
| 62 // We also use gnome_keyring_attribute_list_index(), which is a macro and | |
| 63 // can't be referenced. | |
| 64 | |
| 65 // Set to true if LoadGnomeKeyring() has already succeeded. | |
| 66 static bool keyring_loaded; | |
| 67 | |
| 68 private: | |
| 69 struct FunctionInfo { | |
| 70 const char* name; | |
| 71 void** pointer; | |
| 72 }; | |
| 73 | |
| 74 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). | |
| 75 static const FunctionInfo functions[]; | |
| 76 }; | |
| 77 | |
| 78 // NativeBackend implementation using GNOME Keyring. | 23 // NativeBackend implementation using GNOME Keyring. |
| 79 class NativeBackendGnome : public PasswordStoreX::NativeBackend, | 24 class NativeBackendGnome : public PasswordStoreX::NativeBackend, |
| 80 public GnomeKeyringLoader { | 25 public GnomeKeyringLoader { |
| 81 public: | 26 public: |
| 82 explicit NativeBackendGnome(LocalProfileId id); | 27 explicit NativeBackendGnome(LocalProfileId id); |
| 83 | 28 |
| 84 ~NativeBackendGnome() override; | 29 ~NativeBackendGnome() override; |
| 85 | 30 |
| 86 bool Init() override; | 31 bool Init() override; |
| 87 | 32 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 TimestampToCompare date_to_compare, | 86 TimestampToCompare date_to_compare, |
| 142 password_manager::PasswordStoreChangeList* changes); | 87 password_manager::PasswordStoreChangeList* changes); |
| 143 | 88 |
| 144 // The app string, possibly based on the local profile id. | 89 // The app string, possibly based on the local profile id. |
| 145 std::string app_string_; | 90 std::string app_string_; |
| 146 | 91 |
| 147 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); | 92 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); |
| 148 }; | 93 }; |
| 149 | 94 |
| 150 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ | 95 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ |
| OLD | NEW |