| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/safe_browsing_db/v4_update_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_update_protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 DCHECK(CalledOnValidThread()); | 271 DCHECK(CalledOnValidThread()); |
| 272 | 272 |
| 273 // If an update request is already pending, record and return silently. | 273 // If an update request is already pending, record and return silently. |
| 274 if (request_.get()) { | 274 if (request_.get()) { |
| 275 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR); | 275 RecordUpdateResult(V4OperationResult::ALREADY_PENDING_ERROR); |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 std::string req_base64 = | 279 std::string req_base64 = |
| 280 GetBase64SerializedUpdateRequestProto(current_list_states_); | 280 GetBase64SerializedUpdateRequestProto(current_list_states_); |
| 281 GURL update_url = GetUpdateUrl(req_base64); | 281 GURL update_url; |
| 282 net::HttpRequestHeaders headers; |
| 283 GetUpdateUrlAndHeaders(req_base64, &update_url, &headers); |
| 282 | 284 |
| 283 request_.reset(net::URLFetcher::Create(url_fetcher_id_++, update_url, | 285 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( |
| 284 net::URLFetcher::GET, this) | 286 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); |
| 285 .release()); | 287 fetcher->SetExtraRequestHeaders(headers.ToString()); |
| 288 |
| 289 request_.reset(fetcher.release()); |
| 286 | 290 |
| 287 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 291 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 288 request_->SetRequestContext(request_context_getter_.get()); | 292 request_->SetRequestContext(request_context_getter_.get()); |
| 289 request_->Start(); | 293 request_->Start(); |
| 290 // TODO(vakh): Handle request timeout. | 294 // TODO(vakh): Handle request timeout. |
| 291 } | 295 } |
| 292 | 296 |
| 293 // net::URLFetcherDelegate implementation ---------------------------------- | 297 // net::URLFetcherDelegate implementation ---------------------------------- |
| 294 | 298 |
| 295 // SafeBrowsing request responses are handled here. | 299 // SafeBrowsing request responses are handled here. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 RecordUpdateResult(V4OperationResult::HTTP_ERROR); | 336 RecordUpdateResult(V4OperationResult::HTTP_ERROR); |
| 333 } | 337 } |
| 334 // TODO(vakh): Figure out whether it is just a network error vs backoff vs | 338 // TODO(vakh): Figure out whether it is just a network error vs backoff vs |
| 335 // another condition and RecordUpdateResult more accurately. | 339 // another condition and RecordUpdateResult more accurately. |
| 336 | 340 |
| 337 request_.reset(); | 341 request_.reset(); |
| 338 ScheduleNextUpdateWithBackoff(true); | 342 ScheduleNextUpdateWithBackoff(true); |
| 339 } | 343 } |
| 340 } | 344 } |
| 341 | 345 |
| 342 GURL V4UpdateProtocolManager::GetUpdateUrl( | 346 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( |
| 343 const std::string& req_base64) const { | 347 const std::string& req_base64, |
| 344 GURL url = V4ProtocolManagerUtil::GetRequestUrl(req_base64, "encodedUpdates", | 348 GURL* gurl, |
| 345 config_); | 349 net::HttpRequestHeaders* headers) const { |
| 346 DVLOG(1) << "V4UpdateProtocolManager::GetUpdateUrl: " | 350 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( |
| 347 << "url: " << url; | 351 req_base64, "threatListUpdates:fetch", config_, gurl, headers); |
| 348 return url; | |
| 349 } | 352 } |
| 350 | 353 |
| 351 } // namespace safe_browsing | 354 } // namespace safe_browsing |
| OLD | NEW |