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

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

Issue 11230060: Adding commandline switch and user pref for autofill server url. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More fixes from code review Created 8 years, 2 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_download_url.h"
15 #include "chrome/browser/autofill/autofill_metrics.h" 16 #include "chrome/browser/autofill/autofill_metrics.h"
16 #include "chrome/browser/autofill/autofill_xml_parser.h" 17 #include "chrome/browser/autofill/autofill_xml_parser.h"
17 #include "chrome/browser/autofill/form_structure.h" 18 #include "chrome/browser/autofill/form_structure.h"
18 #include "chrome/browser/api/prefs/pref_service_base.h" 19 #include "chrome/browser/api/prefs/pref_service_base.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
21 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
22 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
23 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
24 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
25 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" 26 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h"
26 27
27 using content::BrowserContext; 28 using content::BrowserContext;
28 29
29 namespace { 30 namespace {
30 const char kAutofillQueryServerRequestUrl[] =
31 "https://clients1.google.com/tbproxy/af/query?client=";
32 const char kAutofillUploadServerRequestUrl[] =
33 "https://clients1.google.com/tbproxy/af/upload?client=";
34 const char kAutofillQueryServerNameStartInHeader[] = "GFE/"; 31 const char kAutofillQueryServerNameStartInHeader[] = "GFE/";
35 32
36 #if defined(GOOGLE_CHROME_BUILD)
37 const char kClientName[] = "Google Chrome";
38 #else
39 const char kClientName[] = "Chromium";
40 #endif // defined(GOOGLE_CHROME_BUILD)
41
42 const size_t kMaxFormCacheSize = 16; 33 const size_t kMaxFormCacheSize = 16;
43 }; 34 };
44 35
45 struct AutofillDownloadManager::FormRequestData { 36 struct AutofillDownloadManager::FormRequestData {
46 std::vector<std::string> form_signatures; 37 std::vector<std::string> form_signatures;
47 AutofillRequestType request_type; 38 AutofillRequestType request_type;
48 }; 39 };
49 40
50 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context, 41 AutofillDownloadManager::AutofillDownloadManager(BrowserContext* context,
51 Observer* observer) 42 Observer* observer)
52 : browser_context_(context), 43 : browser_context_(context),
53 observer_(observer), 44 observer_(observer),
54 max_form_cache_size_(kMaxFormCacheSize), 45 max_form_cache_size_(kMaxFormCacheSize),
55 next_query_request_(base::Time::Now()), 46 next_query_request_(base::Time::Now()),
56 next_upload_request_(base::Time::Now()), 47 next_upload_request_(base::Time::Now()),
57 positive_upload_rate_(0), 48 positive_upload_rate_(0),
58 negative_upload_rate_(0), 49 negative_upload_rate_(0),
59 fetcher_id_for_unittest_(0) { 50 fetcher_id_for_unittest_(0) {
60 DCHECK(observer_); 51 DCHECK(observer_);
61 PrefServiceBase* preferences = 52 PrefServiceBase* preferences =
62 PrefServiceBase::FromBrowserContext(browser_context_); 53 PrefServiceBase::FromBrowserContext(browser_context_);
54 autofill_download_url_.reset(new AutofillDownloadUrl(preferences));
Albert Bodenhamer 2012/10/24 19:51:56 I still think it would be a bit better to just all
ahutter 2012/10/24 21:29:45 Done.
63 positive_upload_rate_ = 55 positive_upload_rate_ =
64 preferences->GetDouble(prefs::kAutofillPositiveUploadRate); 56 preferences->GetDouble(prefs::kAutofillPositiveUploadRate);
65 negative_upload_rate_ = 57 negative_upload_rate_ =
66 preferences->GetDouble(prefs::kAutofillNegativeUploadRate); 58 preferences->GetDouble(prefs::kAutofillNegativeUploadRate);
67 } 59 }
68 60
69 AutofillDownloadManager::~AutofillDownloadManager() { 61 AutofillDownloadManager::~AutofillDownloadManager() {
70 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(), 62 STLDeleteContainerPairFirstPointers(url_fetchers_.begin(),
71 url_fetchers_.end()); 63 url_fetchers_.end());
72 } 64 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 browser_context_); 153 browser_context_);
162 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate); 154 preferences->SetDouble(prefs::kAutofillNegativeUploadRate, rate);
163 } 155 }
164 156
165 bool AutofillDownloadManager::StartRequest( 157 bool AutofillDownloadManager::StartRequest(
166 const std::string& form_xml, 158 const std::string& form_xml,
167 const FormRequestData& request_data) { 159 const FormRequestData& request_data) {
168 net::URLRequestContextGetter* request_context = 160 net::URLRequestContextGetter* request_context =
169 browser_context_->GetRequestContext(); 161 browser_context_->GetRequestContext();
170 DCHECK(request_context); 162 DCHECK(request_context);
171 std::string request_url; 163 GURL request_url;
172 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY) 164 if (request_data.request_type == AutofillDownloadManager::REQUEST_QUERY)
173 request_url = kAutofillQueryServerRequestUrl; 165 request_url = autofill_download_url_.get()->GetAutofillRequestUrl();
174 else 166 else
175 request_url = kAutofillUploadServerRequestUrl; 167 request_url = autofill_download_url_.get()->GetAutofillUploadUrl();
176 request_url += kClientName;
177 168
178 // Id is ignored for regular chrome, in unit test id's for fake fetcher 169 // Id is ignored for regular chrome, in unit test id's for fake fetcher
179 // factory will be 0, 1, 2, ... 170 // factory will be 0, 1, 2, ...
180 net::URLFetcher* fetcher = net::URLFetcher::Create( 171 net::URLFetcher* fetcher = net::URLFetcher::Create(
181 fetcher_id_for_unittest_++, GURL(request_url), net::URLFetcher::POST, 172 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST,
182 this); 173 this);
183 url_fetchers_[fetcher] = request_data; 174 url_fetchers_[fetcher] = request_data;
184 fetcher->SetAutomaticallyRetryOn5xx(false); 175 fetcher->SetAutomaticallyRetryOn5xx(false);
185 fetcher->SetRequestContext(request_context); 176 fetcher->SetRequestContext(request_context);
186 fetcher->SetUploadData("text/plain", form_xml); 177 fetcher->SetUploadData("text/plain", form_xml);
187 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 178 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
188 net::LOAD_DO_NOT_SEND_COOKIES); 179 net::LOAD_DO_NOT_SEND_COOKIES);
189 fetcher->Start(); 180 fetcher->Start();
190 return true; 181 return true;
191 } 182 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 SetPositiveUploadRate(new_positive_upload_rate); 306 SetPositiveUploadRate(new_positive_upload_rate);
316 SetNegativeUploadRate(new_negative_upload_rate); 307 SetNegativeUploadRate(new_negative_upload_rate);
317 } 308 }
318 309
319 observer_->OnUploadedPossibleFieldTypes(); 310 observer_->OnUploadedPossibleFieldTypes();
320 } 311 }
321 } 312 }
322 delete it->first; 313 delete it->first;
323 url_fetchers_.erase(it); 314 url_fetchers_.erase(it);
324 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698