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

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

Issue 10919066: Use BrowserContext as key in API. Switch Autofill to use BC in place of Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to parent Created 8 years, 3 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/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/api/prefs/pref_service_base.h" 18 #include "chrome/browser/api/prefs/pref_service_base.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "content/public/browser/browser_context.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 using content::BrowserContext;
28
27 namespace { 29 namespace {
28 const char kAutofillQueryServerRequestUrl[] = 30 const char kAutofillQueryServerRequestUrl[] =
29 "https://clients1.google.com/tbproxy/af/query?client="; 31 "https://clients1.google.com/tbproxy/af/query?client=";
30 const char kAutofillUploadServerRequestUrl[] = 32 const char kAutofillUploadServerRequestUrl[] =
31 "https://clients1.google.com/tbproxy/af/upload?client="; 33 "https://clients1.google.com/tbproxy/af/upload?client=";
32 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; 34 const char kAutofillQueryServerNameStartInHeader[] = "GFE/";
33 35
34 #if defined(GOOGLE_CHROME_BUILD) 36 #if defined(GOOGLE_CHROME_BUILD)
35 const char kClientName[] = "Google Chrome"; 37 const char kClientName[] = "Google Chrome";
36 #else 38 #else
37 const char kClientName[] = "Chromium"; 39 const char kClientName[] = "Chromium";
38 #endif // defined(GOOGLE_CHROME_BUILD) 40 #endif // defined(GOOGLE_CHROME_BUILD)
39 41
40 const size_t kMaxFormCacheSize = 16; 42 const size_t kMaxFormCacheSize = 16;
41 }; 43 };
42 44
43 struct AutofillDownloadManager::FormRequestData { 45 struct AutofillDownloadManager::FormRequestData {
44 std::vector<std::string> form_signatures; 46 std::vector<std::string> form_signatures;
45 AutofillRequestType request_type; 47 AutofillRequestType request_type;
46 }; 48 };
47 49
48 AutofillDownloadManager::AutofillDownloadManager(Profile* profile, 50 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context,
49 Observer* observer) 51 Observer* observer)
50 : profile_(profile), 52 : browser_context_(context),
51 observer_(observer), 53 observer_(observer),
52 max_form_cache_size_(kMaxFormCacheSize), 54 max_form_cache_size_(kMaxFormCacheSize),
53 next_query_request_(base::Time::Now()), 55 next_query_request_(base::Time::Now()),
54 next_upload_request_(base::Time::Now()), 56 next_upload_request_(base::Time::Now()),
55 positive_upload_rate_(0), 57 positive_upload_rate_(0),
56 negative_upload_rate_(0), 58 negative_upload_rate_(0),
57 fetcher_id_for_unittest_(0) { 59 fetcher_id_for_unittest_(0) {
58 DCHECK(observer_); 60 DCHECK(observer_);
59 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); 61 PrefServiceBase* preferences = PrefServiceBase::ForContext(browser_context_);
60 positive_upload_rate_ = 62 positive_upload_rate_ =
61 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); 63 preferences->GetDouble(prefs::kAutofillPositiveUploadRate);
62 negative_upload_rate_ = 64 negative_upload_rate_ =
63 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); 65 preferences->GetDouble(prefs::kAutofillNegativeUploadRate);
64 } 66 }
65 67
66 AutofillDownloadManager::~AutofillDownloadManager() { 68 AutofillDownloadManager::~AutofillDownloadManager() {
67 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), 69 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(),
68 url_fetchers_.end()); 70 url_fetchers_.end());
69 } 71 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 double AutofillDownloadManager::GetNegativeUploadRate() const { 138 double AutofillDownloadManager::GetNegativeUploadRate() const {
137 return negative_upload_rate_; 139 return negative_upload_rate_;
138 } 140 }
139 141
140 void AutofillDownloadManager::SetPositiveUploadRate(double rate) { 142 void AutofillDownloadManager::SetPositiveUploadRate(double rate) {
141 if (rate == positive_upload_rate_) 143 if (rate == positive_upload_rate_)
142 return; 144 return;
143 positive_upload_rate_ = rate; 145 positive_upload_rate_ = rate;
144 DCHECK_GE(rate, 0.0); 146 DCHECK_GE(rate, 0.0);
145 DCHECK_LE(rate, 1.0); 147 DCHECK_LE(rate, 1.0);
146 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); 148 PrefServiceBase* preferences = PrefServiceBase::ForContext(browser_context_);
147 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate); 149 preferences->SetDouble(prefs::kAutofillPositiveUploadRate, rate);
148 } 150 }
149 151
150 void AutofillDownloadManager::SetNegativeUploadRate(double rate) { 152 void AutofillDownloadManager::SetNegativeUploadRate(double rate) {
151 if (rate == negative_upload_rate_) 153 if (rate == negative_upload_rate_)
152 return; 154 return;
153 negative_upload_rate_ = rate; 155 negative_upload_rate_ = rate;
154 DCHECK_GE(rate, 0.0); 156 DCHECK_GE(rate, 0.0);
155 DCHECK_LE(rate, 1.0); 157 DCHECK_LE(rate, 1.0);
156 PrefServiceBase* preferences = PrefServiceBase::ForProfile(profile_); 158 PrefServiceBase* preferences = PrefServiceBase::ForContext(browser_context_);
157 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); 159 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate);
158 } 160 }
159 161
160 bool AutofillDownloadManager::StartRequest( 162 bool AutofillDownloadManager::StartRequest(
161 const std::string& form_xml, 163 const std::string& form_xml,
162 const FormRequestData& request_data) { 164 const FormRequestData& request_data) {
163 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 165 net::URLRequestContextGetter* request_context =
166 browser_context_->GetRequestContext();
164 DCHECK(request_context); 167 DCHECK(request_context);
165 std::string request_url; 168 std::string request_url;
166 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) 169 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY)
167 request_url = kAutofillQueryServerRequestUrl; 170 request_url = kAutofillQueryServerRequestUrl;
168 else 171 else
169 request_url = kAutofillUploadServerRequestUrl; 172 request_url = kAutofillUploadServerRequestUrl;
170 request_url += kClientName; 173 request_url += kClientName;
171 174
172 // Id is ignored for regular chrome, in unit test id's for fake fetcher 175 // Id is ignored for regular chrome, in unit test id's for fake fetcher
173 // factory will be 0, 1, 2, ... 176 // factory will be 0, 1, 2, ...
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 SetPositiveUploadRate(new_positive_upload_rate); 312 SetPositiveUploadRate(new_positive_upload_rate);
310 SetNegativeUploadRate(new_negative_upload_rate); 313 SetNegativeUploadRate(new_negative_upload_rate);
311 } 314 }
312 315
313 observer_->OnUploadedPossibleFieldTypes(); 316 observer_->OnUploadedPossibleFieldTypes();
314 } 317 }
315 } 318 }
316 delete it->first; 319 delete it->first;
317 url_fetchers_.erase(it); 320 url_fetchers_.erase(it);
318 } 321 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_download.h ('k') | chrome/browser/autofill/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698