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

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

Issue 7835021: Linux: use our spiffy new DBus client library for KWallet, instead of dbus-glib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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_KWALLET_X_H_ 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ 6 #define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_
7 #pragma once 7 #pragma once
8 8
9 #include <dbus/dbus-glib.h>
10 #include <glib.h>
11
12 #include <string> 9 #include <string>
13 10
14 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
15 #include "base/time.h" 13 #include "base/time.h"
16 #include "chrome/browser/password_manager/password_store_x.h" 14 #include "chrome/browser/password_manager/password_store_x.h"
17 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
18 16
19 class Pickle; 17 class Pickle;
20 class PrefService; 18 class PrefService;
21 19
22 namespace webkit_glue { 20 namespace webkit_glue {
23 struct PasswordForm; 21 struct PasswordForm;
24 } 22 }
25 23
24 namespace base {
25 class WaitableEvent;
26 }
27
28 namespace dbus {
29 class Bus;
30 class ObjectProxy;
31 }
32
26 // NativeBackend implementation using KWallet. 33 // NativeBackend implementation using KWallet.
27 class NativeBackendKWallet : public PasswordStoreX::NativeBackend { 34 class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
28 public: 35 public:
29 NativeBackendKWallet(LocalProfileId id, PrefService* prefs); 36 NativeBackendKWallet(LocalProfileId id, PrefService* prefs);
30 37
31 virtual ~NativeBackendKWallet(); 38 virtual ~NativeBackendKWallet();
32 39
33 virtual bool Init() OVERRIDE; 40 virtual bool Init() OVERRIDE;
34 41
35 // Implements NativeBackend interface. 42 // Implements NativeBackend interface.
36 virtual bool AddLogin(const webkit_glue::PasswordForm& form) OVERRIDE; 43 virtual bool AddLogin(const webkit_glue::PasswordForm& form) OVERRIDE;
37 virtual bool UpdateLogin(const webkit_glue::PasswordForm& form) OVERRIDE; 44 virtual bool UpdateLogin(const webkit_glue::PasswordForm& form) OVERRIDE;
38 virtual bool RemoveLogin(const webkit_glue::PasswordForm& form) OVERRIDE; 45 virtual bool RemoveLogin(const webkit_glue::PasswordForm& form) OVERRIDE;
39 virtual bool RemoveLoginsCreatedBetween( 46 virtual bool RemoveLoginsCreatedBetween(
40 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; 47 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
41 virtual bool GetLogins(const webkit_glue::PasswordForm& form, 48 virtual bool GetLogins(const webkit_glue::PasswordForm& form,
42 PasswordFormList* forms) OVERRIDE; 49 PasswordFormList* forms) OVERRIDE;
43 virtual bool GetLoginsCreatedBetween(const base::Time& delete_begin, 50 virtual bool GetLoginsCreatedBetween(const base::Time& delete_begin,
44 const base::Time& delete_end, 51 const base::Time& delete_end,
45 PasswordFormList* forms) OVERRIDE; 52 PasswordFormList* forms) OVERRIDE;
46 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE; 53 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE;
47 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE; 54 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE;
48 55
56 protected:
57 // Internally used by Init(), but also for testing to provide a mock bus.
58 void InitWithBus(scoped_refptr<dbus::Bus> optional_bus,
59 base::WaitableEvent* event,
60 bool* success);
61
49 private: 62 private:
50 // Initialization. 63 // Initialization.
51 bool StartKWalletd(); 64 bool StartKWalletd();
52 bool InitWallet(); 65 bool InitWallet();
53 66
54 // Reads PasswordForms from the wallet that match the given signon_realm. 67 // Reads PasswordForms from the wallet that match the given signon_realm.
55 bool GetLoginsList(PasswordFormList* forms, 68 bool GetLoginsList(PasswordFormList* forms,
56 const std::string& signon_realm, 69 const std::string& signon_realm,
57 int wallet_handle); 70 int wallet_handle);
58 71
(...skipping 11 matching lines...) Expand all
70 // Helper for some of the above GetLoginsList() methods. 83 // Helper for some of the above GetLoginsList() methods.
71 bool GetAllLogins(PasswordFormList* forms, int wallet_handle); 84 bool GetAllLogins(PasswordFormList* forms, int wallet_handle);
72 85
73 // Writes a list of PasswordForms to the wallet with the given signon_realm. 86 // Writes a list of PasswordForms to the wallet with the given signon_realm.
74 // Overwrites any existing list for this signon_realm. Removes the entry if 87 // Overwrites any existing list for this signon_realm. Removes the entry if
75 // |forms| is empty. Returns true on success. 88 // |forms| is empty. Returns true on success.
76 bool SetLoginsList(const PasswordFormList& forms, 89 bool SetLoginsList(const PasswordFormList& forms,
77 const std::string& signon_realm, 90 const std::string& signon_realm,
78 int wallet_handle); 91 int wallet_handle);
79 92
80 // Checks if the last DBus call returned an error. If it did, logs the error
81 // message, frees it and returns true.
82 // This must be called after every DBus call.
83 bool CheckError();
84
85 // Opens the wallet and ensures that the "Chrome Form Data" folder exists. 93 // Opens the wallet and ensures that the "Chrome Form Data" folder exists.
86 // Returns kInvalidWalletHandle on error. 94 // Returns kInvalidWalletHandle on error.
87 int WalletHandle(); 95 int WalletHandle();
88 96
89 // Compares two PasswordForms and returns true if they are the same. 97 // Compares two PasswordForms and returns true if they are the same.
90 // If |update_check| is false, we only check the fields that are checked by 98 // If |update_check| is false, we only check the fields that are checked by
91 // LoginDatabase::UpdateLogin() when updating logins; otherwise, we check the 99 // LoginDatabase::UpdateLogin() when updating logins; otherwise, we check the
92 // fields that are checked by LoginDatabase::RemoveLogin() for removing them. 100 // fields that are checked by LoginDatabase::RemoveLogin() for removing them.
93 static bool CompareForms(const webkit_glue::PasswordForm& a, 101 static bool CompareForms(const webkit_glue::PasswordForm& a,
94 const webkit_glue::PasswordForm& b, 102 const webkit_glue::PasswordForm& b,
95 bool update_check); 103 bool update_check);
96 104
97 // Serializes a list of PasswordForms to be stored in the wallet. 105 // Serializes a list of PasswordForms to be stored in the wallet.
98 static void SerializeValue(const PasswordFormList& forms, Pickle* pickle); 106 static void SerializeValue(const PasswordFormList& forms, Pickle* pickle);
99 107
100 // Checks a serialized list of PasswordForms for sanity. Returns true if OK. 108 // Checks a serialized list of PasswordForms for sanity. Returns true if OK.
101 // Note that |realm| is only used for generating a useful warning message. 109 // Note that |realm| is only used for generating a useful warning message.
102 static bool CheckSerializedValue(const GArray* byte_array, const char* realm); 110 static bool CheckSerializedValue(const uint8_t* byte_array, size_t length,
111 const std::string& realm);
103 112
104 // Deserializes a list of PasswordForms from the wallet. 113 // Deserializes a list of PasswordForms from the wallet.
105 static void DeserializeValue(const std::string& signon_realm, 114 static void DeserializeValue(const std::string& signon_realm,
106 const Pickle& pickle, 115 const Pickle& pickle,
107 PasswordFormList* forms); 116 PasswordFormList* forms);
108 117
109 // Convenience function to read a GURL from a Pickle. Assumes the URL has 118 // Convenience function to read a GURL from a Pickle. Assumes the URL has
110 // been written as a std::string. Returns true on success. 119 // been written as a std::string. Returns true on success.
111 static bool ReadGURL(const Pickle& pickle, void** iter, GURL* url); 120 static bool ReadGURL(const Pickle& pickle, void** iter, GURL* url);
112 121
113 // In case the fields in the pickle ever change, version them so we can try to 122 // In case the fields in the pickle ever change, version them so we can try to
114 // read old pickles. (Note: do not eat old pickles past the expiration date.) 123 // read old pickles. (Note: do not eat old pickles past the expiration date.)
115 static const int kPickleVersion = 0; 124 static const int kPickleVersion = 0;
116 125
117 // Name of the folder to store passwords in. 126 // Name of the folder to store passwords in.
118 static const char kKWalletFolder[]; 127 static const char kKWalletFolder[];
119 128
120 // DBus stuff. 129 // DBus service, path, and interface names for klauncher and kwalletd.
121 static const char kKWalletServiceName[]; 130 static const char kKWalletServiceName[];
122 static const char kKWalletPath[]; 131 static const char kKWalletPath[];
123 static const char kKWalletInterface[]; 132 static const char kKWalletInterface[];
124 static const char kKLauncherServiceName[]; 133 static const char kKLauncherServiceName[];
125 static const char kKLauncherPath[]; 134 static const char kKLauncherPath[];
126 static const char kKLauncherInterface[]; 135 static const char kKLauncherInterface[];
127 136
128 // Invalid handle returned by WalletHandle(). 137 // Invalid handle returned by WalletHandle().
129 static const int kInvalidKWalletHandle = -1; 138 static const int kInvalidKWalletHandle = -1;
130 139
131 // Generates a profile-specific folder name based on profile_id_. 140 // Generates a profile-specific folder name based on profile_id_.
132 std::string GetProfileSpecificFolderName() const; 141 std::string GetProfileSpecificFolderName() const;
133 142
134 // Migrates non-profile-specific logins to be profile-specific. 143 // Migrates non-profile-specific logins to be profile-specific.
135 void MigrateToProfileSpecificLogins(); 144 void MigrateToProfileSpecificLogins();
136 145
137 // The local profile id, used to generate the folder name. 146 // The local profile id, used to generate the folder name.
138 const LocalProfileId profile_id_; 147 const LocalProfileId profile_id_;
139 148
140 // The pref service to use for persistent migration settings. 149 // The pref service to use for persistent migration settings.
141 PrefService* prefs_; 150 PrefService* prefs_;
142 151
143 // The KWallet folder name, possibly based on the local profile id. 152 // The KWallet folder name, possibly based on the local profile id.
144 std::string folder_name_; 153 std::string folder_name_;
145 154
146 // True once MigrateToProfileSpecificLogins() has been attempted. 155 // True once MigrateToProfileSpecificLogins() has been attempted.
147 bool migrate_tried_; 156 bool migrate_tried_;
148 157
149 // Error from the last DBus call. NULL when there's no error. Freed and 158 // DBus handle for communication with klauncher and kwalletd.
150 // cleared by CheckError(). 159 scoped_refptr<dbus::Bus> session_bus_;
151 GError* error_; 160 // Object proxy for kwalletd. We do not own this.
152 // Connection to the DBus session bus. 161 dbus::ObjectProxy* kwallet_proxy_;
153 DBusGConnection* connection_;
154 // Proxy to the kwallet DBus service.
155 DBusGProxy* proxy_;
156 162
157 // The name of the wallet we've opened. Set during Init(). 163 // The name of the wallet we've opened. Set during Init().
158 std::string wallet_name_; 164 std::string wallet_name_;
159 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs. 165 // The application name (e.g. "Chromium"), shown in KWallet auth dialogs.
160 const std::string app_name_; 166 const std::string app_name_;
161 167
162 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet); 168 DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet);
163 }; 169 };
164 170
165 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_ 171 #endif // CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_KWALLET_X_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/DEPS ('k') | chrome/browser/password_manager/native_backend_kwallet_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698