OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ | 5 #ifndef COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
6 #define COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ | 6 #define COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
7 | 7 |
8 // libgnome-keyring has been deprecated in favor of libsecret. | 8 // libgnome-keyring has been deprecated in favor of libsecret. |
9 // See: https://mail.gnome.org/archives/commits-list/2013-October/msg08876.html | 9 // See: https://mail.gnome.org/archives/commits-list/2013-October/msg08876.html |
10 // | 10 // |
11 // The define below turns off the deprecations, in order to avoid build | 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 | 12 // failures with Gnome 3.12. When we move to libsecret, the define can be |
13 // removed, together with the include below it. | 13 // removed, together with the include below it. |
14 // | 14 // |
15 // The porting is tracked in http://crbug.com/355223 | 15 // The porting is tracked in http://crbug.com/355223 |
16 #define GNOME_KEYRING_DEPRECATED | 16 #define GNOME_KEYRING_DEPRECATED |
17 #define GNOME_KEYRING_DEPRECATED_FOR(x) | 17 #define GNOME_KEYRING_DEPRECATED_FOR(x) |
18 #include <gnome-keyring.h> | 18 #include <gnome-keyring.h> |
19 | 19 |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 | 21 |
22 // Many of the gnome_keyring_* functions use variable arguments, which makes | 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 | 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 | 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 | 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 | 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_* | 27 // from GnomeKeyringLoader will use its versions of the gnome_keyring_* |
28 // functions. Note that it has only static fields. | 28 // functions. Note that it has only static fields. |
29 class GnomeKeyringLoader { | 29 class GnomeKeyringLoader { |
30 protected: | 30 public: |
31 static bool LoadGnomeKeyring(); | 31 static bool LoadGnomeKeyring(); |
32 | 32 |
33 // Declare the actual function pointers that we'll use in client code. | 33 // Declare the actual function pointers that we'll use in client code.\ |
| 34 // These functions may contact the keyring database. |
34 static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr; | 35 static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr; |
35 static decltype( | 36 static decltype( |
36 &::gnome_keyring_store_password) gnome_keyring_store_password_ptr; | 37 &::gnome_keyring_store_password) gnome_keyring_store_password_ptr; |
37 static decltype( | 38 static decltype( |
38 &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr; | 39 &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr; |
39 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr; | 40 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr; |
40 static decltype( | 41 static decltype( |
| 42 &::gnome_keyring_find_password_sync) gnome_keyring_find_password_sync_ptr; |
| 43 static decltype(&::gnome_keyring_store_password_sync) |
| 44 gnome_keyring_store_password_sync_ptr; |
| 45 |
| 46 // These functions are cheaper. |
| 47 static decltype( |
41 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr; | 48 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr; |
42 static decltype(&::gnome_keyring_attribute_list_free) | 49 static decltype(&::gnome_keyring_attribute_list_free) |
43 gnome_keyring_attribute_list_free_ptr; | 50 gnome_keyring_attribute_list_free_ptr; |
44 static decltype( | 51 static decltype( |
45 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr; | 52 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr; |
46 static decltype(&::gnome_keyring_attribute_list_append_string) | 53 static decltype(&::gnome_keyring_attribute_list_append_string) |
47 gnome_keyring_attribute_list_append_string_ptr; | 54 gnome_keyring_attribute_list_append_string_ptr; |
48 static decltype(&::gnome_keyring_attribute_list_append_uint32) | 55 static decltype(&::gnome_keyring_attribute_list_append_uint32) |
49 gnome_keyring_attribute_list_append_uint32_ptr; | 56 gnome_keyring_attribute_list_append_uint32_ptr; |
| 57 static decltype( |
| 58 &::gnome_keyring_free_password) gnome_keyring_free_password_ptr; |
50 // We also use gnome_keyring_attribute_list_index(), which is a macro and | 59 // We also use gnome_keyring_attribute_list_index(), which is a macro and |
51 // can't be referenced. | 60 // can't be referenced. |
52 | 61 |
| 62 protected: |
53 // Set to true if LoadGnomeKeyring() has already succeeded. | 63 // Set to true if LoadGnomeKeyring() has already succeeded. |
54 static bool keyring_loaded; | 64 static bool keyring_loaded; |
55 | 65 |
56 private: | 66 private: |
57 struct FunctionInfo { | 67 struct FunctionInfo { |
58 const char* name; | 68 const char* name; |
59 void** pointer; | 69 void** pointer; |
60 }; | 70 }; |
61 | 71 |
62 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). | 72 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). |
63 static const FunctionInfo functions[]; | 73 static const FunctionInfo functions[]; |
64 }; | 74 }; |
65 | 75 |
66 #endif // COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ | 76 #endif // COMPONENTS_OS_CRYPT_KEYRING_UTIL_LINUX_H_ |
OLD | NEW |