| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 void V4UpdateProtocolManager::IssueUpdateRequest() { | 270 void V4UpdateProtocolManager::IssueUpdateRequest() { |
| 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 net::HttpRequestHeaders headers; |
| 279 std::string req_base64 = | 280 std::string req_base64 = |
| 280 GetBase64SerializedUpdateRequestProto(current_list_states_); | 281 GetBase64SerializedUpdateRequestProto(current_list_states_); |
| 281 GURL update_url = GetUpdateUrl(req_base64); | 282 GURL update_url = GetUpdateUrlAndUpdateHeaders(req_base64, &headers); |
| 282 | 283 |
| 283 request_.reset(net::URLFetcher::Create(url_fetcher_id_++, update_url, | 284 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( |
| 284 net::URLFetcher::GET, this) | 285 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); |
| 285 .release()); | 286 fetcher->SetExtraRequestHeaders(headers.ToString()); |
| 287 |
| 288 request_.reset(fetcher.release()); |
| 286 | 289 |
| 287 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 290 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 288 request_->SetRequestContext(request_context_getter_.get()); | 291 request_->SetRequestContext(request_context_getter_.get()); |
| 289 request_->Start(); | 292 request_->Start(); |
| 290 // TODO(vakh): Handle request timeout. | 293 // TODO(vakh): Handle request timeout. |
| 291 } | 294 } |
| 292 | 295 |
| 293 // net::URLFetcherDelegate implementation ---------------------------------- | 296 // net::URLFetcherDelegate implementation ---------------------------------- |
| 294 | 297 |
| 295 // SafeBrowsing request responses are handled here. | 298 // SafeBrowsing request responses are handled here. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 RecordUpdateResult(V4OperationResult::HTTP_ERROR); | 335 RecordUpdateResult(V4OperationResult::HTTP_ERROR); |
| 333 } | 336 } |
| 334 // TODO(vakh): Figure out whether it is just a network error vs backoff vs | 337 // TODO(vakh): Figure out whether it is just a network error vs backoff vs |
| 335 // another condition and RecordUpdateResult more accurately. | 338 // another condition and RecordUpdateResult more accurately. |
| 336 | 339 |
| 337 request_.reset(); | 340 request_.reset(); |
| 338 ScheduleNextUpdateWithBackoff(true); | 341 ScheduleNextUpdateWithBackoff(true); |
| 339 } | 342 } |
| 340 } | 343 } |
| 341 | 344 |
| 342 GURL V4UpdateProtocolManager::GetUpdateUrl( | 345 GURL V4UpdateProtocolManager::GetUpdateUrlAndUpdateHeaders( |
| 343 const std::string& req_base64) const { | 346 const std::string& req_base64, |
| 344 GURL url = V4ProtocolManagerUtil::GetRequestUrl(req_base64, "encodedUpdates", | 347 net::HttpRequestHeaders* headers) const { |
| 345 config_); | 348 GURL url = V4ProtocolManagerUtil::GetRequestUrlAndUpdateHeaders( |
| 349 req_base64, "threatListUpdates:fetch", config_, headers); |
| 346 DVLOG(1) << "V4UpdateProtocolManager::GetUpdateUrl: " | 350 DVLOG(1) << "V4UpdateProtocolManager::GetUpdateUrl: " |
| 347 << "url: " << url; | 351 << "url: " << url; |
| 348 return url; | 352 return url; |
| 349 } | 353 } |
| 350 | 354 |
| 351 } // namespace safe_browsing | 355 } // namespace safe_browsing |
| OLD | NEW |