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

Side by Side Diff: components/autofill/core/browser/autofill_download_manager.cc

Issue 2288173002: Remove STLDeleteContainerPairFirstPointers from AutofillDownloadManager (Closed)
Patch Set: Created 4 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
« no previous file with comments | « components/autofill/core/browser/autofill_download_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_manager.h" 5 #include "components/autofill/core/browser/autofill_download_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/stl_util.h"
15 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
16 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
17 #include "components/autofill/core/browser/autofill_driver.h" 16 #include "components/autofill/core/browser/autofill_driver.h"
18 #include "components/autofill/core/browser/autofill_metrics.h" 17 #include "components/autofill/core/browser/autofill_metrics.h"
19 #include "components/autofill/core/browser/form_structure.h" 18 #include "components/autofill/core/browser/form_structure.h"
20 #include "components/autofill/core/browser/proto/server.pb.h" 19 #include "components/autofill/core/browser/proto/server.pb.h"
21 #include "components/autofill/core/common/autofill_pref_names.h" 20 #include "components/autofill/core/common/autofill_pref_names.h"
22 #include "components/data_use_measurement/core/data_use_user_data.h" 21 #include "components/data_use_measurement/core/data_use_user_data.h"
23 #include "components/variations/net/variations_http_headers.h" 22 #include "components/variations/net/variations_http_headers.h"
24 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Observer* observer) 146 Observer* observer)
148 : driver_(driver), 147 : driver_(driver),
149 observer_(observer), 148 observer_(observer),
150 max_form_cache_size_(kMaxFormCacheSize), 149 max_form_cache_size_(kMaxFormCacheSize),
151 fetcher_backoff_(&kAutofillBackoffPolicy), 150 fetcher_backoff_(&kAutofillBackoffPolicy),
152 fetcher_id_for_unittest_(0), 151 fetcher_id_for_unittest_(0),
153 weak_factory_(this) { 152 weak_factory_(this) {
154 DCHECK(observer_); 153 DCHECK(observer_);
155 } 154 }
156 155
157 AutofillDownloadManager::~AutofillDownloadManager() { 156 AutofillDownloadManager::~AutofillDownloadManager() = default;
158 base::STLDeleteContainerPairFirstPointers(url_fetchers_.begin(),
159 url_fetchers_.end());
160 }
161 157
162 bool AutofillDownloadManager::StartQueryRequest( 158 bool AutofillDownloadManager::StartQueryRequest(
163 const std::vector<FormStructure*>& forms) { 159 const std::vector<FormStructure*>& forms) {
164 // Do not send the request if it contains more fields than the server can 160 // Do not send the request if it contains more fields than the server can
165 // accept. 161 // accept.
166 if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest) 162 if (CountActiveFieldsInForms(forms) > kMaxFieldsPerQueryRequest)
167 return false; 163 return false;
168 164
169 AutofillQueryContents query; 165 AutofillQueryContents query;
170 FormRequestData request_data; 166 FormRequestData request_data;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 226
231 bool AutofillDownloadManager::StartRequest( 227 bool AutofillDownloadManager::StartRequest(
232 const FormRequestData& request_data) { 228 const FormRequestData& request_data) {
233 net::URLRequestContextGetter* request_context = 229 net::URLRequestContextGetter* request_context =
234 driver_->GetURLRequestContext(); 230 driver_->GetURLRequestContext();
235 DCHECK(request_context); 231 DCHECK(request_context);
236 GURL request_url = GetRequestUrl(request_data.request_type); 232 GURL request_url = GetRequestUrl(request_data.request_type);
237 233
238 // Id is ignored for regular chrome, in unit test id's for fake fetcher 234 // Id is ignored for regular chrome, in unit test id's for fake fetcher
239 // factory will be 0, 1, 2, ... 235 // factory will be 0, 1, 2, ...
240 net::URLFetcher* fetcher = 236 std::unique_ptr<net::URLFetcher> owned_fetcher = net::URLFetcher::Create(
241 net::URLFetcher::Create(fetcher_id_for_unittest_++, request_url, 237 fetcher_id_for_unittest_++, request_url, net::URLFetcher::POST, this);
242 net::URLFetcher::POST, this).release(); 238 net::URLFetcher* fetcher = owned_fetcher.get();
243 data_use_measurement::DataUseUserData::AttachToFetcher( 239 data_use_measurement::DataUseUserData::AttachToFetcher(
244 fetcher, data_use_measurement::DataUseUserData::AUTOFILL); 240 fetcher, data_use_measurement::DataUseUserData::AUTOFILL);
245 url_fetchers_[fetcher] = request_data; 241 url_fetchers_[fetcher] =
242 std::make_pair(std::move(owned_fetcher), request_data);
246 fetcher->SetAutomaticallyRetryOn5xx(false); 243 fetcher->SetAutomaticallyRetryOn5xx(false);
247 fetcher->SetRequestContext(request_context); 244 fetcher->SetRequestContext(request_context);
248 fetcher->SetUploadData("text/proto", request_data.payload); 245 fetcher->SetUploadData("text/proto", request_data.payload);
249 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 246 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
250 net::LOAD_DO_NOT_SEND_COOKIES); 247 net::LOAD_DO_NOT_SEND_COOKIES);
251 // Add Chrome experiment state to the request headers. 248 // Add Chrome experiment state to the request headers.
252 net::HttpRequestHeaders headers; 249 net::HttpRequestHeaders headers;
253 variations::AppendVariationHeaders( 250 variations::AppendVariationHeaders(
254 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers); 251 fetcher->GetOriginalURL(), driver_->IsOffTheRecord(), false, &headers);
255 fetcher->SetExtraRequestHeaders(headers.ToString()); 252 fetcher->SetExtraRequestHeaders(headers.ToString());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 for (size_t i = 0; i < forms_in_query.size(); ++i) { 302 for (size_t i = 0; i < forms_in_query.size(); ++i) {
306 if (i) 303 if (i)
307 signature.append(","); 304 signature.append(",");
308 signature.append(forms_in_query[i]); 305 signature.append(forms_in_query[i]);
309 } 306 }
310 return signature; 307 return signature;
311 } 308 }
312 309
313 void AutofillDownloadManager::OnURLFetchComplete( 310 void AutofillDownloadManager::OnURLFetchComplete(
314 const net::URLFetcher* source) { 311 const net::URLFetcher* source) {
315 std::map<net::URLFetcher *, FormRequestData>::iterator it = 312 auto it = url_fetchers_.find(const_cast<net::URLFetcher*>(source));
316 url_fetchers_.find(const_cast<net::URLFetcher*>(source));
317 if (it == url_fetchers_.end()) { 313 if (it == url_fetchers_.end()) {
318 // Looks like crash on Mac is possibly caused with callback entering here 314 // Looks like crash on Mac is possibly caused with callback entering here
319 // with unknown fetcher when network is refreshed. 315 // with unknown fetcher when network is refreshed.
320 return; 316 return;
321 } 317 }
322 std::string request_type(RequestTypeToString(it->second.request_type)); 318 std::string request_type(RequestTypeToString(it->second.second.request_type));
323 319
324 CHECK(it->second.form_signatures.size()); 320 CHECK(it->second.second.form_signatures.size());
325 bool success = source->GetResponseCode() == net::HTTP_OK; 321 bool success = source->GetResponseCode() == net::HTTP_OK;
326 fetcher_backoff_.InformOfRequest(success); 322 fetcher_backoff_.InformOfRequest(success);
327 323
328 if (!success) { 324 if (!success) {
329 // Reschedule with the appropriate delay, ignoring return value because 325 // Reschedule with the appropriate delay, ignoring return value because
330 // payload is already well formed. 326 // payload is already well formed.
331 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 327 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
332 FROM_HERE, 328 FROM_HERE,
333 base::Bind(base::IgnoreResult(&AutofillDownloadManager::StartRequest), 329 base::Bind(base::IgnoreResult(&AutofillDownloadManager::StartRequest),
334 weak_factory_.GetWeakPtr(), it->second), 330 weak_factory_.GetWeakPtr(), it->second.second),
335 fetcher_backoff_.GetTimeUntilRelease()); 331 fetcher_backoff_.GetTimeUntilRelease());
336 332
337 VLOG(1) << "AutofillDownloadManager: " << request_type 333 VLOG(1) << "AutofillDownloadManager: " << request_type
338 << " request has failed with response " 334 << " request has failed with response "
339 << source->GetResponseCode(); 335 << source->GetResponseCode();
340 observer_->OnServerRequestError(it->second.form_signatures[0], 336 observer_->OnServerRequestError(it->second.second.form_signatures[0],
341 it->second.request_type, 337 it->second.second.request_type,
342 source->GetResponseCode()); 338 source->GetResponseCode());
343 } else { 339 } else {
344 std::string response_body; 340 std::string response_body;
345 source->GetResponseAsString(&response_body); 341 source->GetResponseAsString(&response_body);
346 if (it->second.request_type == AutofillDownloadManager::REQUEST_QUERY) { 342 if (it->second.second.request_type ==
347 CacheQueryRequest(it->second.form_signatures, response_body); 343 AutofillDownloadManager::REQUEST_QUERY) {
344 CacheQueryRequest(it->second.second.form_signatures, response_body);
348 observer_->OnLoadedServerPredictions(std::move(response_body), 345 observer_->OnLoadedServerPredictions(std::move(response_body),
349 it->second.form_signatures); 346 it->second.second.form_signatures);
350 } else { 347 } else {
351 VLOG(1) << "AutofillDownloadManager: upload request has succeeded."; 348 VLOG(1) << "AutofillDownloadManager: upload request has succeeded.";
352 observer_->OnUploadedPossibleFieldTypes(); 349 observer_->OnUploadedPossibleFieldTypes();
353 } 350 }
354 } 351 }
355 delete it->first;
356 url_fetchers_.erase(it); 352 url_fetchers_.erase(it);
357 } 353 }
358 354
359 } // namespace autofill 355 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_download_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698