OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_download.h" | 5 #include "components/autofill/core/browser/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/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "components/autofill/core/browser/autofill_download_url.h" | 16 #include "components/autofill/core/browser/autofill_download_url.h" |
17 #include "components/autofill/core/browser/autofill_metrics.h" | 17 #include "components/autofill/core/browser/autofill_metrics.h" |
18 #include "components/autofill/core/browser/autofill_xml_parser.h" | 18 #include "components/autofill/core/browser/autofill_xml_parser.h" |
19 #include "components/autofill/core/browser/form_structure.h" | 19 #include "components/autofill/core/browser/form_structure.h" |
20 #include "components/autofill/core/common/autofill_pref_names.h" | 20 #include "components/autofill/core/common/autofill_pref_names.h" |
21 #include "components/user_prefs/user_prefs.h" | |
22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
23 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
24 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
25 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
26 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" | 25 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" |
27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
28 | 27 |
29 using content::BrowserContext; | 28 using content::BrowserContext; |
30 | 29 |
31 namespace autofill { | 30 namespace autofill { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 62 } |
64 return std::string(); | 63 return std::string(); |
65 } | 64 } |
66 | 65 |
67 struct AutofillDownloadManager::FormRequestData { | 66 struct AutofillDownloadManager::FormRequestData { |
68 std::vector<std::string> form_signatures; | 67 std::vector<std::string> form_signatures; |
69 AutofillRequestType request_type; | 68 AutofillRequestType request_type; |
70 }; | 69 }; |
71 | 70 |
72 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context, | 71 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context, |
| 72 PrefService* pref_service, |
73 Observer* observer) | 73 Observer* observer) |
74 : browser_context_(context), | 74 : browser_context_(context), |
| 75 pref_service_(pref_service), |
75 observer_(observer), | 76 observer_(observer), |
76 max_form_cache_size_(kMaxFormCacheSize), | 77 max_form_cache_size_(kMaxFormCacheSize), |
77 next_query_request_(base::Time::Now()), | 78 next_query_request_(base::Time::Now()), |
78 next_upload_request_(base::Time::Now()), | 79 next_upload_request_(base::Time::Now()), |
79 positive_upload_rate_(0), | 80 positive_upload_rate_(0), |
80 negative_upload_rate_(0), | 81 negative_upload_rate_(0), |
81 fetcher_id_for_unittest_(0) { | 82 fetcher_id_for_unittest_(0) { |
82 DCHECK(observer_); | 83 DCHECK(observer_); |
83 PrefService* preferences = user_prefs::UserPrefs::Get(browser_context_); | |
84 positive_upload_rate_ = | 84 positive_upload_rate_ = |
85 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); | 85 pref_service_->GetDouble(prefs::kAutofillPositiveUploadRate); |
86 negative_upload_rate_ = | 86 negative_upload_rate_ = |
87 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); | 87 pref_service_->GetDouble(prefs::kAutofillNegativeUploadRate); |
88 } | 88 } |
89 | 89 |
90 AutofillDownloadManager::~AutofillDownloadManager() { | 90 AutofillDownloadManager::~AutofillDownloadManager() { |
91 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), | 91 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), |
92 url_fetchers_.end()); | 92 url_fetchers_.end()); |
93 } | 93 } |
94 | 94 |
95 bool AutofillDownloadManager::StartQueryRequest( | 95 bool AutofillDownloadManager::StartQueryRequest( |
96 const std::vector<FormStructure*>& forms, | 96 const std::vector<FormStructure*>& forms, |
97 const AutofillMetrics& metric_logger) { | 97 const AutofillMetrics& metric_logger) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 double AutofillDownloadManager::GetNegativeUploadRate() const { | 163 double AutofillDownloadManager::GetNegativeUploadRate() const { |
164 return negative_upload_rate_; | 164 return negative_upload_rate_; |
165 } | 165 } |
166 | 166 |
167 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { | 167 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { |
168 if (rate == positive_upload_rate_) | 168 if (rate == positive_upload_rate_) |
169 return; | 169 return; |
170 positive_upload_rate_ = rate; | 170 positive_upload_rate_ = rate; |
171 DCHECK_GE(rate, 0.0); | 171 DCHECK_GE(rate, 0.0); |
172 DCHECK_LE(rate, 1.0); | 172 DCHECK_LE(rate, 1.0); |
173 PrefService* preferences = user_prefs::UserPrefs::Get(browser_context_); | 173 pref_service_->SetDouble(prefs::kAutofillPositiveUploadRate, rate); |
174 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); | |
175 } | 174 } |
176 | 175 |
177 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { | 176 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { |
178 if (rate == negative_upload_rate_) | 177 if (rate == negative_upload_rate_) |
179 return; | 178 return; |
180 negative_upload_rate_ = rate; | 179 negative_upload_rate_ = rate; |
181 DCHECK_GE(rate, 0.0); | 180 DCHECK_GE(rate, 0.0); |
182 DCHECK_LE(rate, 1.0); | 181 DCHECK_LE(rate, 1.0); |
183 PrefService* preferences = user_prefs::UserPrefs::Get(browser_context_); | 182 pref_service_->SetDouble(prefs::kAutofillNegativeUploadRate, rate); |
184 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); | |
185 } | 183 } |
186 | 184 |
187 bool AutofillDownloadManager::StartRequest( | 185 bool AutofillDownloadManager::StartRequest( |
188 const std::string& form_xml, | 186 const std::string& form_xml, |
189 const FormRequestData& request_data) { | 187 const FormRequestData& request_data) { |
190 net::URLRequestContextGetter* request_context = | 188 net::URLRequestContextGetter* request_context = |
191 browser_context_->GetRequestContext(); | 189 browser_context_->GetRequestContext(); |
192 DCHECK(request_context); | 190 DCHECK(request_context); |
193 GURL request_url; | 191 GURL request_url; |
194 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) | 192 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 341 } |
344 | 342 |
345 observer_->OnUploadedPossibleFieldTypes(); | 343 observer_->OnUploadedPossibleFieldTypes(); |
346 } | 344 } |
347 } | 345 } |
348 delete it->first; | 346 delete it->first; |
349 url_fetchers_.erase(it); | 347 url_fetchers_.erase(it); |
350 } | 348 } |
351 | 349 |
352 } // namespace autofill | 350 } // namespace autofill |
OLD | NEW |