| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 19 #include "base/string16.h" | 20 #include "base/string16.h" |
| 20 #include "base/time.h" | 21 #include "base/time.h" |
| 21 #include "chrome/browser/autofill/autofill_download.h" | 22 #include "chrome/browser/autofill/autofill_download.h" |
| 22 #include "chrome/browser/autofill/field_types.h" | 23 #include "chrome/browser/autofill/field_types.h" |
| 23 #include "chrome/browser/autofill/form_structure.h" | 24 #include "chrome/browser/autofill/form_structure.h" |
| 24 #include "content/browser/tab_contents/tab_contents_observer.h" | 25 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 25 | 26 |
| 26 class AutofillExternalDelegate; | 27 class AutofillExternalDelegate; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 } | 41 } |
| 41 | 42 |
| 42 namespace webkit_glue { | 43 namespace webkit_glue { |
| 43 struct FormData; | 44 struct FormData; |
| 44 struct FormField; | 45 struct FormField; |
| 45 } | 46 } |
| 46 | 47 |
| 47 // Manages saving and restoring the user's personal information entered into web | 48 // Manages saving and restoring the user's personal information entered into web |
| 48 // forms. | 49 // forms. |
| 49 class AutofillManager : public TabContentsObserver, | 50 class AutofillManager : public TabContentsObserver, |
| 50 public AutofillDownloadManager::Observer { | 51 public AutofillDownloadManager::Observer, |
| 52 public base::RefCounted<AutofillManager> { |
| 51 public: | 53 public: |
| 52 explicit AutofillManager(TabContentsWrapper* tab_contents); | 54 explicit AutofillManager(TabContentsWrapper* tab_contents); |
| 53 virtual ~AutofillManager(); | |
| 54 | 55 |
| 55 // Registers our Enable/Disable Autofill pref. | 56 // Registers our Enable/Disable Autofill pref. |
| 56 static void RegisterUserPrefs(PrefService* prefs); | 57 static void RegisterUserPrefs(PrefService* prefs); |
| 57 | 58 |
| 58 // Set our external delegate. | 59 // Set our external delegate. |
| 59 // TODO(jrg): consider passing delegate into the ctor. That won't | 60 // TODO(jrg): consider passing delegate into the ctor. That won't |
| 60 // work if the delegate has a pointer to the AutofillManager, but | 61 // work if the delegate has a pointer to the AutofillManager, but |
| 61 // future directions may not need such a pointer. | 62 // future directions may not need such a pointer. |
| 62 void SetExternalDelegate(AutofillExternalDelegate* delegate) { | 63 void SetExternalDelegate(AutofillExternalDelegate* delegate) { |
| 63 external_delegate_ = delegate; | 64 external_delegate_ = delegate; |
| 64 } | 65 } |
| 65 | 66 |
| 66 protected: | 67 protected: |
| 67 // Only test code should subclass AutofillManager. | 68 // Only test code should subclass AutofillManager. |
| 69 friend class base::RefCounted<AutofillManager>; |
| 70 virtual ~AutofillManager(); |
| 68 | 71 |
| 69 // The string/int pair is composed of the guid string and variant index | 72 // The string/int pair is composed of the guid string and variant index |
| 70 // respectively. The variant index is an index into the multi-valued item | 73 // respectively. The variant index is an index into the multi-valued item |
| 71 // (where applicable). | 74 // (where applicable). |
| 72 typedef std::pair<std::string, size_t> GUIDPair; | 75 typedef std::pair<std::string, size_t> GUIDPair; |
| 73 | 76 |
| 74 // Test code should prefer to use this constructor. | 77 // Test code should prefer to use this constructor. |
| 75 AutofillManager(TabContentsWrapper* tab_contents, | 78 AutofillManager(TabContentsWrapper* tab_contents, |
| 76 PersonalDataManager* personal_data); | 79 PersonalDataManager* personal_data); |
| 77 | 80 |
| 78 // Returns the value of the AutofillEnabled pref. | 81 // Returns the value of the AutofillEnabled pref. |
| 79 virtual bool IsAutofillEnabled() const; | 82 virtual bool IsAutofillEnabled() const; |
| 80 | 83 |
| 81 // Uploads the form data to the Autofill server. | 84 // Uploads the form data to the Autofill server. |
| 82 virtual void UploadFormData(const FormStructure& submitted_form); | 85 virtual void UploadFormData(const FormStructure& submitted_form); |
| 83 | 86 |
| 84 // Reset cache. | 87 // Reset cache. |
| 85 void Reset(); | 88 void Reset(); |
| 86 | 89 |
| 90 // Logs quality metrics for the |submitted_form| and uploads the form data |
| 91 // to the crowdsourcing server, if appropriate. |
| 92 virtual void UploadFormDataAsyncCallback( |
| 93 const FormStructure* submitted_form, |
| 94 const base::TimeTicks& load_time, |
| 95 const base::TimeTicks& interaction_time, |
| 96 const base::TimeTicks& submission_time); |
| 97 |
| 87 // Maps GUIDs to and from IDs that are used to identify profiles and credit | 98 // Maps GUIDs to and from IDs that are used to identify profiles and credit |
| 88 // cards sent to and from the renderer process. | 99 // cards sent to and from the renderer process. |
| 89 virtual int GUIDToID(const GUIDPair& guid) const; | 100 virtual int GUIDToID(const GUIDPair& guid) const; |
| 90 virtual const GUIDPair IDToGUID(int id) const; | 101 virtual const GUIDPair IDToGUID(int id) const; |
| 91 | 102 |
| 92 // Methods for packing and unpacking credit card and profile IDs for sending | 103 // Methods for packing and unpacking credit card and profile IDs for sending |
| 93 // and receiving to and from the renderer process. | 104 // and receiving to and from the renderer process. |
| 94 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const; | 105 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const; |
| 95 void UnpackGUIDs(int id, GUIDPair* cc_guid, GUIDPair* profile_guid) const; | 106 void UnpackGUIDs(int id, GUIDPair* cc_guid, GUIDPair* profile_guid) const; |
| 96 | 107 |
| 97 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } | 108 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } |
| 98 void set_metric_logger(const AutofillMetrics* metric_logger); | 109 void set_metric_logger(const AutofillMetrics* metric_logger); |
| 99 | 110 |
| 100 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } | 111 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } |
| 101 | 112 |
| 102 // Called from our external delegate so it cannot be private. | 113 // Called from our external delegate so it cannot be private. |
| 103 void OnFillAutoFillFormData(int query_id, | 114 void OnFillAutoFillFormData(int query_id, |
| 104 const webkit_glue::FormData& form, | 115 const webkit_glue::FormData& form, |
| 105 const webkit_glue::FormField& field, | 116 const webkit_glue::FormField& field, |
| 106 int unique_id); | 117 int unique_id); |
| 107 | 118 |
| 108 // Exposed for testing. | 119 // Exposed for testing. |
| 109 AutofillExternalDelegate* external_delegate() { | 120 AutofillExternalDelegate* external_delegate() { |
| 110 return external_delegate_; | 121 return external_delegate_; |
| 111 } | 122 } |
| 112 | 123 |
| 124 // Processes the submitted |form|, saving any new Autofill data and uploading |
| 125 // the possible field types for the submitted fields to the crowdsouring |
| 126 // server. Returns false if this form is not relevant for Autofill. |
| 127 bool OnFormSubmitted(const webkit_glue::FormData& form, |
| 128 const base::TimeTicks& timestamp); |
| 129 |
| 113 private: | 130 private: |
| 114 // TabContentsObserver: | 131 // TabContentsObserver: |
| 115 virtual void DidNavigateMainFramePostCommit( | 132 virtual void DidNavigateMainFramePostCommit( |
| 116 const content::LoadCommittedDetails& details, | 133 const content::LoadCommittedDetails& details, |
| 117 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; | 134 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; |
| 118 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 135 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 119 | 136 |
| 120 // AutofillDownloadManager::Observer: | 137 // AutofillDownloadManager::Observer: |
| 121 virtual void OnLoadedServerPredictions( | 138 virtual void OnLoadedServerPredictions( |
| 122 const std::string& response_xml) OVERRIDE; | 139 const std::string& response_xml) OVERRIDE; |
| 123 | 140 |
| 124 void OnFormSubmitted(const webkit_glue::FormData& form, | |
| 125 const base::TimeTicks& timestamp); | |
| 126 void OnFormsSeen(const std::vector<webkit_glue::FormData>& forms, | 141 void OnFormsSeen(const std::vector<webkit_glue::FormData>& forms, |
| 127 const base::TimeTicks& timestamp); | 142 const base::TimeTicks& timestamp); |
| 128 void OnTextFieldDidChange(const webkit_glue::FormData& form, | 143 void OnTextFieldDidChange(const webkit_glue::FormData& form, |
| 129 const webkit_glue::FormField& field, | 144 const webkit_glue::FormField& field, |
| 130 const base::TimeTicks& timestamp); | 145 const base::TimeTicks& timestamp); |
| 131 void OnQueryFormFieldAutofill(int query_id, | 146 void OnQueryFormFieldAutofill(int query_id, |
| 132 const webkit_glue::FormData& form, | 147 const webkit_glue::FormData& form, |
| 133 const webkit_glue::FormField& field); | 148 const webkit_glue::FormField& field); |
| 134 void OnFillAutofillFormData(int query_id, | 149 void OnFillAutofillFormData(int query_id, |
| 135 const webkit_glue::FormData& form, | 150 const webkit_glue::FormData& form, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // phone prefix or suffix. The |variant| parameter specifies which value in a | 231 // phone prefix or suffix. The |variant| parameter specifies which value in a |
| 217 // multi-valued profile. | 232 // multi-valued profile. |
| 218 void FillPhoneNumberField(const AutofillProfile& profile, | 233 void FillPhoneNumberField(const AutofillProfile& profile, |
| 219 const AutofillField& cached_field, | 234 const AutofillField& cached_field, |
| 220 size_t variant, | 235 size_t variant, |
| 221 webkit_glue::FormField* field); | 236 webkit_glue::FormField* field); |
| 222 | 237 |
| 223 // Parses the forms using heuristic matching and querying the Autofill server. | 238 // Parses the forms using heuristic matching and querying the Autofill server. |
| 224 void ParseForms(const std::vector<webkit_glue::FormData>& forms); | 239 void ParseForms(const std::vector<webkit_glue::FormData>& forms); |
| 225 | 240 |
| 226 // Uses existing personal data to determine possible field types for the | |
| 227 // |submitted_form|. | |
| 228 void DeterminePossibleFieldTypesForUpload(FormStructure* submitted_form); | |
| 229 | |
| 230 // Imports the form data, submitted by the user, into |personal_data_|. | 241 // Imports the form data, submitted by the user, into |personal_data_|. |
| 231 void ImportFormData(const FormStructure& submitted_form); | 242 void ImportFormData(const FormStructure& submitted_form); |
| 232 | 243 |
| 233 // If |initial_interaction_timestamp_| is unset or is set to a later time than | 244 // If |initial_interaction_timestamp_| is unset or is set to a later time than |
| 234 // |interaction_timestamp|, updates the cached timestamp. The latter check is | 245 // |interaction_timestamp|, updates the cached timestamp. The latter check is |
| 235 // needed because IPC messages can arrive out of order. | 246 // needed because IPC messages can arrive out of order. |
| 236 void UpdateInitialInteractionTimestamp( | 247 void UpdateInitialInteractionTimestamp( |
| 237 const base::TimeTicks& interaction_timestamp); | 248 const base::TimeTicks& interaction_timestamp); |
| 238 | 249 |
| 239 // Send our current field type predictions to the renderer. This is a no-op if | 250 // Send our current field type predictions to the renderer. This is a no-op if |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 TestTabContentsWithExternalDelegate); | 322 TestTabContentsWithExternalDelegate); |
| 312 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, | 323 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, |
| 313 UserHappinessFormLoadAndSubmission); | 324 UserHappinessFormLoadAndSubmission); |
| 314 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 325 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
| 315 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); | 326 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); |
| 316 | 327 |
| 317 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 328 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
| 318 }; | 329 }; |
| 319 | 330 |
| 320 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ | 331 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ |
| OLD | NEW |