Chromium Code Reviews| 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 #include "chrome/browser/autofill/autofill_download.h" | 5 #include "chrome/browser/autofill/autofill_download.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/browser/autofill/autofill_metrics.h" | 15 #include "chrome/browser/autofill/autofill_metrics.h" |
| 16 #include "chrome/browser/autofill/autofill_xml_parser.h" | 16 #include "chrome/browser/autofill/autofill_xml_parser.h" |
| 17 #include "chrome/browser/autofill/form_structure.h" | 17 #include "chrome/browser/autofill/form_structure.h" |
| 18 #include "chrome/browser/api/prefs/pref_service_base.h" | 18 #include "chrome/browser/api/prefs/pref_service_base.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 24 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
| 25 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" | 25 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" |
| 26 | 26 |
| 27 using content::BrowserContext; | 27 using content::BrowserContext; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 const char kAutofillQueryServerRequestUrl[] = | |
| 31 "https://clients1.google.com/tbproxy/af/query?client="; | |
| 32 const char kAutofillUploadServerRequestUrl[] = | |
| 33 "https://clients1.google.com/tbproxy/af/upload?client="; | |
| 34 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; | 30 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; |
| 35 | 31 |
| 36 #if defined(GOOGLE_CHROME_BUILD) | |
| 37 const char kClientName[] = "Google Chrome"; | |
| 38 #else | |
| 39 const char kClientName[] = "Chromium"; | |
| 40 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 41 | |
| 42 const size_t kMaxFormCacheSize = 16; | 32 const size_t kMaxFormCacheSize = 16; |
| 43 }; | 33 }; |
| 44 | 34 |
| 45 struct AutofillDownloadManager::FormRequestData { | 35 struct AutofillDownloadManager::FormRequestData { |
| 46 std::vector<std::string> form_signatures; | 36 std::vector<std::string> form_signatures; |
| 47 AutofillRequestType request_type; | 37 AutofillRequestType request_type; |
| 48 }; | 38 }; |
| 49 | 39 |
| 50 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context, | 40 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context, |
| 51 Observer* observer) | 41 Observer* observer) |
| 52 : browser_context_(context), | 42 : browser_context_(context), |
| 53 observer_(observer), | 43 observer_(observer), |
| 54 max_form_cache_size_(kMaxFormCacheSize), | 44 max_form_cache_size_(kMaxFormCacheSize), |
| 55 next_query_request_(base::Time::Now()), | 45 next_query_request_(base::Time::Now()), |
| 56 next_upload_request_(base::Time::Now()), | 46 next_upload_request_(base::Time::Now()), |
| 57 positive_upload_rate_(0), | 47 positive_upload_rate_(0), |
| 58 negative_upload_rate_(0), | 48 negative_upload_rate_(0), |
| 59 fetcher_id_for_unittest_(0) { | 49 fetcher_id_for_unittest_(0) { |
| 60 DCHECK(observer_); | 50 DCHECK(observer_); |
| 61 PrefServiceBase* preferences = | 51 PrefServiceBase* preferences = |
| 62 PrefServiceBase::FromBrowserContext(browser_context_); | 52 PrefServiceBase::FromBrowserContext(browser_context_); |
| 53 autofill_download_url_ = new AutofillDownloadUrl(preferences); | |
|
Ilya Sherman
2012/10/23 23:45:13
This will leak...
Albert Bodenhamer
2012/10/23 23:57:11
Currently there's a leak here. Most consumers of
ahutter
2012/10/24 17:33:45
Done.
| |
| 63 positive_upload_rate_ = | 54 positive_upload_rate_ = |
| 64 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); | 55 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); |
| 65 negative_upload_rate_ = | 56 negative_upload_rate_ = |
| 66 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); | 57 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); |
| 67 } | 58 } |
| 68 | 59 |
| 69 AutofillDownloadManager::~AutofillDownloadManager() { | 60 AutofillDownloadManager::~AutofillDownloadManager() { |
| 70 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), | 61 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), |
| 71 url_fetchers_.end()); | 62 url_fetchers_.end()); |
| 72 } | 63 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 browser_context_); | 152 browser_context_); |
| 162 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); | 153 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); |
| 163 } | 154 } |
| 164 | 155 |
| 165 bool AutofillDownloadManager::StartRequest( | 156 bool AutofillDownloadManager::StartRequest( |
| 166 const std::string& form_xml, | 157 const std::string& form_xml, |
| 167 const FormRequestData& request_data) { | 158 const FormRequestData& request_data) { |
| 168 net::URLRequestContextGetter* request_context = | 159 net::URLRequestContextGetter* request_context = |
| 169 browser_context_->GetRequestContext(); | 160 browser_context_->GetRequestContext(); |
| 170 DCHECK(request_context); | 161 DCHECK(request_context); |
| 171 std::string request_url; | 162 GURL request_url; |
| 172 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) | 163 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) |
| 173 request_url = kAutofillQueryServerRequestUrl; | 164 request_url = autofill_download_url_->GetAutofillRequestUrl(); |
| 174 else | 165 else |
| 175 request_url = kAutofillUploadServerRequestUrl; | 166 request_url = autofill_download_url_->GetAutofillUploadUrl(); |
| 176 request_url += kClientName; | |
| 177 | 167 |
| 178 // Id is ignored for regular chrome, in unit test id's for fake fetcher | 168 // Id is ignored for regular chrome, in unit test id's for fake fetcher |
| 179 // factory will be 0, 1, 2, ... | 169 // factory will be 0, 1, 2, ... |
| 180 net::URLFetcher* fetcher = net::URLFetcher::Create( | 170 net::URLFetcher* fetcher = net::URLFetcher::Create( |
| 181 fetcher_id_for_unittest_++, GURL(request_url), net::URLFetcher::POST, | 171 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST, |
| 182 this); | 172 this); |
| 183 url_fetchers_[fetcher] = request_data; | 173 url_fetchers_[fetcher] = request_data; |
| 184 fetcher->SetAutomaticallyRetryOn5xx(false); | 174 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 185 fetcher->SetRequestContext(request_context); | 175 fetcher->SetRequestContext(request_context); |
| 186 fetcher->SetUploadData("text/plain", form_xml); | 176 fetcher->SetUploadData("text/plain", form_xml); |
| 187 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 177 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 188 net::LOAD_DO_NOT_SEND_COOKIES); | 178 net::LOAD_DO_NOT_SEND_COOKIES); |
| 189 fetcher->Start(); | 179 fetcher->Start(); |
| 190 return true; | 180 return true; |
| 191 } | 181 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 SetPositiveUploadRate(new_positive_upload_rate); | 305 SetPositiveUploadRate(new_positive_upload_rate); |
| 316 SetNegativeUploadRate(new_negative_upload_rate); | 306 SetNegativeUploadRate(new_negative_upload_rate); |
| 317 } | 307 } |
| 318 | 308 |
| 319 observer_->OnUploadedPossibleFieldTypes(); | 309 observer_->OnUploadedPossibleFieldTypes(); |
| 320 } | 310 } |
| 321 } | 311 } |
| 322 delete it->first; | 312 delete it->first; |
| 323 url_fetchers_.erase(it); | 313 url_fetchers_.erase(it); |
| 324 } | 314 } |
| OLD | NEW |