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

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

Issue 8509038: Linux: split GNOME Keyring integration into a separate process. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: merge Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
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
11 #include <string> 9 #include <string>
12 10
13 #include "base/basictypes.h" 11 #include "base/basictypes.h"
14 #include "base/time.h" 12 #include "base/time.h"
15 #include "chrome/browser/password_manager/password_store_x.h" 13 #include "chrome/browser/password_manager/password_store_x.h"
16 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
17 15
18 class PrefService; 16 class PrefService;
19 17
18 namespace keyring_proxy {
19 class KeyringProxyClient;
20 }
21
20 namespace webkit { 22 namespace webkit {
21 namespace forms { 23 namespace forms {
22 struct PasswordForm; 24 struct PasswordForm;
23 } 25 }
24 } 26 }
25 27
26 // Many of the gnome_keyring_* functions use variable arguments, which makes 28 // NativeBackend implementation using GNOME Keyring.
27 // them difficult if not impossible to truly wrap in C. Therefore, we use 29 class NativeBackendGnome : public PasswordStoreX::NativeBackend {
28 // appropriately-typed function pointers and scoping to make the fact that we 30 public:
29 // might be dynamically loading the library almost invisible. As a bonus, we 31 static const char kGnomeKeyringAppString[];
30 // also get a simple way to mock the library for testing. Classes that inherit
31 // from GnomeKeyringLoader will use its versions of the gnome_keyring_*
32 // functions. Note that it has only static fields.
33 class GnomeKeyringLoader {
34 protected:
35 static bool LoadGnomeKeyring();
36 32
37 // Call a given parameter with the name of each function we use from GNOME
38 // Keyring. Make sure to adjust the unit test if you change these.
39 #define GNOME_KEYRING_FOR_EACH_FUNC(F) \
40 F(is_available) \
41 F(store_password) \
42 F(delete_password) \
43 F(find_itemsv) \
44 F(result_to_message)
45
46 // Declare the actual function pointers that we'll use in client code.
47 #define GNOME_KEYRING_DECLARE_POINTER(name) \
48 static typeof(&::gnome_keyring_##name) gnome_keyring_##name;
49 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DECLARE_POINTER)
50 #undef GNOME_KEYRING_DECLARE_POINTER
51
52 // Set to true if LoadGnomeKeyring() has already succeeded.
53 static bool keyring_loaded;
54
55 private:
56 #if defined(DLOPEN_GNOME_KEYRING)
57 struct FunctionInfo {
58 const char* name;
59 void** pointer;
60 };
61
62 // Make it easy to initialize the function pointers in LoadGnomeKeyring().
63 static const FunctionInfo functions[];
64 #endif // defined(DLOPEN_GNOME_KEYRING)
65 };
66
67 // NativeBackend implementation using GNOME Keyring.
68 class NativeBackendGnome : public PasswordStoreX::NativeBackend,
69 public GnomeKeyringLoader {
70 public:
71 NativeBackendGnome(LocalProfileId id, PrefService* prefs); 33 NativeBackendGnome(LocalProfileId id, PrefService* prefs);
72 34
73 virtual ~NativeBackendGnome(); 35 virtual ~NativeBackendGnome();
74 36
75 virtual bool Init() OVERRIDE; 37 virtual bool Init() OVERRIDE;
76 38
77 // Implements NativeBackend interface. 39 // Implements NativeBackend interface.
78 virtual bool AddLogin(const webkit::forms::PasswordForm& form) OVERRIDE; 40 virtual bool AddLogin(const webkit::forms::PasswordForm& form) OVERRIDE;
79 virtual bool UpdateLogin(const webkit::forms::PasswordForm& form) OVERRIDE; 41 virtual bool UpdateLogin(const webkit::forms::PasswordForm& form) OVERRIDE;
80 virtual bool RemoveLogin(const webkit::forms::PasswordForm& form) OVERRIDE; 42 virtual bool RemoveLogin(const webkit::forms::PasswordForm& form) OVERRIDE;
81 virtual bool RemoveLoginsCreatedBetween( 43 virtual bool RemoveLoginsCreatedBetween(
82 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; 44 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
83 virtual bool GetLogins(const webkit::forms::PasswordForm& form, 45 virtual bool GetLogins(const webkit::forms::PasswordForm& form,
84 PasswordFormList* forms) OVERRIDE; 46 PasswordFormList* forms) OVERRIDE;
85 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin, 47 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin,
86 const base::Time& get_end, 48 const base::Time& get_end,
87 PasswordFormList* forms) OVERRIDE; 49 PasswordFormList* forms) OVERRIDE;
88 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE; 50 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE;
89 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE; 51 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE;
90 52
53 protected:
54 // Takes ownership of |client|. Use for testing only.
55 void InitForTesting(keyring_proxy::KeyringProxyClient* client);
56
91 private: 57 private:
92 // Adds a login form without checking for one to replace first. 58 // Adds a login form without checking for one to replace first.
93 bool RawAddLogin(const webkit::forms::PasswordForm& form); 59 bool RawAddLogin(const webkit::forms::PasswordForm& form);
94 60
95 // Reads PasswordForms from the keyring with the given autofillability state. 61 // Reads PasswordForms from the keyring with the given autofillability state.
96 bool GetLoginsList(PasswordFormList* forms, bool autofillable); 62 bool GetLoginsList(PasswordFormList* forms, bool autofillable);
97 63
98 // Helper for GetLoginsCreatedBetween(). 64 // Helper for GetLoginsCreatedBetween().
99 bool GetAllLogins(PasswordFormList* forms); 65 bool GetAllLogins(PasswordFormList* forms);
100 66
101 // Generates a profile-specific app string based on profile_id_. 67 // Generates a profile-specific app string based on profile_id_.
102 std::string GetProfileSpecificAppString() const; 68 std::string GetProfileSpecificAppString() const;
103 69
104 // Migrates non-profile-specific logins to be profile-specific. 70 // Migrates non-profile-specific logins to be profile-specific.
105 void MigrateToProfileSpecificLogins(); 71 void MigrateToProfileSpecificLogins();
106 72
107 // The local profile id, used to generate the app string. 73 // The local profile id, used to generate the app string.
108 const LocalProfileId profile_id_; 74 const LocalProfileId profile_id_;
109 75
110 // The pref service to use for persistent migration settings. 76 // The pref service to use for persistent migration settings.
111 PrefService* prefs_; 77 PrefService* prefs_;
112 78
113 // The app string, possibly based on the local profile id. 79 // The app string, possibly based on the local profile id.
114 std::string app_string_; 80 std::string app_string_;
115 81
116 // True once MigrateToProfileSpecificLogins() has been attempted. 82 // True once MigrateToProfileSpecificLogins() has been attempted.
117 bool migrate_tried_; 83 bool migrate_tried_;
118 84
85 // The keyring proxy client handles communicating with an out-of-process
86 // GNOME Keyring client, since to do it in-process we'd need to involve
87 // the UI thread which can lead to deadlocks with password sync.
88 scoped_ptr<keyring_proxy::KeyringProxyClient> proxy_client_;
89
119 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); 90 DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome);
120 }; 91 };
121 92
122 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_ 93 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698