OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_GNOME_KEYRING_LOADER_H_ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_GNOME_KEYRING_LOADER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <gnome-keyring.h> |
| 10 |
| 11 #include <string> |
| 12 |
| 13 namespace keyring_proxy { |
| 14 |
| 15 // Many of the gnome_keyring_* functions use variable arguments, which makes |
| 16 // them difficult if not impossible to truly wrap in C/C++. Therefore, we use |
| 17 // appropriately-typed function pointers and scoping to make the fact that we |
| 18 // might be dynamically loading the library almost invisible. Classes that |
| 19 // inherit from GnomeKeyringLoader will use its versions of the gnome_keyring_* |
| 20 // functions. Note that it has only static fields. |
| 21 class GnomeKeyringLoader { |
| 22 protected: |
| 23 static bool LoadGnomeKeyring(); |
| 24 |
| 25 // Call a given parameter with the name of each function we use from GNOME |
| 26 // Keyring. Make sure to adjust the unit test if you change these. |
| 27 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \ |
| 28 F(is_available) \ |
| 29 F(store_password) \ |
| 30 F(delete_password) \ |
| 31 F(find_itemsv) \ |
| 32 F(result_to_message) |
| 33 |
| 34 // Declare the actual function pointers that we'll use in client code. |
| 35 #define GNOME_KEYRING_DECLARE_POINTER(name) \ |
| 36 static typeof(&::gnome_keyring_##name) gnome_keyring_##name; |
| 37 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DECLARE_POINTER) |
| 38 #undef GNOME_KEYRING_DECLARE_POINTER |
| 39 |
| 40 // Set to true if LoadGnomeKeyring() has already succeeded. |
| 41 static bool keyring_loaded; |
| 42 |
| 43 private: |
| 44 #if defined(DLOPEN_GNOME_KEYRING) |
| 45 struct FunctionInfo { |
| 46 const char* name; |
| 47 void** pointer; |
| 48 }; |
| 49 |
| 50 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). |
| 51 static const FunctionInfo functions[]; |
| 52 #endif // defined(DLOPEN_GNOME_KEYRING) |
| 53 }; |
| 54 |
| 55 } // namespace keyring_proxy |
| 56 |
| 57 #endif // CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_GNOME_KEYRING_LOADER_H_ |
OLD | NEW |