Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_x.h

Issue 2196193002: Expanded GnomeKeyringLoader macros (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unnecessary null termination Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
vasilii 2016/08/01 09:51:26 Do you deliberately reuse the same names?
cfroussios 2016/08/01 10:54:52 That's the names that the macros would produce. Ar
vasilii 2016/08/01 11:46:37 I'd use gnome_keyring_is_available_ptr. I'm totall
cfroussios 2016/08/01 14:31:04 I used ptr. I didn't get rid of the prefix, becaus
47 // The list of functions is divided into those we plan to mock in the unittest, 47 static decltype(&::gnome_keyring_store_password) gnome_keyring_store_password;
48 // and those which we use without mocking in the test. 48 static decltype(
49 #define GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F) \ 49 &::gnome_keyring_delete_password) gnome_keyring_delete_password;
50 F(is_available) \ 50 static decltype(&::gnome_keyring_find_items) gnome_keyring_find_items;
51 F(store_password) \ 51 static decltype(
52 F(delete_password) \ 52 &::gnome_keyring_result_to_message) gnome_keyring_result_to_message;
53 F(find_items) \ 53 static decltype(
54 F(result_to_message) 54 &::gnome_keyring_attribute_list_free) gnome_keyring_attribute_list_free;
55 #define GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \ 55 static decltype(
56 F(attribute_list_free) \ 56 &::gnome_keyring_attribute_list_new) gnome_keyring_attribute_list_new;
57 F(attribute_list_new) \ 57 static decltype(&::gnome_keyring_attribute_list_append_string)
58 F(attribute_list_append_string) \ 58 gnome_keyring_attribute_list_append_string;
59 F(attribute_list_append_uint32) 59 static decltype(&::gnome_keyring_attribute_list_append_uint32)
60 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \ 60 gnome_keyring_attribute_list_append_uint32;
61 GNOME_KEYRING_FOR_EACH_NON_MOCKED_FUNC(F) \
62 GNOME_KEYRING_FOR_EACH_MOCKED_FUNC(F)
63
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 61
70 // Set to true if LoadGnomeKeyring() has already succeeded. 62 // Set to true if LoadGnomeKeyring() has already succeeded.
71 static bool keyring_loaded; 63 static bool keyring_loaded;
72 64
73 private: 65 private:
74 struct FunctionInfo { 66 struct FunctionInfo {
75 const char* name; 67 const char* name;
76 void** pointer; 68 void** pointer;
77 }; 69 };
78 70
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 TimestampToCompare date_to_compare, 138 TimestampToCompare date_to_compare,
147 password_manager::PasswordStoreChangeList* changes); 139 password_manager::PasswordStoreChangeList* changes);
148 140
149 // The app string, possibly based on the local profile id. 141 // The app string, possibly based on the local profile id.
150 std::string app_string_; 142 std::string app_string_;
151 143
152 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); 144 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome);
153 }; 145 };
154 146
155 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ 147 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698