Chromium Code Reviews| 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_DOWNLOAD_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 // Handles getting and updating Autofill heuristics. | 31 // Handles getting and updating Autofill heuristics. |
| 32 class AutofillDownloadManager : public content::URLFetcherDelegate { | 32 class AutofillDownloadManager : public content::URLFetcherDelegate { |
| 33 public: | 33 public: |
| 34 enum AutofillRequestType { | 34 enum AutofillRequestType { |
| 35 REQUEST_QUERY, | 35 REQUEST_QUERY, |
| 36 REQUEST_UPLOAD, | 36 REQUEST_UPLOAD, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // An interface used to notify clients of AutofillDownloadManager. | 39 // An interface used to notify clients of AutofillDownloadManager. |
| 40 // Notifications are *not* guaranteed to be called. | |
| 41 class Observer { | 40 class Observer { |
| 42 public: | 41 public: |
| 43 // Called when field type predictions are successfully received from the | 42 // Called when field type predictions are successfully received from the |
| 44 // server. | 43 // server. |response_xml| contains the server response. |
| 45 // |response_xml| - server response. | |
| 46 virtual void OnLoadedServerPredictions(const std::string& response_xml) = 0; | 44 virtual void OnLoadedServerPredictions(const std::string& response_xml) = 0; |
| 45 | |
| 46 // These notifications are used to help with testing. | |
| 47 // Called when heuristic either successfully considered for upload and | 47 // Called when heuristic either successfully considered for upload and |
| 48 // not send or uploaded. | 48 // not send or uploaded. |
| 49 virtual void OnUploadedPossibleFieldTypes() = 0; | 49 virtual void OnUploadedPossibleFieldTypes() {} |
| 50 // Called when there was an error during the request. | 50 // Called when there was an error during the request. |
| 51 // |form_signature| - the signature of the requesting form. | 51 // |form_signature| - the signature of the requesting form. |
| 52 // |request_type| - type of request that failed. | 52 // |request_type| - type of request that failed. |
| 53 // |http_error| - HTTP error code. | 53 // |http_error| - HTTP error code. |
| 54 virtual void OnServerRequestError(const std::string& form_signature, | 54 virtual void OnServerRequestError(const std::string& form_signature, |
| 55 AutofillRequestType request_type, | 55 AutofillRequestType request_type, |
| 56 int http_error) = 0; | 56 int http_error) {} |
| 57 | |
| 57 protected: | 58 protected: |
| 58 virtual ~Observer() {} | 59 virtual ~Observer() {} |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 // |profile| can be NULL in unit-tests only. | 62 // |observer| - observer to notify on successful completion or error. |
| 62 explicit AutofillDownloadManager(Profile* profile); | 63 AutofillDownloadManager(Profile* profile, Observer* observer); |
| 63 virtual ~AutofillDownloadManager(); | 64 virtual ~AutofillDownloadManager(); |
| 64 | 65 |
| 65 // |observer| - observer to notify on successful completion or error. | |
| 66 void SetObserver(AutofillDownloadManager::Observer* observer); | |
| 67 | |
| 68 // Starts a query request to Autofill servers. The observer is called with the | 66 // Starts a query request to Autofill servers. The observer is called with the |
| 69 // list of the fields of all requested forms. | 67 // list of the fields of all requested forms. |
| 70 // |forms| - array of forms aggregated in this request. | 68 // |forms| - array of forms aggregated in this request. |
| 71 bool StartQueryRequest(const std::vector<FormStructure*>& forms, | 69 bool StartQueryRequest(const std::vector<FormStructure*>& forms, |
| 72 const AutofillMetrics& metric_logger); | 70 const AutofillMetrics& metric_logger); |
| 73 | 71 |
| 74 // Starts an upload request for the given |form|, unless throttled by the | 72 // Starts an upload request for the given |form|, unless throttled by the |
| 75 // server. The probability of the request going over the wire is | 73 // server. The probability of the request going over the wire is |
| 76 // GetPositiveUploadRate() if |form_was_autofilled| is true, or | 74 // GetPositiveUploadRate() if |form_was_autofilled| is true, or |
| 77 // GetNegativeUploadRate() otherwise. The observer will be called even if | 75 // GetNegativeUploadRate() otherwise. The observer will be called even if |
| 78 // there was no actual trip over the wire. | 76 // there was no actual trip over the wire. |
| 79 // |available_field_types| should contain the types for which we have data | 77 // |available_field_types| should contain the types for which we have data |
| 80 // stored on the local client. | 78 // stored on the local client. |
| 81 bool StartUploadRequest(const FormStructure& form, | 79 bool StartUploadRequest(const FormStructure& form, |
| 82 bool form_was_autofilled, | 80 bool form_was_autofilled, |
| 83 const FieldTypeSet& available_field_types); | 81 const FieldTypeSet& available_field_types); |
| 84 | 82 |
| 85 // Cancels pending request. | |
| 86 // |form_signature| - signature of the form being cancelled. Warning: | |
| 87 // for query request if more than one form sent in the request, all other | |
| 88 // forms will be cancelled as well. | |
| 89 // |request_type| - type of the request. | |
| 90 bool CancelRequest(const std::string& form_signature, | |
| 91 AutofillRequestType request_type); | |
| 92 | |
| 93 private: | 83 private: |
| 94 friend class AutofillDownloadTest; | 84 friend class AutofillDownloadTest; |
| 95 FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, QueryAndUploadTest); | 85 FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, QueryAndUploadTest); |
| 96 | 86 |
| 97 struct FormRequestData; | 87 struct FormRequestData; |
| 98 typedef std::list<std::pair<std::string, std::string> > QueryRequestCache; | 88 typedef std::list<std::pair<std::string, std::string> > QueryRequestCache; |
| 99 | 89 |
| 100 // Initiates request to Autofill servers to download/upload heuristics. | 90 // Initiates request to Autofill servers to download/upload heuristics. |
| 101 // |form_xml| - form structure XML to upload/download. | 91 // |form_xml| - form structure XML to upload/download. |
| 102 // |request_data| - form signature hash(es) and indicator if it was a query. | 92 // |request_data| - form signature hash(es) and indicator if it was a query. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 130 | 120 |
| 131 // Probability of the form upload. Between 0 (no upload) and 1 (upload all). | 121 // Probability of the form upload. Between 0 (no upload) and 1 (upload all). |
| 132 // GetPositiveUploadRate() is for matched forms, | 122 // GetPositiveUploadRate() is for matched forms, |
| 133 // GetNegativeUploadRate() for non-matched. | 123 // GetNegativeUploadRate() for non-matched. |
| 134 double GetPositiveUploadRate() const; | 124 double GetPositiveUploadRate() const; |
| 135 double GetNegativeUploadRate() const; | 125 double GetNegativeUploadRate() const; |
| 136 void SetPositiveUploadRate(double rate); | 126 void SetPositiveUploadRate(double rate); |
| 137 void SetNegativeUploadRate(double rate); | 127 void SetNegativeUploadRate(double rate); |
| 138 | 128 |
| 139 // Profile for preference storage. | 129 // Profile for preference storage. |
| 140 Profile* profile_; | 130 Profile* const profile_; // WEAK |
|
dhollowa
2011/10/26 15:58:33
It would be helpful to add a comment that profile_
Ilya Sherman
2011/10/26 23:06:32
Done.
| |
| 131 // The observer to notify when server predictions are successfully received. | |
| 132 AutofillDownloadManager::Observer* const observer_; // WEAK | |
|
dhollowa
2011/10/26 15:58:33
It would be helpful to add a comment that observer
Ilya Sherman
2011/10/26 23:06:32
Done.
| |
| 141 | 133 |
| 142 // For each requested form for both query and upload we create a separate | 134 // For each requested form for both query and upload we create a separate |
| 143 // request and save its info. As url fetcher is identified by its address | 135 // request and save its info. As url fetcher is identified by its address |
| 144 // we use a map between fetchers and info. | 136 // we use a map between fetchers and info. |
| 145 std::map<content::URLFetcher*, FormRequestData> url_fetchers_; | 137 std::map<content::URLFetcher*, FormRequestData> url_fetchers_; |
| 146 AutofillDownloadManager::Observer *observer_; | |
| 147 | 138 |
| 148 // Cached QUERY requests. | 139 // Cached QUERY requests. |
| 149 QueryRequestCache cached_forms_; | 140 QueryRequestCache cached_forms_; |
| 150 size_t max_form_cache_size_; | 141 size_t max_form_cache_size_; |
| 151 | 142 |
| 152 // Time when next query/upload requests are allowed. If 50x HTTP received, | 143 // Time when next query/upload requests are allowed. If 50x HTTP received, |
| 153 // exponential back off is initiated, so this times will be in the future | 144 // exponential back off is initiated, so this times will be in the future |
| 154 // for awhile. | 145 // for awhile. |
| 155 base::Time next_query_request_; | 146 base::Time next_query_request_; |
| 156 base::Time next_upload_request_; | 147 base::Time next_upload_request_; |
| 157 | 148 |
| 158 // |positive_upload_rate_| is for matched forms, | 149 // |positive_upload_rate_| is for matched forms, |
| 159 // |negative_upload_rate_| for non matched. | 150 // |negative_upload_rate_| for non matched. |
| 160 double positive_upload_rate_; | 151 double positive_upload_rate_; |
| 161 double negative_upload_rate_; | 152 double negative_upload_rate_; |
| 162 | 153 |
| 163 // Needed for unit-test. | 154 // Needed for unit-test. |
| 164 int fetcher_id_for_unittest_; | 155 int fetcher_id_for_unittest_; |
| 165 }; | 156 }; |
| 166 | 157 |
| 167 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ | 158 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ |
| OLD | NEW |