| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 Observer* observer) | 64 Observer* observer) |
| 64 : browser_context_(context), | 65 : browser_context_(context), |
| 65 observer_(observer), | 66 observer_(observer), |
| 66 max_form_cache_size_(kMaxFormCacheSize), | 67 max_form_cache_size_(kMaxFormCacheSize), |
| 67 next_query_request_(base::Time::Now()), | 68 next_query_request_(base::Time::Now()), |
| 68 next_upload_request_(base::Time::Now()), | 69 next_upload_request_(base::Time::Now()), |
| 69 positive_upload_rate_(0), | 70 positive_upload_rate_(0), |
| 70 negative_upload_rate_(0), | 71 negative_upload_rate_(0), |
| 71 fetcher_id_for_unittest_(0) { | 72 fetcher_id_for_unittest_(0) { |
| 72 DCHECK(observer_); | 73 DCHECK(observer_); |
| 73 PrefService* preferences = | 74 PrefService* preferences = components::UserPrefs::Get(browser_context_); |
| 74 PrefServiceFromBrowserContext(browser_context_); | |
| 75 positive_upload_rate_ = | 75 positive_upload_rate_ = |
| 76 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); | 76 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); |
| 77 negative_upload_rate_ = | 77 negative_upload_rate_ = |
| 78 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); | 78 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); |
| 79 } | 79 } |
| 80 | 80 |
| 81 AutofillDownloadManager::~AutofillDownloadManager() { | 81 AutofillDownloadManager::~AutofillDownloadManager() { |
| 82 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), | 82 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), |
| 83 url_fetchers_.end()); | 83 url_fetchers_.end()); |
| 84 } | 84 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 double AutofillDownloadManager::GetNegativeUploadRate() const { | 153 double AutofillDownloadManager::GetNegativeUploadRate() const { |
| 154 return negative_upload_rate_; | 154 return negative_upload_rate_; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { | 157 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { |
| 158 if (rate == positive_upload_rate_) | 158 if (rate == positive_upload_rate_) |
| 159 return; | 159 return; |
| 160 positive_upload_rate_ = rate; | 160 positive_upload_rate_ = rate; |
| 161 DCHECK_GE(rate, 0.0); | 161 DCHECK_GE(rate, 0.0); |
| 162 DCHECK_LE(rate, 1.0); | 162 DCHECK_LE(rate, 1.0); |
| 163 PrefService* preferences = PrefServiceFromBrowserContext( | 163 PrefService* preferences = components::UserPrefs::Get(browser_context_); |
| 164 browser_context_); | |
| 165 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); | 164 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { | 167 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { |
| 169 if (rate == negative_upload_rate_) | 168 if (rate == negative_upload_rate_) |
| 170 return; | 169 return; |
| 171 negative_upload_rate_ = rate; | 170 negative_upload_rate_ = rate; |
| 172 DCHECK_GE(rate, 0.0); | 171 DCHECK_GE(rate, 0.0); |
| 173 DCHECK_LE(rate, 1.0); | 172 DCHECK_LE(rate, 1.0); |
| 174 PrefService* preferences = PrefServiceFromBrowserContext( | 173 PrefService* preferences = components::UserPrefs::Get(browser_context_); |
| 175 browser_context_); | |
| 176 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); | 174 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); |
| 177 } | 175 } |
| 178 | 176 |
| 179 bool AutofillDownloadManager::StartRequest( | 177 bool AutofillDownloadManager::StartRequest( |
| 180 const std::string& form_xml, | 178 const std::string& form_xml, |
| 181 const FormRequestData& request_data) { | 179 const FormRequestData& request_data) { |
| 182 net::URLRequestContextGetter* request_context = | 180 net::URLRequestContextGetter* request_context = |
| 183 browser_context_->GetRequestContext(); | 181 browser_context_->GetRequestContext(); |
| 184 DCHECK(request_context); | 182 DCHECK(request_context); |
| 185 GURL request_url; | 183 GURL request_url; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 SetPositiveUploadRate(new_positive_upload_rate); | 331 SetPositiveUploadRate(new_positive_upload_rate); |
| 334 SetNegativeUploadRate(new_negative_upload_rate); | 332 SetNegativeUploadRate(new_negative_upload_rate); |
| 335 } | 333 } |
| 336 | 334 |
| 337 observer_->OnUploadedPossibleFieldTypes(); | 335 observer_->OnUploadedPossibleFieldTypes(); |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 delete it->first; | 338 delete it->first; |
| 341 url_fetchers_.erase(it); | 339 url_fetchers_.erase(it); |
| 342 } | 340 } |
| OLD | NEW |