OLD | NEW |
| (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 class PasswordStore : public base::RefCountedThreadSafe<PasswordStore> { | |
30 public: | |
31 PasswordStore(); | |
32 virtual ~PasswordStore() {} | |
33 | |
34 // Reimplement this to add custom initialization. Always call this too. | |
35 virtual bool Init(); | |
36 | |
37 // Adds the given PasswordForm to the secure password store asynchronously. | |
38 void AddLogin(const PasswordForm& form); | |
39 // Updates the matching PasswordForm in the secure password store (async). | |
40 void UpdateLogin(const PasswordForm& form); | |
41 // Removes the matching PasswordForm from the secure password store (async). | |
42 void RemoveLogin(const PasswordForm& form); | |
43 // Searches for a matching PasswordForm and returns a handle so the async | |
44 // request can be tracked. Implement the PasswordStoreConsumer interface to | |
45 // be notified on completion. | |
46 int GetLogins(const PasswordForm& form, | |
47 PasswordStoreConsumer* consumer); | |
48 | |
49 // Cancels a previous GetLogins query (async) | |
50 virtual void CancelLoginsQuery(int handle); | |
51 | |
52 protected: | |
53 // Simple container class that represents a GetLogins request. | |
54 // Created in GetLogins and passed to GetLoginsImpl. | |
55 struct GetLoginsRequest { | |
56 GetLoginsRequest(const PasswordForm& f, | |
57 PasswordStoreConsumer* c, | |
58 int handle); | |
59 | |
60 // The query form that was originally passed to GetLogins | |
61 PasswordForm form; | |
62 // The consumer to notify when this GetLogins request is complete | |
63 PasswordStoreConsumer* consumer; | |
64 // A unique handle for the request | |
65 int handle; | |
66 // The message loop that the GetLogins request was made from. We send the | |
67 // result back to the consumer in this same message loop. | |
68 MessageLoop* message_loop; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(GetLoginsRequest); | |
71 }; | |
72 | |
73 // Schedule the given task to be run in the PasswordStore's own thread. | |
74 void ScheduleTask(Task* task); | |
75 | |
76 // These will be run in PasswordStore's own thread. | |
77 // Synchronous implementation to add the given login. | |
78 virtual void AddLoginImpl(const PasswordForm& form) = 0; | |
79 // Synchronous implementation to update the given login. | |
80 virtual void UpdateLoginImpl(const PasswordForm& form) = 0; | |
81 // Synchronous implementation to remove the given login. | |
82 virtual void RemoveLoginImpl(const PasswordForm& form) = 0; | |
83 // Should find all PasswordForms with the same signon_realm. The results | |
84 // will then be scored by the PasswordFormManager. Once they are found | |
85 // (or not), the consumer should be notified. | |
86 virtual void GetLoginsImpl(GetLoginsRequest* request) = 0; | |
87 | |
88 // Notifies the consumer that GetLoginsImpl() is complete. | |
89 void NotifyConsumer(GetLoginsRequest* request, | |
90 const std::vector<PasswordForm*> forms); | |
91 | |
92 // Next handle to return from GetLogins() to allow callers to track | |
93 // their request. | |
94 int handle_; | |
95 | |
96 // Thread that the synchronous methods are run in. | |
97 scoped_ptr<base::Thread> thread_; | |
98 | |
99 private: | |
100 // Called by NotifyConsumer, but runs in the consumer's thread. Will not | |
101 // call the consumer if the request was canceled. This extra layer is here so | |
102 // that PasswordStoreConsumer doesn't have to be reference counted (we assume | |
103 // consumers will cancel their requests before they are destroyed). | |
104 void NotifyConsumerImpl(PasswordStoreConsumer* consumer, int handle, | |
105 const std::vector<PasswordForm*> forms); | |
106 | |
107 // List of pending request handles. Handles are removed from the set when | |
108 // they finish or are canceled. | |
109 Lock pending_requests_lock_; | |
110 std::set<int> pending_requests_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(PasswordStore); | |
113 }; | |
114 | |
115 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE | |
OLD | NEW |