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

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

Issue 114057: Re-land the password store work from bug 8205, with changes that should fix b... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
(Empty)
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE
7
8 #include <set>
9 #include <vector>
10
11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h"
13 #include "base/thread.h"
14 #include "webkit/glue/password_form.h"
15
16 class Profile;
17 class Task;
18
19 class PasswordStoreConsumer {
20 public:
21 virtual ~PasswordStoreConsumer() {}
22 // Call this when the request is finished. If there are no results, call it
23 // anyway with an empty vector.
24 virtual void OnPasswordStoreRequestDone(
25 int handle, const std::vector<PasswordForm*>& result) = 0;
26 };
27
28 // Interface for storing form passwords in a platform-specific secure way.
29 // The login request/manipulation API is not threadsafe.
30 class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> {
31 public:
32 PasswordStore();
33 virtual ~PasswordStore() {}
34
35 // Reimplement this to add custom initialization. Always call this too.
36 virtual bool Init();
37
38 // Adds the given PasswordForm to the secure password store asynchronously.
39 void AddLogin(const PasswordForm& form);
40 // Updates the matching PasswordForm in the secure password store (async).
41 void UpdateLogin(const PasswordForm& form);
42 // Removes the matching PasswordForm from the secure password store (async).
43 void RemoveLogin(const PasswordForm& form);
44 // Searches for a matching PasswordForm and returns a handle so the async
45 // request can be tracked. Implement the PasswordStoreConsumer interface to
46 // be notified on completion.
47 int GetLogins(const PasswordForm& form,
48 PasswordStoreConsumer* consumer);
49
50 // Cancels a previous GetLogins query (async)
51 virtual void CancelLoginsQuery(int handle);
52
53 protected:
54 // Simple container class that represents a GetLogins request.
55 // Created in GetLogins and passed to GetLoginsImpl.
56 struct GetLoginsRequest {
57 GetLoginsRequest(const PasswordForm& f,
58 PasswordStoreConsumer* c,
59 int handle);
60
61 // The query form that was originally passed to GetLogins
62 PasswordForm form;
63 // The consumer to notify when this GetLogins request is complete
64 PasswordStoreConsumer* consumer;
65 // A unique handle for the request
66 int handle;
67 // The message loop that the GetLogins request was made from. We send the
68 // result back to the consumer in this same message loop.
69 MessageLoop* message_loop;
70
71 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest);
72 };
73
74 // Schedule the given task to be run in the PasswordStore's own thread.
75 void ScheduleTask(Task* task);
76
77 // These will be run in PasswordStore's own thread.
78 // Synchronous implementation to add the given login.
79 virtual void AddLoginImpl(const PasswordForm& form) = 0;
80 // Synchronous implementation to update the given login.
81 virtual void UpdateLoginImpl(const PasswordForm& form) = 0;
82 // Synchronous implementation to remove the given login.
83 virtual void RemoveLoginImpl(const PasswordForm& form) = 0;
84 // Should find all PasswordForms with the same signon_realm. The results
85 // will then be scored by the PasswordFormManager. Once they are found
86 // (or not), the consumer should be notified.
87 virtual void GetLoginsImpl(GetLoginsRequest* request) = 0;
88
89 // Notifies the consumer that GetLoginsImpl() is complete.
90 void NotifyConsumer(GetLoginsRequest* request,
91 const std::vector<PasswordForm*> forms);
92
93 // Next handle to return from GetLogins() to allow callers to track
94 // their request.
95 int handle_;
96
97 // Thread that the synchronous methods are run in.
98 scoped_ptr<base::Thread> thread_;
99
100 private:
101 // Called by NotifyConsumer, but runs in the consumer's thread. Will not
102 // call the consumer if the request was canceled. This extra layer is here so
103 // that PasswordStoreConsumer doesn't have to be reference counted (we assume
104 // consumers will cancel their requests before they are destroyed).
105 void NotifyConsumerImpl(PasswordStoreConsumer* consumer, int handle,
106 const std::vector<PasswordForm*> forms);
107
108 // List of pending request handles. Handles are removed from the set when
109 // they finish or are canceled.
110 std::set<int> pending_requests_;
111
112 DISALLOW_COPY_AND_ASSIGN(PasswordStore);
113 };
114
115 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_manager.cc ('k') | chrome/browser/password_manager/password_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698