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 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/prefs/public/pref_change_registrar.h" | 20 #include "base/prefs/public/pref_change_registrar.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/api/sync/profile_sync_service_observer.h" | 23 #include "chrome/browser/api/sync/profile_sync_service_observer.h" |
24 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 24 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
25 #include "chrome/browser/autofill/autofill_download.h" | 25 #include "chrome/browser/autofill/autofill_download.h" |
26 #include "chrome/browser/autofill/field_types.h" | 26 #include "chrome/browser/autofill/field_types.h" |
27 #include "chrome/browser/autofill/form_structure.h" | 27 #include "chrome/browser/autofill/form_structure.h" |
| 28 #include "chrome/browser/autofill/personal_data_manager.h" |
28 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
29 #include "content/public/common/ssl_status.h" | 30 #include "content/public/common/ssl_status.h" |
30 | 31 |
31 class AutofillExternalDelegate; | 32 class AutofillExternalDelegate; |
32 class AutofillField; | 33 class AutofillField; |
33 class AutofillProfile; | 34 class AutofillProfile; |
34 class AutofillMetrics; | 35 class AutofillMetrics; |
35 class CreditCard; | 36 class CreditCard; |
36 class FormGroup; | 37 class FormGroup; |
37 class GURL; | 38 class GURL; |
38 class PersonalDataManager; | |
39 class PrefService; | 39 class PrefService; |
40 class ProfileSyncService; | 40 class ProfileSyncService; |
41 | 41 |
42 struct FormData; | 42 struct FormData; |
43 struct FormFieldData; | 43 struct FormFieldData; |
44 struct PasswordFormFillData; | 44 struct PasswordFormFillData; |
45 struct ViewHostMsg_FrameNavigate_Params; | 45 struct ViewHostMsg_FrameNavigate_Params; |
46 | 46 |
47 namespace autofill { | 47 namespace autofill { |
48 class AutofillManagerDelegate; | 48 class AutofillManagerDelegate; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void RemoveAutocompleteEntry(const string16& name, const string16& value); | 106 void RemoveAutocompleteEntry(const string16& name, const string16& value); |
107 | 107 |
108 protected: | 108 protected: |
109 // Only test code should subclass AutofillManager. | 109 // Only test code should subclass AutofillManager. |
110 friend class base::RefCounted<AutofillManager>; | 110 friend class base::RefCounted<AutofillManager>; |
111 | 111 |
112 AutofillManager(content::WebContents* web_contents, | 112 AutofillManager(content::WebContents* web_contents, |
113 autofill::AutofillManagerDelegate* delegate); | 113 autofill::AutofillManagerDelegate* delegate); |
114 virtual ~AutofillManager(); | 114 virtual ~AutofillManager(); |
115 | 115 |
116 // The string/int pair is composed of the guid string and variant index | |
117 // respectively. The variant index is an index into the multi-valued item | |
118 // (where applicable). | |
119 typedef std::pair<std::string, size_t> GUIDPair; | |
120 | |
121 // Test code should prefer to use this constructor. | 116 // Test code should prefer to use this constructor. |
122 AutofillManager(content::WebContents* web_contents, | 117 AutofillManager(content::WebContents* web_contents, |
123 autofill::AutofillManagerDelegate* delegate, | 118 autofill::AutofillManagerDelegate* delegate, |
124 PersonalDataManager* personal_data); | 119 PersonalDataManager* personal_data); |
125 | 120 |
126 // Returns the value of the AutofillEnabled pref. | 121 // Returns the value of the AutofillEnabled pref. |
127 virtual bool IsAutofillEnabled() const; | 122 virtual bool IsAutofillEnabled() const; |
128 | 123 |
129 // Uploads the form data to the Autofill server. | 124 // Uploads the form data to the Autofill server. |
130 virtual void UploadFormData(const FormStructure& submitted_form); | 125 virtual void UploadFormData(const FormStructure& submitted_form); |
(...skipping 10 matching lines...) Expand all Loading... |
141 // Logs quality metrics for the |submitted_form| and uploads the form data | 136 // Logs quality metrics for the |submitted_form| and uploads the form data |
142 // to the crowdsourcing server, if appropriate. | 137 // to the crowdsourcing server, if appropriate. |
143 virtual void UploadFormDataAsyncCallback( | 138 virtual void UploadFormDataAsyncCallback( |
144 const FormStructure* submitted_form, | 139 const FormStructure* submitted_form, |
145 const base::TimeTicks& load_time, | 140 const base::TimeTicks& load_time, |
146 const base::TimeTicks& interaction_time, | 141 const base::TimeTicks& interaction_time, |
147 const base::TimeTicks& submission_time); | 142 const base::TimeTicks& submission_time); |
148 | 143 |
149 // Maps GUIDs to and from IDs that are used to identify profiles and credit | 144 // Maps GUIDs to and from IDs that are used to identify profiles and credit |
150 // cards sent to and from the renderer process. | 145 // cards sent to and from the renderer process. |
151 virtual int GUIDToID(const GUIDPair& guid) const; | 146 virtual int GUIDToID(const PersonalDataManager::GUIDPair& guid) const; |
152 virtual const GUIDPair IDToGUID(int id) const; | 147 virtual const PersonalDataManager::GUIDPair IDToGUID(int id) const; |
153 | 148 |
154 // Methods for packing and unpacking credit card and profile IDs for sending | 149 // Methods for packing and unpacking credit card and profile IDs for sending |
155 // and receiving to and from the renderer process. | 150 // and receiving to and from the renderer process. |
156 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const; | 151 int PackGUIDs(const PersonalDataManager::GUIDPair& cc_guid, |
157 void UnpackGUIDs(int id, GUIDPair* cc_guid, GUIDPair* profile_guid) const; | 152 const PersonalDataManager::GUIDPair& profile_guid) const; |
| 153 void UnpackGUIDs(int id, |
| 154 PersonalDataManager::GUIDPair* cc_guid, |
| 155 PersonalDataManager::GUIDPair* profile_guid) const; |
158 | 156 |
159 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } | 157 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } |
160 void set_metric_logger(const AutofillMetrics* metric_logger); | 158 void set_metric_logger(const AutofillMetrics* metric_logger); |
161 | 159 |
162 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } | 160 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } |
163 | 161 |
164 // Exposed for testing. | 162 // Exposed for testing. |
165 AutofillExternalDelegate* external_delegate() { | 163 AutofillExternalDelegate* external_delegate() { |
166 return external_delegate_; | 164 return external_delegate_; |
167 } | 165 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // Listens for changes to the 'enabled' state for password generation. | 357 // Listens for changes to the 'enabled' state for password generation. |
360 PrefChangeRegistrar registrar_; | 358 PrefChangeRegistrar registrar_; |
361 | 359 |
362 // To be passed to the password generation UI to generate the password. | 360 // To be passed to the password generation UI to generate the password. |
363 scoped_ptr<autofill::PasswordGenerator> password_generator_; | 361 scoped_ptr<autofill::PasswordGenerator> password_generator_; |
364 | 362 |
365 // Our copy of the form data. | 363 // Our copy of the form data. |
366 ScopedVector<FormStructure> form_structures_; | 364 ScopedVector<FormStructure> form_structures_; |
367 | 365 |
368 // GUID to ID mapping. We keep two maps to convert back and forth. | 366 // GUID to ID mapping. We keep two maps to convert back and forth. |
369 mutable std::map<GUIDPair, int> guid_id_map_; | 367 mutable std::map<PersonalDataManager::GUIDPair, int> guid_id_map_; |
370 mutable std::map<int, GUIDPair> id_guid_map_; | 368 mutable std::map<int, PersonalDataManager::GUIDPair> id_guid_map_; |
371 | 369 |
372 // Delegate to perform external processing (display, selection) on | 370 // Delegate to perform external processing (display, selection) on |
373 // our behalf. Weak. | 371 // our behalf. Weak. |
374 AutofillExternalDelegate* external_delegate_; | 372 AutofillExternalDelegate* external_delegate_; |
375 | 373 |
376 friend class AutofillManagerTest; | 374 friend class AutofillManagerTest; |
377 friend class FormStructureBrowserTest; | 375 friend class FormStructureBrowserTest; |
378 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 376 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
379 DeterminePossibleFieldTypesForUpload); | 377 DeterminePossibleFieldTypesForUpload); |
380 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 378 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
(...skipping 14 matching lines...) Expand all Loading... |
395 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 393 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
396 TestTabContentsWithExternalDelegate); | 394 TestTabContentsWithExternalDelegate); |
397 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, | 395 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, |
398 UserHappinessFormLoadAndSubmission); | 396 UserHappinessFormLoadAndSubmission); |
399 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 397 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
400 | 398 |
401 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 399 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
402 }; | 400 }; |
403 | 401 |
404 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 402 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
OLD | NEW |