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 <list> | |
9 #include <map> | 10 #include <map> |
10 #include <string> | 11 #include <string> |
12 #include <vector> | |
11 | 13 |
12 #include "base/scoped_vector.h" | 14 #include "base/scoped_vector.h" |
13 #include "base/time.h" | 15 #include "base/time.h" |
14 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
15 #include "chrome/browser/autofill/field_types.h" | 17 #include "chrome/browser/autofill/field_types.h" |
16 #include "chrome/browser/autofill/form_structure.h" | 18 #include "chrome/browser/autofill/form_structure.h" |
17 #include "chrome/common/net/url_fetcher.h" | 19 #include "chrome/common/net/url_fetcher.h" |
18 | 20 |
19 class AutoFillMetrics; | 21 class AutoFillMetrics; |
20 class Profile; | 22 class Profile; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 // percentages, they would be called once per 100 auto-fillable forms filled | 91 // percentages, they would be called once per 100 auto-fillable forms filled |
90 // and submitted by user. The order of magnitude would remain similar in the | 92 // and submitted by user. The order of magnitude would remain similar in the |
91 // future. | 93 // future. |
92 void SetPositiveUploadRate(double rate); | 94 void SetPositiveUploadRate(double rate); |
93 void SetNegativeUploadRate(double rate); | 95 void SetNegativeUploadRate(double rate); |
94 | 96 |
95 private: | 97 private: |
96 friend class AutoFillDownloadTestHelper; // unit-test. | 98 friend class AutoFillDownloadTestHelper; // unit-test. |
97 | 99 |
98 struct FormRequestData; | 100 struct FormRequestData; |
101 typedef std::list<std::pair<std::string, std::string> > QueryRequestCache; | |
99 | 102 |
100 // Initiates request to AutoFill servers to download/upload heuristics. | 103 // Initiates request to AutoFill servers to download/upload heuristics. |
101 // |form_xml| - form structure XML to upload/download. | 104 // |form_xml| - form structure XML to upload/download. |
102 // |request_data| - form signature hash(es) and indicator if it was a query. | 105 // |request_data| - form signature hash(es) and indicator if it was a query. |
103 // |request_data.query| - if true the data is queried and observer notified | 106 // |request_data.query| - if true the data is queried and observer notified |
104 // with new data, if available. If false heuristic data is uploaded to our | 107 // with new data, if available. If false heuristic data is uploaded to our |
105 // servers. | 108 // servers. |
106 bool StartRequest(const std::string& form_xml, | 109 bool StartRequest(const std::string& form_xml, |
107 const FormRequestData& request_data); | 110 const FormRequestData& request_data); |
108 | 111 |
112 // Each request is page visited. We store last |max_form_cache_size| | |
113 // request, to avoid going over the wire. Set to 16 in constructor. Warning: | |
114 // the search is linear (newest first), so do not make the constant very big. | |
115 void set_max_form_cache_size(size_t max_form_cache_size) { | |
116 max_form_cache_size_ = max_form_cache_size; | |
117 } | |
118 | |
119 // Caches query request. |forms_in_query| is a vector of form signatures in | |
120 // the query. |query_data| is the successfull data returned over the wire. | |
dhollowa
2011/01/26 00:15:02
nit: s/successfull/successful /
GeorgeY
2011/01/26 00:45:57
Too much doubled letters :). Fixed.
| |
121 void CacheQueryRequest(const std::vector<std::string>& forms_in_query, | |
122 const std::string& query_data); | |
123 // Returns true if query is in the cache, while filling |query_data|, false | |
124 // otherwise. |forms_in_query| is a vector of form signatures in the query. | |
125 bool CheckCacheForQueryRequest(const std::vector<std::string>& forms_in_query, | |
126 std::string* query_data) const; | |
127 // Concatenates |forms_in_query| into one signature. | |
128 std::string GetCombinedSignature( | |
129 const std::vector<std::string>& forms_in_query) const; | |
130 | |
109 // URLFetcher::Delegate implementation: | 131 // URLFetcher::Delegate implementation: |
110 virtual void OnURLFetchComplete(const URLFetcher* source, | 132 virtual void OnURLFetchComplete(const URLFetcher* source, |
111 const GURL& url, | 133 const GURL& url, |
112 const net::URLRequestStatus& status, | 134 const net::URLRequestStatus& status, |
113 int response_code, | 135 int response_code, |
114 const ResponseCookies& cookies, | 136 const ResponseCookies& cookies, |
115 const std::string& data); | 137 const std::string& data); |
116 | 138 |
117 // Profile for preference storage. | 139 // Profile for preference storage. |
118 Profile* profile_; | 140 Profile* profile_; |
119 | 141 |
120 // For each requested form for both query and upload we create a separate | 142 // For each requested form for both query and upload we create a separate |
121 // request and save its info. As url fetcher is identified by its address | 143 // request and save its info. As url fetcher is identified by its address |
122 // we use a map between fetchers and info. | 144 // we use a map between fetchers and info. |
123 std::map<URLFetcher*, FormRequestData> url_fetchers_; | 145 std::map<URLFetcher*, FormRequestData> url_fetchers_; |
124 AutoFillDownloadManager::Observer *observer_; | 146 AutoFillDownloadManager::Observer *observer_; |
125 | 147 |
148 // Cached QUERY requests. | |
149 QueryRequestCache cached_forms_; | |
150 size_t max_form_cache_size_; | |
151 | |
126 // Time when next query/upload requests are allowed. If 50x HTTP received, | 152 // Time when next query/upload requests are allowed. If 50x HTTP received, |
127 // exponential back off is initiated, so this times will be in the future | 153 // exponential back off is initiated, so this times will be in the future |
128 // for awhile. | 154 // for awhile. |
129 base::Time next_query_request_; | 155 base::Time next_query_request_; |
130 base::Time next_upload_request_; | 156 base::Time next_upload_request_; |
131 | 157 |
132 // |positive_upload_rate_| is for matched forms, | 158 // |positive_upload_rate_| is for matched forms, |
133 // |negative_upload_rate_| for non matched. | 159 // |negative_upload_rate_| for non matched. |
134 double positive_upload_rate_; | 160 double positive_upload_rate_; |
135 double negative_upload_rate_; | 161 double negative_upload_rate_; |
136 | 162 |
137 // Needed for unit-test. | 163 // Needed for unit-test. |
138 int fetcher_id_for_unittest_; | 164 int fetcher_id_for_unittest_; |
139 bool is_testing_; | 165 bool is_testing_; |
140 }; | 166 }; |
141 | 167 |
142 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ | 168 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DOWNLOAD_H_ |
143 | 169 |
OLD | NEW |