Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: chrome/browser/autofill/autofill_download.cc

Issue 12340111: Introduce //components/user_prefs, use to eliminate c/b/prefs dependency in Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
51 Observer* observer) 52 Observer* observer)
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 = components::UserPrefs::Get(browser_context_);
62 PrefServiceFromBrowserContext(browser_context_);
63 positive_upload_rate_ = 63 positive_upload_rate_ =
64 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); 64 preferences->GetDouble(prefs::kAutofillPositiveUploadRate);
65 negative_upload_rate_ = 65 negative_upload_rate_ =
66 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); 66 preferences->GetDouble(prefs::kAutofillNegativeUploadRate);
67 } 67 }
68 68
69 AutofillDownloadManager::~AutofillDownloadManager() { 69 AutofillDownloadManager::~AutofillDownloadManager() {
70 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), 70 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(),
71 url_fetchers_.end()); 71 url_fetchers_.end());
72 } 72 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 double AutofillDownloadManager::GetNegativeUploadRate() const { 141 double AutofillDownloadManager::GetNegativeUploadRate() const {
142 return negative_upload_rate_; 142 return negative_upload_rate_;
143 } 143 }
144 144
145 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { 145 void AutofillDownloadManager::SetPositiveUploadRate(double rate) {
146 if (rate == positive_upload_rate_) 146 if (rate == positive_upload_rate_)
147 return; 147 return;
148 positive_upload_rate_ = rate; 148 positive_upload_rate_ = rate;
149 DCHECK_GE(rate, 0.0); 149 DCHECK_GE(rate, 0.0);
150 DCHECK_LE(rate, 1.0); 150 DCHECK_LE(rate, 1.0);
151 PrefService* preferences = PrefServiceFromBrowserContext( 151 PrefService* preferences = components::UserPrefs::Get(browser_context_);
152 browser_context_);
153 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); 152 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate);
154 } 153 }
155 154
156 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { 155 void AutofillDownloadManager::SetNegativeUploadRate(double rate) {
157 if (rate == negative_upload_rate_) 156 if (rate == negative_upload_rate_)
158 return; 157 return;
159 negative_upload_rate_ = rate; 158 negative_upload_rate_ = rate;
160 DCHECK_GE(rate, 0.0); 159 DCHECK_GE(rate, 0.0);
161 DCHECK_LE(rate, 1.0); 160 DCHECK_LE(rate, 1.0);
162 PrefService* preferences = PrefServiceFromBrowserContext( 161 PrefService* preferences = components::UserPrefs::Get(browser_context_);
163 browser_context_);
164 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); 162 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate);
165 } 163 }
166 164
167 bool AutofillDownloadManager::StartRequest( 165 bool AutofillDownloadManager::StartRequest(
168 const std::string& form_xml, 166 const std::string& form_xml,
169 const FormRequestData& request_data) { 167 const FormRequestData& request_data) {
170 net::URLRequestContextGetter* request_context = 168 net::URLRequestContextGetter* request_context =
171 browser_context_->GetRequestContext(); 169 browser_context_->GetRequestContext();
172 DCHECK(request_context); 170 DCHECK(request_context);
173 GURL request_url; 171 GURL request_url;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 SetPositiveUploadRate(new_positive_upload_rate); 314 SetPositiveUploadRate(new_positive_upload_rate);
317 SetNegativeUploadRate(new_negative_upload_rate); 315 SetNegativeUploadRate(new_negative_upload_rate);
318 } 316 }
319 317
320 observer_->OnUploadedPossibleFieldTypes(); 318 observer_->OnUploadedPossibleFieldTypes();
321 } 319 }
322 } 320 }
323 delete it->first; 321 delete it->first;
324 url_fetchers_.erase(it); 322 url_fetchers_.erase(it);
325 } 323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698