OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_AUTOFILL_AUTOFILL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/string16.h" | 21 #include "base/string16.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "chrome/browser/autofill/autofill_download.h" | 23 #include "chrome/browser/autofill/autofill_download.h" |
24 #include "chrome/browser/autofill/field_types.h" | 24 #include "chrome/browser/autofill/field_types.h" |
25 #include "chrome/browser/autofill/form_structure.h" | 25 #include "chrome/browser/autofill/form_structure.h" |
26 #include "chrome/browser/prefs/pref_change_registrar.h" | |
26 #include "chrome/browser/sync/profile_sync_service_observer.h" | 27 #include "chrome/browser/sync/profile_sync_service_observer.h" |
28 #include "content/public/browser/notification_observer.h" | |
27 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
28 | 30 |
29 class AutofillExternalDelegate; | 31 class AutofillExternalDelegate; |
30 class AutofillField; | 32 class AutofillField; |
31 class AutofillProfile; | 33 class AutofillProfile; |
32 class AutofillMetrics; | 34 class AutofillMetrics; |
33 class CreditCard; | 35 class CreditCard; |
34 class PersonalDataManager; | 36 class PersonalDataManager; |
35 class PrefService; | 37 class PrefService; |
36 class ProfileSyncService; | 38 class ProfileSyncService; |
(...skipping 16 matching lines...) Expand all Loading... | |
53 namespace webkit { | 55 namespace webkit { |
54 namespace forms { | 56 namespace forms { |
55 struct FormData; | 57 struct FormData; |
56 struct FormField; | 58 struct FormField; |
57 struct PasswordFormFillData; | 59 struct PasswordFormFillData; |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
61 // Manages saving and restoring the user's personal information entered into web | 63 // Manages saving and restoring the user's personal information entered into web |
62 // forms. | 64 // forms. |
63 class AutofillManager : public content::WebContentsObserver, | 65 class AutofillManager : public content::NotificationObserver, |
66 public content::WebContentsObserver, | |
64 public AutofillDownloadManager::Observer, | 67 public AutofillDownloadManager::Observer, |
65 public ProfileSyncServiceObserver, | 68 public ProfileSyncServiceObserver, |
66 public base::RefCounted<AutofillManager> { | 69 public base::RefCounted<AutofillManager> { |
67 public: | 70 public: |
68 explicit AutofillManager(TabContentsWrapper* tab_contents); | 71 explicit AutofillManager(TabContentsWrapper* tab_contents); |
69 | 72 |
70 // Registers our Enable/Disable Autofill pref. | 73 // Registers our Enable/Disable Autofill pref. |
71 static void RegisterUserPrefs(PrefService* prefs); | 74 static void RegisterUserPrefs(PrefService* prefs); |
72 | 75 |
73 // Set our external delegate. | 76 // Set our external delegate. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 111 |
109 // Returns the value of the AutofillEnabled pref. | 112 // Returns the value of the AutofillEnabled pref. |
110 virtual bool IsAutofillEnabled() const; | 113 virtual bool IsAutofillEnabled() const; |
111 | 114 |
112 // Uploads the form data to the Autofill server. | 115 // Uploads the form data to the Autofill server. |
113 virtual void UploadFormData(const FormStructure& submitted_form); | 116 virtual void UploadFormData(const FormStructure& submitted_form); |
114 | 117 |
115 // Reset cache. | 118 // Reset cache. |
116 void Reset(); | 119 void Reset(); |
117 | 120 |
118 // Informs the renderer of the current password generation state. This is a | 121 // Informs the renderer of the current password sync state. This is a |
119 // separate function to aid with testing. | 122 // separate function to aid with testing. |
123 virtual void SendPasswordSyncStateToRenderer( | |
Garrett Casto
2012/04/26 23:23:59
It looks like you have two versions of some of the
| |
124 content::RenderViewHost* host, | |
125 bool enabled); | |
126 | |
127 // Informs the renderers of the current password generation state for use | |
128 // in password generation. This is a separate function to aid with testing. | |
120 virtual void SendPasswordGenerationStateToRenderer( | 129 virtual void SendPasswordGenerationStateToRenderer( |
121 content::RenderViewHost* host, | 130 content::RenderViewHost* host, |
122 bool enabled); | 131 bool enabled); |
123 | 132 |
133 | |
124 // Logs quality metrics for the |submitted_form| and uploads the form data | 134 // Logs quality metrics for the |submitted_form| and uploads the form data |
125 // to the crowdsourcing server, if appropriate. | 135 // to the crowdsourcing server, if appropriate. |
126 virtual void UploadFormDataAsyncCallback( | 136 virtual void UploadFormDataAsyncCallback( |
127 const FormStructure* submitted_form, | 137 const FormStructure* submitted_form, |
128 const base::TimeTicks& load_time, | 138 const base::TimeTicks& load_time, |
129 const base::TimeTicks& interaction_time, | 139 const base::TimeTicks& interaction_time, |
130 const base::TimeTicks& submission_time); | 140 const base::TimeTicks& submission_time); |
131 | 141 |
132 // Maps GUIDs to and from IDs that are used to identify profiles and credit | 142 // Maps GUIDs to and from IDs that are used to identify profiles and credit |
133 // cards sent to and from the renderer process. | 143 // cards sent to and from the renderer process. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 // AutofillDownloadManager::Observer: | 176 // AutofillDownloadManager::Observer: |
167 virtual void OnLoadedServerPredictions( | 177 virtual void OnLoadedServerPredictions( |
168 const std::string& response_xml) OVERRIDE; | 178 const std::string& response_xml) OVERRIDE; |
169 | 179 |
170 // ProfileSyncServiceObserver: | 180 // ProfileSyncServiceObserver: |
171 virtual void OnStateChanged() OVERRIDE; | 181 virtual void OnStateChanged() OVERRIDE; |
172 | 182 |
173 // Register as an observer with the sync service. | 183 // Register as an observer with the sync service. |
174 void RegisterWithSyncService(); | 184 void RegisterWithSyncService(); |
175 | 185 |
176 // Determines what the current state of password generation is, and if it has | 186 // Determines what the current state of password sync is, and if it has |
177 // changed from |password_generation_enabled_|. If it has changed or if | 187 // changed from |password_sync_enabled_|. If it has changed or if |
188 // |new_renderer| is true, it notifies the renderer of this change via | |
189 // SendPasswordSyncStateToRenderer. | |
190 void UpdatePasswordSyncState(content::RenderViewHost* host, | |
191 bool new_renderer); | |
192 | |
193 // content::NotificationObserver override | |
194 virtual void Observe(int type, | |
195 const content::NotificationSource& source, | |
196 const content::NotificationDetails& details) OVERRIDE; | |
197 | |
198 // Determines that the current state of password generation is, and if it | |
199 // has changed from password_generation_enabled_. If it has changed or if | |
178 // |new_renderer| is true, it notifies the renderer of this change via | 200 // |new_renderer| is true, it notifies the renderer of this change via |
179 // SendPasswordGenerationStateToRenderer. | 201 // SendPasswordGenerationStateToRenderer. |
180 void UpdatePasswordGenerationState(content::RenderViewHost* host, | 202 void UpdatePasswordGenerationState(content::RenderViewHost* host, |
181 bool new_renderer); | 203 bool new_renderer); |
182 | 204 |
183 void OnFormsSeen(const std::vector<webkit::forms::FormData>& forms, | 205 void OnFormsSeen(const std::vector<webkit::forms::FormData>& forms, |
184 const base::TimeTicks& timestamp); | 206 const base::TimeTicks& timestamp); |
185 void OnTextFieldDidChange(const webkit::forms::FormData& form, | 207 void OnTextFieldDidChange(const webkit::forms::FormData& form, |
186 const webkit::forms::FormField& field, | 208 const webkit::forms::FormField& field, |
187 const base::TimeTicks& timestamp); | 209 const base::TimeTicks& timestamp); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 bool user_did_type_; | 352 bool user_did_type_; |
331 // Has the user autofilled a form on this page? | 353 // Has the user autofilled a form on this page? |
332 bool user_did_autofill_; | 354 bool user_did_autofill_; |
333 // Has the user edited a field that was previously autofilled? | 355 // Has the user edited a field that was previously autofilled? |
334 bool user_did_edit_autofilled_field_; | 356 bool user_did_edit_autofilled_field_; |
335 // When the page finished loading. | 357 // When the page finished loading. |
336 base::TimeTicks forms_loaded_timestamp_; | 358 base::TimeTicks forms_loaded_timestamp_; |
337 // When the user first interacted with a potentially fillable form on this | 359 // When the user first interacted with a potentially fillable form on this |
338 // page. | 360 // page. |
339 base::TimeTicks initial_interaction_timestamp_; | 361 base::TimeTicks initial_interaction_timestamp_; |
362 // If password sync is enabled. We cache this value so that we don't | |
363 // spam the renderer with messages during startup when the sync state | |
364 // is changing rapidly. | |
365 bool password_sync_enabled_; | |
Garrett Casto
2012/04/26 23:23:59
This should be removed.
| |
366 // The ProfileSyncService associated with this tab. This may be NULL in | |
367 // testing. | |
368 base::WeakPtr<ProfileSyncService> sync_service_; | |
340 // If password generation is enabled. We cache this value so that we don't | 369 // If password generation is enabled. We cache this value so that we don't |
341 // spam the renderer with messages during startup when the sync state | 370 // spam the renderer with messages during startup when the sync state |
342 // is changing rapidly. | 371 // is changing rapidly. |
343 bool password_generation_enabled_; | 372 bool password_generation_enabled_; |
344 // The ProfileSyncService associated with this tab. This may be NULL in | 373 // Handle preference change event. |
345 // testing. | 374 PrefChangeRegistrar registrar_; |
346 base::WeakPtr<ProfileSyncService> sync_service_; | |
347 | 375 |
348 // Our copy of the form data. | 376 // Our copy of the form data. |
349 ScopedVector<FormStructure> form_structures_; | 377 ScopedVector<FormStructure> form_structures_; |
350 | 378 |
351 // GUID to ID mapping. We keep two maps to convert back and forth. | 379 // GUID to ID mapping. We keep two maps to convert back and forth. |
352 mutable std::map<GUIDPair, int> guid_id_map_; | 380 mutable std::map<GUIDPair, int> guid_id_map_; |
353 mutable std::map<int, GUIDPair> id_guid_map_; | 381 mutable std::map<int, GUIDPair> id_guid_map_; |
354 | 382 |
355 // Delegate to perform external processing (display, selection) on | 383 // Delegate to perform external processing (display, selection) on |
356 // our behalf. Weak. | 384 // our behalf. Weak. |
(...skipping 18 matching lines...) Expand all Loading... | |
375 TestTabContentsWithExternalDelegate); | 403 TestTabContentsWithExternalDelegate); |
376 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, | 404 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, |
377 UserHappinessFormLoadAndSubmission); | 405 UserHappinessFormLoadAndSubmission); |
378 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 406 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
379 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); | 407 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); |
380 | 408 |
381 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 409 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
382 }; | 410 }; |
383 | 411 |
384 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 412 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
OLD | NEW |