| Index: chrome/browser/password_manager/keyring_proxy/keyring_proxy_client.h
 | 
| ===================================================================
 | 
| --- chrome/browser/password_manager/keyring_proxy/keyring_proxy_client.h	(revision 0)
 | 
| +++ chrome/browser/password_manager/keyring_proxy/keyring_proxy_client.h	(revision 0)
 | 
| @@ -0,0 +1,142 @@
 | 
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
 | 
| +// Use of this source code is governed by a BSD-style license that can be
 | 
| +// found in the LICENSE file.
 | 
| +
 | 
| +#ifndef CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_KEYRING_PROXY_CLIENT_H_
 | 
| +#define CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_KEYRING_PROXY_CLIENT_H_
 | 
| +#pragma once
 | 
| +
 | 
| +#include <gnome-keyring.h>
 | 
| +
 | 
| +#include <map>
 | 
| +#include <string>
 | 
| +#include <vector>
 | 
| +
 | 
| +#include "base/memory/ref_counted.h"
 | 
| +#include "base/synchronization/lock.h"
 | 
| +#include "base/synchronization/waitable_event.h"
 | 
| +
 | 
| +namespace webkit {
 | 
| +namespace forms {
 | 
| +struct PasswordForm;
 | 
| +}
 | 
| +}
 | 
| +
 | 
| +namespace keyring_proxy {
 | 
| +
 | 
| +// Used internally by KeyringProxyClient to watch the file descriptor for data
 | 
| +// to read. Done in a separate class so it can be refcounted and shut down
 | 
| +// safely on the file thread after pending callbacks are done.
 | 
| +class KeyringProxyFDWatcher;
 | 
| +
 | 
| +class KeyringProxyClient {
 | 
| + public:
 | 
| +  // This is the name of the binary for the proxy itself.
 | 
| +  static const char kProxyBinary[];
 | 
| +
 | 
| +  // Save some typing with convenient short types for password forms.
 | 
| +  typedef webkit::forms::PasswordForm PasswordForm;
 | 
| +  typedef std::vector<PasswordForm*> PasswordFormList;
 | 
| +
 | 
| +  // Every request to the proxy has a context, and internally also an ID.
 | 
| +  struct RequestContext {
 | 
| +    base::WaitableEvent event;
 | 
| +    GnomeKeyringResult result_code;
 | 
| +    PasswordFormList* result_list;  // Not used for AddLogin() or RemoveLogin().
 | 
| +
 | 
| +    RequestContext()
 | 
| +        : event(false, false), result_code(GNOME_KEYRING_RESULT_CANCELLED),
 | 
| +          result_list(NULL) {}
 | 
| +    explicit RequestContext(PasswordFormList* list)
 | 
| +        : event(false, false), result_code(GNOME_KEYRING_RESULT_CANCELLED),
 | 
| +          result_list(list) {}
 | 
| +  };
 | 
| +
 | 
| +  // The client is constructed and destructed on the UI thread.
 | 
| +  KeyringProxyClient();
 | 
| +  ~KeyringProxyClient();
 | 
| +
 | 
| +  // Starts a keyring proxy process. Returns true on fork() success; the process
 | 
| +  // itself may still fail to start or fail later. Use connected() to check it.
 | 
| +  // Safe to call on the UI thread after instantiation, but if called again to
 | 
| +  // reconnect later, should be called on the DB thread.
 | 
| +  bool Connect();
 | 
| +
 | 
| +  // Returns true if the keyring proxy is still connected as far as we know.
 | 
| +  bool connected() const { return !!fd_watcher_.get(); }
 | 
| +
 | 
| +  // These are safe to call on the DB thread. The request is complete when the
 | 
| +  // waitable event in the provided request context becomes ready. The actual
 | 
| +  // callbacks that happen when data is received from the proxy will happen on
 | 
| +  // the file thread, where they will signal the waitable events. This is done
 | 
| +  // because we want to parallelize multiple requests, but the password store
 | 
| +  // APIs on the DB thread are synchronous and so must wait for the replies.
 | 
| +  void AddLogin(const PasswordForm& form,
 | 
| +                const std::string& app_string,
 | 
| +                RequestContext* context);
 | 
| +  void AddLoginSearch(const PasswordForm& form,
 | 
| +                      const std::string& app_string,
 | 
| +                      RequestContext* context);
 | 
| +  void UpdateLoginSearch(const PasswordForm& form,
 | 
| +                         const std::string& app_string,
 | 
| +                         RequestContext* context);
 | 
| +  void RemoveLogin(const PasswordForm& form,
 | 
| +                   const std::string& app_string,
 | 
| +                   RequestContext* context);
 | 
| +  void GetLogins(const PasswordForm& form,
 | 
| +                 const std::string& app_string,
 | 
| +                 RequestContext* context);
 | 
| +  void GetLoginsList(bool blacklisted_by_user,
 | 
| +                     const std::string& app_string,
 | 
| +                     RequestContext* context);
 | 
| +  void GetAllLogins(const std::string& app_string,
 | 
| +                    RequestContext* context);
 | 
| +
 | 
| +  // Launches the keyring proxy and returns the IPC file descriptor to it.
 | 
| +  static int LaunchKeyringProxy();
 | 
| +
 | 
| + protected:
 | 
| +  // This is the type of the messages actually exchanged with the proxy.
 | 
| +  typedef std::vector<std::string> ProxyMessage;
 | 
| +
 | 
| +  // Connects to the given file descriptor instead of launching the proxy.
 | 
| +  // Will still close it, but will only listen for reads if requested.
 | 
| +  void ConnectForTesting(int fd, bool watch_for_reads);
 | 
| +
 | 
| +  // Cancel all outstanding requests and unblock waiters. Must already hold
 | 
| +  // |request_lock_| to call CancelAllRequests(). Protected for testing.
 | 
| +  void CancelAllRequests();
 | 
| +
 | 
| +  // These are called by KeyringProxyFDWatcher on the file thread.
 | 
| +  void HandleProxyReply(const ProxyMessage& reply);
 | 
| +  void HandleProxyError(bool eof);
 | 
| +
 | 
| + private:
 | 
| +  friend class KeyringProxyFDWatcher;
 | 
| +
 | 
| +  // Must already hold |request_lock_| to call GetRequestId().
 | 
| +  int GetRequestId();
 | 
| +  // Send a request of type |type| and add an entry to |proxy_requests_| for it.
 | 
| +  void SendRequest(
 | 
| +      char type, const ProxyMessage& request, RequestContext* context);
 | 
| +
 | 
| +  // Cancel a single request context, unblocking the waiter.
 | 
| +  void CancelRequest(RequestContext* context);
 | 
| +
 | 
| +  scoped_refptr<KeyringProxyFDWatcher> fd_watcher_;
 | 
| +
 | 
| +  // The next proxy request ID to try.
 | 
| +  int next_request_id_;
 | 
| +
 | 
| +  // A map from proxy request IDs to proxy requests. Guarded by |request_lock_|.
 | 
| +  std::map<int, RequestContext*> proxy_requests_;
 | 
| +
 | 
| +  // Guards |proxy_requests_| since it is accessed on the DB and file threads.
 | 
| +  base::Lock request_lock_;
 | 
| +
 | 
| +  DISALLOW_COPY_AND_ASSIGN(KeyringProxyClient);
 | 
| +};
 | 
| +
 | 
| +}  // namespace keyring_proxy
 | 
| +
 | 
| +#endif  // CHROME_BROWSER_PASSWORD_MANAGER_KEYRING_PROXY_KEYRING_PROXY_CLIENT_H_
 | 
| 
 | 
| Property changes on: chrome/browser/password_manager/keyring_proxy/keyring_proxy_client.h
 | 
| ___________________________________________________________________
 | 
| Added: svn:eol-style
 | 
|    + LF
 | 
| 
 | 
| 
 |