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/prefs/pref_service.h" | 18 #include "chrome/browser/api/prefs/pref_service_base.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.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 namespace { | 27 namespace { |
28 const char kAutofillQueryServerRequestUrl[] = | 28 const char kAutofillQueryServerRequestUrl[] = |
(...skipping 20 matching lines...) Expand all Loading... |
49 Observer* observer) | 49 Observer* observer) |
50 : profile_(profile), | 50 : profile_(profile), |
51 observer_(observer), | 51 observer_(observer), |
52 max_form_cache_size_(kMaxFormCacheSize), | 52 max_form_cache_size_(kMaxFormCacheSize), |
53 next_query_request_(base::Time::Now()), | 53 next_query_request_(base::Time::Now()), |
54 next_upload_request_(base::Time::Now()), | 54 next_upload_request_(base::Time::Now()), |
55 positive_upload_rate_(0), | 55 positive_upload_rate_(0), |
56 negative_upload_rate_(0), | 56 negative_upload_rate_(0), |
57 fetcher_id_for_unittest_(0) { | 57 fetcher_id_for_unittest_(0) { |
58 DCHECK(observer_); | 58 DCHECK(observer_); |
59 PrefService* preferences = profile_->GetPrefs(); | 59 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); |
60 positive_upload_rate_ = | 60 positive_upload_rate_ = |
61 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); | 61 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); |
62 negative_upload_rate_ = | 62 negative_upload_rate_ = |
63 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); | 63 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); |
64 } | 64 } |
65 | 65 |
66 AutofillDownloadManager::~AutofillDownloadManager() { | 66 AutofillDownloadManager::~AutofillDownloadManager() { |
67 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), | 67 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), |
68 url_fetchers_.end()); | 68 url_fetchers_.end()); |
69 } | 69 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 double AutofillDownloadManager::GetNegativeUploadRate() const { | 136 double AutofillDownloadManager::GetNegativeUploadRate() const { |
137 return negative_upload_rate_; | 137 return negative_upload_rate_; |
138 } | 138 } |
139 | 139 |
140 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { | 140 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { |
141 if (rate == positive_upload_rate_) | 141 if (rate == positive_upload_rate_) |
142 return; | 142 return; |
143 positive_upload_rate_ = rate; | 143 positive_upload_rate_ = rate; |
144 DCHECK_GE(rate, 0.0); | 144 DCHECK_GE(rate, 0.0); |
145 DCHECK_LE(rate, 1.0); | 145 DCHECK_LE(rate, 1.0); |
146 PrefService* preferences = profile_->GetPrefs(); | 146 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); |
147 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); | 147 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); |
148 } | 148 } |
149 | 149 |
150 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { | 150 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { |
151 if (rate == negative_upload_rate_) | 151 if (rate == negative_upload_rate_) |
152 return; | 152 return; |
153 negative_upload_rate_ = rate; | 153 negative_upload_rate_ = rate; |
154 DCHECK_GE(rate, 0.0); | 154 DCHECK_GE(rate, 0.0); |
155 DCHECK_LE(rate, 1.0); | 155 DCHECK_LE(rate, 1.0); |
156 PrefService* preferences = profile_->GetPrefs(); | 156 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); |
157 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); | 157 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); |
158 } | 158 } |
159 | 159 |
160 bool AutofillDownloadManager::StartRequest( | 160 bool AutofillDownloadManager::StartRequest( |
161 const std::string& form_xml, | 161 const std::string& form_xml, |
162 const FormRequestData& request_data) { | 162 const FormRequestData& request_data) { |
163 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 163 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
164 DCHECK(request_context); | 164 DCHECK(request_context); |
165 std::string request_url; | 165 std::string request_url; |
166 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) | 166 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 SetPositiveUploadRate(new_positive_upload_rate); | 309 SetPositiveUploadRate(new_positive_upload_rate); |
310 SetNegativeUploadRate(new_negative_upload_rate); | 310 SetNegativeUploadRate(new_negative_upload_rate); |
311 } | 311 } |
312 | 312 |
313 observer_->OnUploadedPossibleFieldTypes(); | 313 observer_->OnUploadedPossibleFieldTypes(); |
314 } | 314 } |
315 } | 315 } |
316 delete it->first; | 316 delete it->first; |
317 url_fetchers_.erase(it); | 317 url_fetchers_.erase(it); |
318 } | 318 } |
OLD | NEW |