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