OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #ifndef COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
| 6 #define COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
| 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 "base/macros.h" |
| 21 |
| 22 // Many of the gnome_keyring_* functions use variable arguments, which makes |
| 23 // them difficult if not impossible to truly wrap in C. Therefore, we use |
| 24 // appropriately-typed function pointers and scoping to make the fact that we |
| 25 // might be dynamically loading the library almost invisible. As a bonus, we |
| 26 // also get a simple way to mock the library for testing. Classes that inherit |
| 27 // from GnomeKeyringLoader will use its versions of the gnome_keyring_* |
| 28 // functions. Note that it has only static fields. |
| 29 class GnomeKeyringLoader { |
| 30 protected: |
| 31 static bool LoadGnomeKeyring(); |
| 32 |
| 33 // Declare the actual function pointers that we'll use in client code. |
| 34 static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr; |
| 35 static decltype( |
| 36 &::gnome_keyring_store_password) gnome_keyring_store_password_ptr; |
| 37 static decltype( |
| 38 &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr; |
| 39 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr; |
| 40 static decltype( |
| 41 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr; |
| 42 static decltype(&::gnome_keyring_attribute_list_free) |
| 43 gnome_keyring_attribute_list_free_ptr; |
| 44 static decltype( |
| 45 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr; |
| 46 static decltype(&::gnome_keyring_attribute_list_append_string) |
| 47 gnome_keyring_attribute_list_append_string_ptr; |
| 48 static decltype(&::gnome_keyring_attribute_list_append_uint32) |
| 49 gnome_keyring_attribute_list_append_uint32_ptr; |
| 50 // We also use gnome_keyring_attribute_list_index(), which is a macro and |
| 51 // can't be referenced. |
| 52 |
| 53 // Set to true if LoadGnomeKeyring() has already succeeded. |
| 54 static bool keyring_loaded; |
| 55 |
| 56 private: |
| 57 struct FunctionInfo { |
| 58 const char* name; |
| 59 void** pointer; |
| 60 }; |
| 61 |
| 62 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). |
| 63 static const FunctionInfo functions[]; |
| 64 }; |
| 65 |
| 66 #endif // COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
OLD | NEW |