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. | 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 // |
(...skipping 24 matching lines...) Expand all Loading... |
35 // them difficult if not impossible to truly wrap in C. Therefore, we use | 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 | 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 | 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 | 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_* | 39 // from GnomeKeyringLoader will use its versions of the gnome_keyring_* |
40 // functions. Note that it has only static fields. | 40 // functions. Note that it has only static fields. |
41 class GnomeKeyringLoader { | 41 class GnomeKeyringLoader { |
42 protected: | 42 protected: |
43 static bool LoadGnomeKeyring(); | 43 static bool LoadGnomeKeyring(); |
44 | 44 |
45 // Call a given parameter with the name of each function we use from GNOME | 45 // Declare the actual function pointers that we'll use in client code. |
46 // Keyring. Make sure to adjust the unit test if you change these. | 46 static decltype(&::gnome_keyring_is_available) gnome_keyring_is_available_ptr; |
47 // The list of functions is divided into those we plan to mock in the unittest, | 47 static decltype( |
48 // and those which we use without mocking in the test. | 48 &::gnome_keyring_store_password) gnome_keyring_store_password_ptr; |
49 #define GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F) \ | 49 static decltype( |
50 F(is_available) \ | 50 &::gnome_keyring_delete_password) gnome_keyring_delete_password_ptr; |
51 F(store_password) \ | 51 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items_ptr; |
52 F(delete_password) \ | 52 static decltype( |
53 F(find_items) \ | 53 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message_ptr; |
54 F(result_to_message) | 54 static decltype(&::gnome_keyring_attribute_list_free) |
55 #define GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \ | 55 gnome_keyring_attribute_list_free_ptr; |
56 F(attribute_list_free) \ | 56 static decltype( |
57 F(attribute_list_new) \ | 57 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new_ptr; |
58 F(attribute_list_append_string) \ | 58 static decltype(&::gnome_keyring_attribute_list_append_string) |
59 F(attribute_list_append_uint32) | 59 gnome_keyring_attribute_list_append_string_ptr; |
60 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \ | 60 static decltype(&::gnome_keyring_attribute_list_append_uint32) |
61 GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \ | 61 gnome_keyring_attribute_list_append_uint32_ptr; |
62 GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F) | 62 // We also use gnome_keyring_attribute_list_index(), which is a macro and |
63 | 63 // can't be referenced. |
64 // Declare the actual function pointers that we'll use in client code. | |
65 #define GNOME_KEYRING_DECLARE_POINTER(name) \ | |
66 static decltype(&::gnome_keyring_##name) gnome_keyring_##name; | |
67 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DECLARE_POINTER) | |
68 #undef GNOME_KEYRING_DECLARE_POINTER | |
69 | 64 |
70 // Set to true if LoadGnomeKeyring() has already succeeded. | 65 // Set to true if LoadGnomeKeyring() has already succeeded. |
71 static bool keyring_loaded; | 66 static bool keyring_loaded; |
72 | 67 |
73 private: | 68 private: |
74 struct FunctionInfo { | 69 struct FunctionInfo { |
75 const char* name; | 70 const char* name; |
76 void** pointer; | 71 void** pointer; |
77 }; | 72 }; |
78 | 73 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 TimestampToCompare date_to_compare, | 141 TimestampToCompare date_to_compare, |
147 password_manager::PasswordStoreChangeList* changes); | 142 password_manager::PasswordStoreChangeList* changes); |
148 | 143 |
149 // The app string, possibly based on the local profile id. | 144 // The app string, possibly based on the local profile id. |
150 std::string app_string_; | 145 std::string app_string_; |
151 | 146 |
152 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); | 147 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); |
153 }; | 148 }; |
154 | 149 |
155 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ | 150 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ |
OLD | NEW |