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

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 1870003002: Convert //chrome/browser/safe_browsing from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments Created 4 years, 8 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
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/safe_browsing/protocol_manager.h" 5 #include "chrome/browser/safe_browsing/protocol_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a 245 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a
246 // chunk should retry the download and parse of that chunk (and 246 // chunk should retry the download and parse of that chunk (and
247 // what back off / how many times to try), and if that effects the 247 // what back off / how many times to try), and if that effects the
248 // update back off. For now, a failed parse of the chunk means we 248 // update back off. For now, a failed parse of the chunk means we
249 // drop it. This isn't so bad because the next UPDATE_REQUEST we 249 // drop it. This isn't so bad because the next UPDATE_REQUEST we
250 // do will report all the chunks we have. If that chunk is still 250 // do will report all the chunks we have. If that chunk is still
251 // required, the SafeBrowsing servers will tell us to get it again. 251 // required, the SafeBrowsing servers will tell us to get it again.
252 void SafeBrowsingProtocolManager::OnURLFetchComplete( 252 void SafeBrowsingProtocolManager::OnURLFetchComplete(
253 const net::URLFetcher* source) { 253 const net::URLFetcher* source) {
254 DCHECK(CalledOnValidThread()); 254 DCHECK(CalledOnValidThread());
255 scoped_ptr<const net::URLFetcher> fetcher; 255 std::unique_ptr<const net::URLFetcher> fetcher;
256 256
257 HashRequests::iterator it = hash_requests_.find(source); 257 HashRequests::iterator it = hash_requests_.find(source);
258 int response_code = source->GetResponseCode(); 258 int response_code = source->GetResponseCode();
259 net::URLRequestStatus status = source->GetStatus(); 259 net::URLRequestStatus status = source->GetStatus();
260 260
261 if (it != hash_requests_.end()) { 261 if (it != hash_requests_.end()) {
262 // GetHash response. 262 // GetHash response.
263 // Reset the scoped pointer so the fetcher gets destroyed properly. 263 // Reset the scoped pointer so the fetcher gets destroyed properly.
264 fetcher.reset(it->first); 264 fetcher.reset(it->first);
265 RecordHttpResponseOrErrorCode(kGetHashUmaResponseMetricName, status, 265 RecordHttpResponseOrErrorCode(kGetHashUmaResponseMetricName, status,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, 409 bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url,
410 const char* data, 410 const char* data,
411 size_t length) { 411 size_t length) {
412 DCHECK(CalledOnValidThread()); 412 DCHECK(CalledOnValidThread());
413 413
414 switch (request_type_) { 414 switch (request_type_) {
415 case UPDATE_REQUEST: 415 case UPDATE_REQUEST:
416 case BACKUP_UPDATE_REQUEST: { 416 case BACKUP_UPDATE_REQUEST: {
417 size_t next_update_sec = 0; 417 size_t next_update_sec = 0;
418 bool reset = false; 418 bool reset = false;
419 scoped_ptr<std::vector<SBChunkDelete>> chunk_deletes( 419 std::unique_ptr<std::vector<SBChunkDelete>> chunk_deletes(
420 new std::vector<SBChunkDelete>); 420 new std::vector<SBChunkDelete>);
421 std::vector<ChunkUrl> chunk_urls; 421 std::vector<ChunkUrl> chunk_urls;
422 if (!ParseUpdate(data, length, &next_update_sec, &reset, 422 if (!ParseUpdate(data, length, &next_update_sec, &reset,
423 chunk_deletes.get(), &chunk_urls)) { 423 chunk_deletes.get(), &chunk_urls)) {
424 return false; 424 return false;
425 } 425 }
426 426
427 // New time for the next update. 427 // New time for the next update.
428 base::TimeDelta finch_next_update_interval = 428 base::TimeDelta finch_next_update_interval =
429 GetNextUpdateIntervalFromFinch(); 429 GetNextUpdateIntervalFromFinch();
(...skipping 26 matching lines...) Expand all
456 if (!chunk_deletes->empty()) 456 if (!chunk_deletes->empty())
457 delegate_->DeleteChunks(std::move(chunk_deletes)); 457 delegate_->DeleteChunks(std::move(chunk_deletes));
458 458
459 break; 459 break;
460 } 460 }
461 case CHUNK_REQUEST: { 461 case CHUNK_REQUEST: {
462 UMA_HISTOGRAM_TIMES("SB2.ChunkRequest", 462 UMA_HISTOGRAM_TIMES("SB2.ChunkRequest",
463 base::Time::Now() - chunk_request_start_); 463 base::Time::Now() - chunk_request_start_);
464 464
465 const ChunkUrl chunk_url = chunk_request_urls_.front(); 465 const ChunkUrl chunk_url = chunk_request_urls_.front();
466 scoped_ptr<std::vector<scoped_ptr<SBChunkData>>> chunks( 466 std::unique_ptr<std::vector<std::unique_ptr<SBChunkData>>> chunks(
467 new std::vector<scoped_ptr<SBChunkData>>); 467 new std::vector<std::unique_ptr<SBChunkData>>);
468 UMA_HISTOGRAM_COUNTS("SB2.ChunkSize", length); 468 UMA_HISTOGRAM_COUNTS("SB2.ChunkSize", length);
469 update_size_ += length; 469 update_size_ += length;
470 if (!ParseChunk(data, length, chunks.get())) 470 if (!ParseChunk(data, length, chunks.get()))
471 return false; 471 return false;
472 472
473 // Chunks to add to storage. Pass ownership of |chunks|. 473 // Chunks to add to storage. Pass ownership of |chunks|.
474 if (!chunks->empty()) { 474 if (!chunks->empty()) {
475 chunk_pending_to_write_ = true; 475 chunk_pending_to_write_ = true;
476 delegate_->AddChunks( 476 delegate_->AddChunks(
477 chunk_url.list_name, std::move(chunks), 477 chunk_url.list_name, std::move(chunks),
(...skipping 11 matching lines...) Expand all
489 return true; 489 return true;
490 } 490 }
491 491
492 void SafeBrowsingProtocolManager::Initialize() { 492 void SafeBrowsingProtocolManager::Initialize() {
493 DCHECK(CalledOnValidThread()); 493 DCHECK(CalledOnValidThread());
494 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/483689 is fixed. 494 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/483689 is fixed.
495 tracked_objects::ScopedTracker tracking_profile( 495 tracked_objects::ScopedTracker tracking_profile(
496 FROM_HERE_WITH_EXPLICIT_FUNCTION( 496 FROM_HERE_WITH_EXPLICIT_FUNCTION(
497 "483689 SafeBrowsingProtocolManager::Initialize")); 497 "483689 SafeBrowsingProtocolManager::Initialize"));
498 // Don't want to hit the safe browsing servers on build/chrome bots. 498 // Don't want to hit the safe browsing servers on build/chrome bots.
499 scoped_ptr<base::Environment> env(base::Environment::Create()); 499 std::unique_ptr<base::Environment> env(base::Environment::Create());
500 if (env->HasVar(env_vars::kHeadless)) 500 if (env->HasVar(env_vars::kHeadless))
501 return; 501 return;
502 ScheduleNextUpdate(false /* no back off */); 502 ScheduleNextUpdate(false /* no back off */);
503 } 503 }
504 504
505 void SafeBrowsingProtocolManager::ScheduleNextUpdate(bool back_off) { 505 void SafeBrowsingProtocolManager::ScheduleNextUpdate(bool back_off) {
506 DCHECK(CalledOnValidThread()); 506 DCHECK(CalledOnValidThread());
507 if (disable_auto_update_) { 507 if (disable_auto_update_) {
508 // Unschedule any current timer. 508 // Unschedule any current timer.
509 update_timer_.Stop(); 509 update_timer_.Stop();
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 : callback(callback), is_download(is_download) {} 801 : callback(callback), is_download(is_download) {}
802 802
803 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( 803 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails(
804 const FullHashDetails& other) = default; 804 const FullHashDetails& other) = default;
805 805
806 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} 806 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {}
807 807
808 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} 808 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {}
809 809
810 } // namespace safe_browsing 810 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_manager_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698