| 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/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/autofill/autofill_download_url.h" | 16 #include "chrome/browser/autofill/autofill_download_url.h" |
| 17 #include "chrome/browser/autofill/autofill_metrics.h" | 17 #include "chrome/browser/autofill/autofill_metrics.h" |
| 18 #include "chrome/browser/autofill/autofill_xml_parser.h" | 18 #include "chrome/browser/autofill/autofill_xml_parser.h" |
| 19 #include "chrome/browser/autofill/form_structure.h" | 19 #include "chrome/browser/autofill/form_structure.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_prefs/user_prefs.h" |
| 21 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 24 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
| 26 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" | 27 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" |
| 27 | 28 |
| 28 using content::BrowserContext; | 29 using content::BrowserContext; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 52 : browser_context_(context), | 53 : browser_context_(context), |
| 53 observer_(observer), | 54 observer_(observer), |
| 54 max_form_cache_size_(kMaxFormCacheSize), | 55 max_form_cache_size_(kMaxFormCacheSize), |
| 55 next_query_request_(base::Time::Now()), | 56 next_query_request_(base::Time::Now()), |
| 56 next_upload_request_(base::Time::Now()), | 57 next_upload_request_(base::Time::Now()), |
| 57 positive_upload_rate_(0), | 58 positive_upload_rate_(0), |
| 58 negative_upload_rate_(0), | 59 negative_upload_rate_(0), |
| 59 fetcher_id_for_unittest_(0) { | 60 fetcher_id_for_unittest_(0) { |
| 60 DCHECK(observer_); | 61 DCHECK(observer_); |
| 61 PrefService* preferences = | 62 PrefService* preferences = |
| 62 PrefServiceFromBrowserContext(browser_context_); | 63 components::UserPrefs::GetInstance()->Lookup(browser_context_); |
| 63 positive_upload_rate_ = | 64 positive_upload_rate_ = |
| 64 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); | 65 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); |
| 65 negative_upload_rate_ = | 66 negative_upload_rate_ = |
| 66 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); | 67 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); |
| 67 } | 68 } |
| 68 | 69 |
| 69 AutofillDownloadManager::~AutofillDownloadManager() { | 70 AutofillDownloadManager::~AutofillDownloadManager() { |
| 70 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), | 71 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), |
| 71 url_fetchers_.end()); | 72 url_fetchers_.end()); |
| 72 } | 73 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 double AutofillDownloadManager::GetNegativeUploadRate() const { | 142 double AutofillDownloadManager::GetNegativeUploadRate() const { |
| 142 return negative_upload_rate_; | 143 return negative_upload_rate_; |
| 143 } | 144 } |
| 144 | 145 |
| 145 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { | 146 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { |
| 146 if (rate == positive_upload_rate_) | 147 if (rate == positive_upload_rate_) |
| 147 return; | 148 return; |
| 148 positive_upload_rate_ = rate; | 149 positive_upload_rate_ = rate; |
| 149 DCHECK_GE(rate, 0.0); | 150 DCHECK_GE(rate, 0.0); |
| 150 DCHECK_LE(rate, 1.0); | 151 DCHECK_LE(rate, 1.0); |
| 151 PrefService* preferences = PrefServiceFromBrowserContext( | 152 PrefService* preferences = components::UserPrefs::GetInstance()->Lookup( |
| 152 browser_context_); | 153 browser_context_); |
| 153 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); | 154 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { | 157 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { |
| 157 if (rate == negative_upload_rate_) | 158 if (rate == negative_upload_rate_) |
| 158 return; | 159 return; |
| 159 negative_upload_rate_ = rate; | 160 negative_upload_rate_ = rate; |
| 160 DCHECK_GE(rate, 0.0); | 161 DCHECK_GE(rate, 0.0); |
| 161 DCHECK_LE(rate, 1.0); | 162 DCHECK_LE(rate, 1.0); |
| 162 PrefService* preferences = PrefServiceFromBrowserContext( | 163 PrefService* preferences = components::UserPrefs::GetInstance()->Lookup( |
| 163 browser_context_); | 164 browser_context_); |
| 164 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); | 165 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool AutofillDownloadManager::StartRequest( | 168 bool AutofillDownloadManager::StartRequest( |
| 168 const std::string& form_xml, | 169 const std::string& form_xml, |
| 169 const FormRequestData& request_data) { | 170 const FormRequestData& request_data) { |
| 170 net::URLRequestContextGetter* request_context = | 171 net::URLRequestContextGetter* request_context = |
| 171 browser_context_->GetRequestContext(); | 172 browser_context_->GetRequestContext(); |
| 172 DCHECK(request_context); | 173 DCHECK(request_context); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 SetPositiveUploadRate(new_positive_upload_rate); | 317 SetPositiveUploadRate(new_positive_upload_rate); |
| 317 SetNegativeUploadRate(new_negative_upload_rate); | 318 SetNegativeUploadRate(new_negative_upload_rate); |
| 318 } | 319 } |
| 319 | 320 |
| 320 observer_->OnUploadedPossibleFieldTypes(); | 321 observer_->OnUploadedPossibleFieldTypes(); |
| 321 } | 322 } |
| 322 } | 323 } |
| 323 delete it->first; | 324 delete it->first; |
| 324 url_fetchers_.erase(it); | 325 url_fetchers_.erase(it); |
| 325 } | 326 } |
| OLD | NEW |