OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <gnome-keyring.h> |
| 10 |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
12 #include "base/time.h" | 14 #include "base/time.h" |
13 #include "chrome/browser/password_manager/password_store_x.h" | 15 #include "chrome/browser/password_manager/password_store_x.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 | 17 |
16 class PrefService; | 18 class PrefService; |
17 | 19 |
18 namespace webkit_glue { | 20 namespace webkit_glue { |
19 struct PasswordForm; | 21 struct PasswordForm; |
20 } | 22 } |
21 | 23 |
| 24 // Many of the gnome_keyring_* functions use variable arguments, which makes |
| 25 // them difficult if not impossible to truly wrap in C. Therefore, we use |
| 26 // appropriately-typed function pointers and scoping to make the fact that we |
| 27 // might be dynamically loading the library almost invisible. As a bonus, we |
| 28 // also get a simple way to mock the library for testing. Classes that inherit |
| 29 // from GnomeKeyringLoader will use its versions of the gnome_keyring_* |
| 30 // functions. Note that it has only static fields. |
| 31 class GnomeKeyringLoader { |
| 32 protected: |
| 33 static bool LoadGnomeKeyring(); |
| 34 |
| 35 // Call a given parameter with the name of each function we use from GNOME |
| 36 // Keyring. Make sure to adjust the unit test if you change these. |
| 37 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \ |
| 38 F(is_available) \ |
| 39 F(store_password) \ |
| 40 F(delete_password) \ |
| 41 F(find_itemsv) \ |
| 42 F(result_to_message) |
| 43 |
| 44 // Declare the actual function pointers that we'll use in client code. |
| 45 #define GNOME_KEYRING_DECLARE_POINTER(name) \ |
| 46 static typeof(&::gnome_keyring_##name) gnome_keyring_##name; |
| 47 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DECLARE_POINTER) |
| 48 #undef GNOME_KEYRING_DECLARE_POINTER |
| 49 |
| 50 // Set to true if LoadGnomeKeyring() has already succeeded. |
| 51 static bool keyring_loaded; |
| 52 |
| 53 private: |
| 54 #if defined(DLOPEN_GNOME_KEYRING) |
| 55 struct FunctionInfo { |
| 56 const char* name; |
| 57 void** pointer; |
| 58 }; |
| 59 |
| 60 // Make it easy to initialize the function pointers in LoadGnomeKeyring(). |
| 61 static const FunctionInfo functions[]; |
| 62 #endif // defined(DLOPEN_GNOME_KEYRING) |
| 63 }; |
| 64 |
22 // NativeBackend implementation using GNOME Keyring. | 65 // NativeBackend implementation using GNOME Keyring. |
23 class NativeBackendGnome : public PasswordStoreX::NativeBackend { | 66 class NativeBackendGnome : public PasswordStoreX::NativeBackend, |
| 67 public GnomeKeyringLoader { |
24 public: | 68 public: |
25 NativeBackendGnome(LocalProfileId id, PrefService* prefs); | 69 NativeBackendGnome(LocalProfileId id, PrefService* prefs); |
26 | 70 |
27 virtual ~NativeBackendGnome(); | 71 virtual ~NativeBackendGnome(); |
28 | 72 |
29 virtual bool Init(); | 73 virtual bool Init(); |
30 | 74 |
31 // Implements NativeBackend interface. | 75 // Implements NativeBackend interface. |
32 virtual bool AddLogin(const webkit_glue::PasswordForm& form); | 76 virtual bool AddLogin(const webkit_glue::PasswordForm& form); |
33 virtual bool UpdateLogin(const webkit_glue::PasswordForm& form); | 77 virtual bool UpdateLogin(const webkit_glue::PasswordForm& form); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // The app string, possibly based on the local profile id. | 111 // The app string, possibly based on the local profile id. |
68 std::string app_string_; | 112 std::string app_string_; |
69 | 113 |
70 // True once MigrateToProfileSpecificLogins() has been attempted. | 114 // True once MigrateToProfileSpecificLogins() has been attempted. |
71 bool migrate_tried_; | 115 bool migrate_tried_; |
72 | 116 |
73 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); | 117 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); |
74 }; | 118 }; |
75 | 119 |
76 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ | 120 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ |
OLD | NEW |