| Index: chrome/browser/password_manager/native_backend_gnome_x.cc
|
| ===================================================================
|
| --- chrome/browser/password_manager/native_backend_gnome_x.cc (revision 119287)
|
| +++ chrome/browser/password_manager/native_backend_gnome_x.cc (working copy)
|
| @@ -4,416 +4,33 @@
|
|
|
| #include "chrome/browser/password_manager/native_backend_gnome_x.h"
|
|
|
| -#include <dlfcn.h>
|
| #include <gnome-keyring.h>
|
|
|
| -#include <map>
|
| #include <string>
|
| -#include <vector>
|
|
|
| #include "base/logging.h"
|
| #include "base/string_number_conversions.h"
|
| -#include "base/string_piece.h"
|
| -#include "base/string_util.h"
|
| #include "base/stringprintf.h"
|
| -#include "base/synchronization/waitable_event.h"
|
| -#include "base/time.h"
|
| -#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/password_manager/keyring_proxy/keyring_proxy_client.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| using content::BrowserThread;
|
| +using keyring_proxy::KeyringProxyClient;
|
| using webkit::forms::PasswordForm;
|
|
|
| -#define GNOME_KEYRING_DEFINE_POINTER(name) \
|
| - typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name;
|
| -GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER)
|
| -#undef GNOME_KEYRING_DEFINE_POINTER
|
| +const char NativeBackendGnome::kGnomeKeyringAppString[] = "chrome";
|
|
|
| -bool GnomeKeyringLoader::keyring_loaded = false;
|
| -
|
| -#if defined(DLOPEN_GNOME_KEYRING)
|
| -
|
| -#define GNOME_KEYRING_FUNCTION_INFO(name) \
|
| - {"gnome_keyring_"#name, reinterpret_cast<void**>(&gnome_keyring_##name)},
|
| -const GnomeKeyringLoader::FunctionInfo GnomeKeyringLoader::functions[] = {
|
| - GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_FUNCTION_INFO)
|
| - {NULL, NULL}
|
| -};
|
| -#undef GNOME_KEYRING_FUNCTION_INFO
|
| -
|
| -/* Load the library and initialize the function pointers. */
|
| -bool GnomeKeyringLoader::LoadGnomeKeyring() {
|
| - if (keyring_loaded)
|
| - return true;
|
| -
|
| - void* handle = dlopen("libgnome-keyring.so.0", RTLD_NOW | RTLD_GLOBAL);
|
| - if (!handle) {
|
| - // We wanted to use GNOME Keyring, but we couldn't load it. Warn, because
|
| - // either the user asked for this, or we autodetected it incorrectly. (Or
|
| - // the system has broken libraries, which is also good to warn about.)
|
| - LOG(WARNING) << "Could not load libgnome-keyring.so.0: " << dlerror();
|
| - return false;
|
| - }
|
| -
|
| - for (size_t i = 0; functions[i].name; ++i) {
|
| - dlerror();
|
| - *functions[i].pointer = dlsym(handle, functions[i].name);
|
| - const char* error = dlerror();
|
| - if (error) {
|
| - LOG(ERROR) << "Unable to load symbol "
|
| - << functions[i].name << ": " << error;
|
| - dlclose(handle);
|
| - return false;
|
| - }
|
| - }
|
| -
|
| - keyring_loaded = true;
|
| - // We leak the library handle. That's OK: this function is called only once.
|
| - return true;
|
| -}
|
| -
|
| -#else // defined(DLOPEN_GNOME_KEYRING)
|
| -
|
| -bool GnomeKeyringLoader::LoadGnomeKeyring() {
|
| - if (keyring_loaded)
|
| - return true;
|
| -#define GNOME_KEYRING_ASSIGN_POINTER(name) \
|
| - gnome_keyring_##name = &::gnome_keyring_##name;
|
| - GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER)
|
| -#undef GNOME_KEYRING_ASSIGN_POINTER
|
| - keyring_loaded = true;
|
| - return true;
|
| -}
|
| -
|
| -#endif // defined(DLOPEN_GNOME_KEYRING)
|
| -
|
| -namespace {
|
| -
|
| -const char kGnomeKeyringAppString[] = "chrome";
|
| -
|
| -// Convert the attributes of a given keyring entry into a new PasswordForm.
|
| -// Note: does *not* get the actual password, as that is not a key attribute!
|
| -// Returns NULL if the attributes are for the wrong application.
|
| -PasswordForm* FormFromAttributes(GnomeKeyringAttributeList* attrs) {
|
| - // Read the string and int attributes into the appropriate map.
|
| - std::map<std::string, std::string> string_attr_map;
|
| - std::map<std::string, uint32_t> uint_attr_map;
|
| - for (guint i = 0; i < attrs->len; ++i) {
|
| - GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index(attrs, i);
|
| - if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)
|
| - string_attr_map[attr.name] = attr.value.string;
|
| - else if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32)
|
| - uint_attr_map[attr.name] = attr.value.integer;
|
| - }
|
| - // Check to make sure this is a password we care about.
|
| - const std::string& app_value = string_attr_map["application"];
|
| - if (!base::StringPiece(app_value).starts_with(kGnomeKeyringAppString))
|
| - return NULL;
|
| -
|
| - PasswordForm* form = new PasswordForm();
|
| - form->origin = GURL(string_attr_map["origin_url"]);
|
| - form->action = GURL(string_attr_map["action_url"]);
|
| - form->username_element = UTF8ToUTF16(string_attr_map["username_element"]);
|
| - form->username_value = UTF8ToUTF16(string_attr_map["username_value"]);
|
| - form->password_element = UTF8ToUTF16(string_attr_map["password_element"]);
|
| - form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]);
|
| - form->signon_realm = string_attr_map["signon_realm"];
|
| - form->ssl_valid = uint_attr_map["ssl_valid"];
|
| - form->preferred = uint_attr_map["preferred"];
|
| - int64 date_created = 0;
|
| - bool date_ok = base::StringToInt64(string_attr_map["date_created"],
|
| - &date_created);
|
| - DCHECK(date_ok);
|
| - form->date_created = base::Time::FromTimeT(date_created);
|
| - form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"];
|
| - form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]);
|
| -
|
| - return form;
|
| -}
|
| -
|
| -// Parse all the results from the given GList into a PasswordFormList, and free
|
| -// the GList. PasswordForms are allocated on the heap, and should be deleted by
|
| -// the consumer.
|
| -void ConvertFormList(GList* found,
|
| - NativeBackendGnome::PasswordFormList* forms) {
|
| - GList* element = g_list_first(found);
|
| - while (element != NULL) {
|
| - GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data);
|
| - GnomeKeyringAttributeList* attrs = data->attributes;
|
| -
|
| - PasswordForm* form = FormFromAttributes(attrs);
|
| - if (form) {
|
| - if (data->secret) {
|
| - form->password_value = UTF8ToUTF16(data->secret);
|
| - } else {
|
| - LOG(WARNING) << "Unable to access password from list element!";
|
| - }
|
| - forms->push_back(form);
|
| - } else {
|
| - LOG(WARNING) << "Could not initialize PasswordForm from attributes!";
|
| - }
|
| -
|
| - element = g_list_next(element);
|
| - }
|
| -}
|
| -
|
| -// Schema is analagous to the fields in PasswordForm.
|
| -const GnomeKeyringPasswordSchema kGnomeSchema = {
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET, {
|
| - { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "submit_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "ssl_valid", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
|
| - { "preferred", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
|
| - { "date_created", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { "blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
|
| - { "scheme", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
|
| - // This field is always "chrome" so that we can search for it.
|
| - { "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
|
| - { NULL }
|
| - }
|
| -};
|
| -
|
| // Sadly, PasswordStore goes to great lengths to switch from the originally
|
| // calling thread to the DB thread, and to provide an asynchronous API to
|
| // callers while using a synchronous (virtual) API provided by subclasses like
|
| // PasswordStoreX -- but GNOME Keyring really wants to be on the GLib main
|
| -// thread, which is the UI thread to us. So we end up having to switch threads
|
| -// again, possibly back to the very same thread (in case the UI thread is the
|
| -// caller, e.g. in the password management UI), and *block* the DB thread
|
| -// waiting for a response from the UI thread to provide the synchronous API
|
| -// PasswordStore expects of us. (It will then in turn switch back to the
|
| -// original caller to send the asynchronous reply to the original request.)
|
| +// thread, which is the UI thread to us. We used to send a message to the UI
|
| +// thread and then wait for it, but that could cause deadlocks with password
|
| +// sync which blocks the UI thread (!) for some operations. To avoid this, we
|
| +// start a small proxy process with its own GLib main thread and talk to that.
|
| +// We end up having to use the file thread for this, because the DB thread is
|
| +// not a MessageLoopForIO and we need one of those to watch file descriptors.
|
|
|
| -// This class represents a call to a GNOME Keyring method. A RunnableMethod
|
| -// should be posted to the UI thread to call one of its action methods, and then
|
| -// a WaitResult() method should be called to wait for the result. Each instance
|
| -// supports only one outstanding method at a time, though multiple instances may
|
| -// be used in parallel.
|
| -class GKRMethod : public GnomeKeyringLoader {
|
| - public:
|
| - typedef NativeBackendGnome::PasswordFormList PasswordFormList;
|
| -
|
| - GKRMethod() : event_(false, false), result_(GNOME_KEYRING_RESULT_CANCELLED) {}
|
| -
|
| - // Action methods. These call gnome_keyring_* functions. Call from UI thread.
|
| - // See GetProfileSpecificAppString() for more information on the app string.
|
| - void AddLogin(const PasswordForm& form, const char* app_string);
|
| - void AddLoginSearch(const PasswordForm& form, const char* app_string);
|
| - void UpdateLoginSearch(const PasswordForm& form, const char* app_string);
|
| - void RemoveLogin(const PasswordForm& form, const char* app_string);
|
| - void GetLogins(const PasswordForm& form, const char* app_string);
|
| - void GetLoginsList(uint32_t blacklisted_by_user, const char* app_string);
|
| - void GetAllLogins(const char* app_string);
|
| -
|
| - // Use after AddLogin, RemoveLogin.
|
| - GnomeKeyringResult WaitResult();
|
| -
|
| - // Use after AddLoginSearch, UpdateLoginSearch, GetLogins, GetLoginsList,
|
| - // GetAllLogins.
|
| - GnomeKeyringResult WaitResult(PasswordFormList* forms);
|
| -
|
| - private:
|
| - // All these callbacks are called on UI thread.
|
| - static void OnOperationDone(GnomeKeyringResult result, gpointer data);
|
| -
|
| - static void OnOperationGetList(GnomeKeyringResult result, GList* list,
|
| - gpointer data);
|
| -
|
| - base::WaitableEvent event_;
|
| - GnomeKeyringResult result_;
|
| - NativeBackendGnome::PasswordFormList forms_;
|
| -};
|
| -
|
| -void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - time_t date_created = form.date_created.ToTimeT();
|
| - // If we are asked to save a password with 0 date, use the current time.
|
| - // We don't want to actually save passwords as though on January 1, 1970.
|
| - if (!date_created)
|
| - date_created = time(NULL);
|
| - gnome_keyring_store_password(
|
| - &kGnomeSchema,
|
| - NULL, // Default keyring.
|
| - form.origin.spec().c_str(), // Display name.
|
| - UTF16ToUTF8(form.password_value).c_str(),
|
| - OnOperationDone,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "origin_url", form.origin.spec().c_str(),
|
| - "action_url", form.action.spec().c_str(),
|
| - "username_element", UTF16ToUTF8(form.username_element).c_str(),
|
| - "username_value", UTF16ToUTF8(form.username_value).c_str(),
|
| - "password_element", UTF16ToUTF8(form.password_element).c_str(),
|
| - "submit_element", UTF16ToUTF8(form.submit_element).c_str(),
|
| - "signon_realm", form.signon_realm.c_str(),
|
| - "ssl_valid", form.ssl_valid,
|
| - "preferred", form.preferred,
|
| - "date_created", base::Int64ToString(date_created).c_str(),
|
| - "blacklisted_by_user", form.blacklisted_by_user,
|
| - "scheme", form.scheme,
|
| - "application", app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::AddLoginSearch(const PasswordForm& form,
|
| - const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // Search GNOME Keyring for matching passwords to update.
|
| - gnome_keyring_find_itemsv(
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
| - OnOperationGetList,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - form.origin.spec().c_str(),
|
| - "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.username_element).c_str(),
|
| - "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.username_value).c_str(),
|
| - "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.password_element).c_str(),
|
| - "submit_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.submit_element).c_str(),
|
| - "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - form.signon_realm.c_str(),
|
| - "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::UpdateLoginSearch(const PasswordForm& form,
|
| - const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // Search GNOME Keyring for matching passwords to update.
|
| - gnome_keyring_find_itemsv(
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
| - OnOperationGetList,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - form.origin.spec().c_str(),
|
| - "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.username_element).c_str(),
|
| - "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.username_value).c_str(),
|
| - "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - UTF16ToUTF8(form.password_element).c_str(),
|
| - "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - form.signon_realm.c_str(),
|
| - "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::RemoveLogin(const PasswordForm& form, const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // We find forms using the same fields as LoginDatabase::RemoveLogin().
|
| - gnome_keyring_delete_password(
|
| - &kGnomeSchema,
|
| - OnOperationDone,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "origin_url", form.origin.spec().c_str(),
|
| - "action_url", form.action.spec().c_str(),
|
| - "username_element", UTF16ToUTF8(form.username_element).c_str(),
|
| - "username_value", UTF16ToUTF8(form.username_value).c_str(),
|
| - "password_element", UTF16ToUTF8(form.password_element).c_str(),
|
| - "submit_element", UTF16ToUTF8(form.submit_element).c_str(),
|
| - "signon_realm", form.signon_realm.c_str(),
|
| - "application", app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // Search GNOME Keyring for matching passwords.
|
| - gnome_keyring_find_itemsv(
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
| - OnOperationGetList,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - form.signon_realm.c_str(),
|
| - "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user,
|
| - const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // Search GNOME Keyring for matching passwords.
|
| - gnome_keyring_find_itemsv(
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
| - OnOperationGetList,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32,
|
| - blacklisted_by_user,
|
| - "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - app_string,
|
| - NULL);
|
| -}
|
| -
|
| -void GKRMethod::GetAllLogins(const char* app_string) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - // We need to search for something, otherwise we get no results - so
|
| - // we search for the fixed application string.
|
| - gnome_keyring_find_itemsv(
|
| - GNOME_KEYRING_ITEM_GENERIC_SECRET,
|
| - OnOperationGetList,
|
| - this, // data
|
| - NULL, // destroy_data
|
| - "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
|
| - app_string,
|
| - NULL);
|
| -}
|
| -
|
| -GnomeKeyringResult GKRMethod::WaitResult() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - event_.Wait();
|
| - return result_;
|
| -}
|
| -
|
| -GnomeKeyringResult GKRMethod::WaitResult(PasswordFormList* forms) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - event_.Wait();
|
| - if (forms->empty()) {
|
| - // Normal case. Avoid extra allocation by swapping.
|
| - forms->swap(forms_);
|
| - } else {
|
| - // Rare case. Append forms_ to *forms.
|
| - forms->insert(forms->end(), forms_.begin(), forms_.end());
|
| - forms_.clear();
|
| - }
|
| - return result_;
|
| -}
|
| -
|
| -// static
|
| -void GKRMethod::OnOperationDone(GnomeKeyringResult result, gpointer data) {
|
| - GKRMethod* method = static_cast<GKRMethod*>(data);
|
| - method->result_ = result;
|
| - method->event_.Signal();
|
| -}
|
| -
|
| -// static
|
| -void GKRMethod::OnOperationGetList(GnomeKeyringResult result, GList* list,
|
| - gpointer data) {
|
| - GKRMethod* method = static_cast<GKRMethod*>(data);
|
| - method->result_ = result;
|
| - method->forms_.clear();
|
| - // |list| will be freed after this callback returns, so convert it now.
|
| - ConvertFormList(list, &method->forms_);
|
| - method->event_.Signal();
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| NativeBackendGnome::NativeBackendGnome(LocalProfileId id, PrefService* prefs)
|
| : profile_id_(id), prefs_(prefs) {
|
| // TODO(mdm): after a few more releases, remove the code which is now dead due
|
| @@ -433,20 +50,31 @@
|
| }
|
|
|
| bool NativeBackendGnome::Init() {
|
| - return LoadGnomeKeyring() && gnome_keyring_is_available();
|
| + // We don't need to determine with absolute certainty that we can use GNOME
|
| + // Keyring here. PasswordStoreX is conservative and will back off if the first
|
| + // attempt to use it fails. Since that will conveniently occur on the DB
|
| + // thread, where we need to finish initialization by watching the IPC file
|
| + // descriptor, we merely start the proxy here and claim success if that works.
|
| + DCHECK(!proxy_client_.get());
|
| + scoped_ptr<KeyringProxyClient> client(new KeyringProxyClient);
|
| + if (!client->Connect())
|
| + return false;
|
| + proxy_client_.reset(client.release());
|
| + return true;
|
| }
|
|
|
| +void NativeBackendGnome::InitForTesting(KeyringProxyClient* client) {
|
| + DCHECK(!proxy_client_.get());
|
| + proxy_client_.reset(client);
|
| +}
|
| +
|
| bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::AddLogin,
|
| - base::Unretained(&method),
|
| - form, app_string_.c_str()));
|
| - GnomeKeyringResult result = method.WaitResult();
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| - LOG(ERROR) << "Keyring save failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + KeyringProxyClient::RequestContext context;
|
| + proxy_client_->AddLogin(form, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| + LOG(ERROR) << "Keyring save failed: code " << context.result_code;
|
| return false;
|
| }
|
| // Successful write. Try migration if necessary.
|
| @@ -462,17 +90,13 @@
|
| // We'd add the new one first, and then delete the original, but then the
|
| // delete might actually delete the newly-added entry!
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::AddLoginSearch,
|
| - base::Unretained(&method),
|
| - form, app_string_.c_str()));
|
| PasswordFormList forms;
|
| - GnomeKeyringResult result = method.WaitResult(&forms);
|
| - if (result != GNOME_KEYRING_RESULT_OK &&
|
| - result != GNOME_KEYRING_RESULT_NO_MATCH) {
|
| - LOG(ERROR) << "Keyring find failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + KeyringProxyClient::RequestContext context(&forms);
|
| + proxy_client_->AddLoginSearch(form, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK &&
|
| + context.result_code != GNOME_KEYRING_RESULT_NO_MATCH) {
|
| + LOG(ERROR) << "Keyring find failed: code " << context.result_code;
|
| return false;
|
| }
|
| if (forms.size() > 0) {
|
| @@ -502,16 +126,12 @@
|
| // the new one first, and then delete the original, but then the delete might
|
| // actually delete the newly-added entry!
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::UpdateLoginSearch,
|
| - base::Unretained(&method),
|
| - form, app_string_.c_str()));
|
| PasswordFormList forms;
|
| - GnomeKeyringResult result = method.WaitResult(&forms);
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| - LOG(ERROR) << "Keyring find failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + KeyringProxyClient::RequestContext context(&forms);
|
| + proxy_client_->UpdateLoginSearch(form, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| + LOG(ERROR) << "Keyring find failed: code " << context.result_code;
|
| return false;
|
| }
|
|
|
| @@ -548,17 +168,13 @@
|
|
|
| bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::RemoveLogin,
|
| - base::Unretained(&method),
|
| - form, app_string_.c_str()));
|
| - GnomeKeyringResult result = method.WaitResult();
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| + KeyringProxyClient::RequestContext context;
|
| + proxy_client_->RemoveLogin(form, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| // Warning, not error, because this can sometimes happen due to the user
|
| // racing with the daemon to delete the password a second time.
|
| - LOG(WARNING) << "Keyring delete failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + LOG(WARNING) << "Keyring delete failed: code " << context.result_code;
|
| return false;
|
| }
|
| // Successful write. Try migration if necessary. Note that presumably if we've
|
| @@ -595,17 +211,13 @@
|
| bool NativeBackendGnome::GetLogins(const PasswordForm& form,
|
| PasswordFormList* forms) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::GetLogins,
|
| - base::Unretained(&method),
|
| - form, app_string_.c_str()));
|
| - GnomeKeyringResult result = method.WaitResult(forms);
|
| - if (result == GNOME_KEYRING_RESULT_NO_MATCH)
|
| + KeyringProxyClient::RequestContext context(forms);
|
| + proxy_client_->GetLogins(form, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code == GNOME_KEYRING_RESULT_NO_MATCH)
|
| return true;
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| - LOG(ERROR) << "Keyring find failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| + LOG(ERROR) << "Keyring find failed: code " << context.result_code;
|
| return false;
|
| }
|
| // Successful read of actual data. Try migration if necessary.
|
| @@ -652,17 +264,13 @@
|
|
|
| uint32_t blacklisted_by_user = !autofillable;
|
|
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::GetLoginsList,
|
| - base::Unretained(&method),
|
| - blacklisted_by_user, app_string_.c_str()));
|
| - GnomeKeyringResult result = method.WaitResult(forms);
|
| - if (result == GNOME_KEYRING_RESULT_NO_MATCH)
|
| + KeyringProxyClient::RequestContext context(forms);
|
| + proxy_client_->GetLoginsList(blacklisted_by_user, app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code == GNOME_KEYRING_RESULT_NO_MATCH)
|
| return true;
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| - LOG(ERROR) << "Keyring find failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| + LOG(ERROR) << "Keyring find failed: code " << context.result_code;
|
| return false;
|
| }
|
| // Successful read of actual data. Try migration if necessary.
|
| @@ -672,17 +280,13 @@
|
| }
|
|
|
| bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
|
| - GKRMethod method;
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&GKRMethod::GetAllLogins,
|
| - base::Unretained(&method),
|
| - app_string_.c_str()));
|
| - GnomeKeyringResult result = method.WaitResult(forms);
|
| - if (result == GNOME_KEYRING_RESULT_NO_MATCH)
|
| + KeyringProxyClient::RequestContext context(forms);
|
| + proxy_client_->GetAllLogins(app_string_, &context);
|
| + context.event.Wait();
|
| + if (context.result_code == GNOME_KEYRING_RESULT_NO_MATCH)
|
| return true;
|
| - if (result != GNOME_KEYRING_RESULT_OK) {
|
| - LOG(ERROR) << "Keyring find failed: "
|
| - << gnome_keyring_result_to_message(result);
|
| + if (context.result_code != GNOME_KEYRING_RESULT_OK) {
|
| + LOG(ERROR) << "Keyring find failed: code " << context.result_code;
|
| return false;
|
| }
|
| // Successful read of actual data. Try migration if necessary.
|
|
|