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

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.cc

Issue 2259523003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 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 "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 new ManagerContext(read_runner_, write_runner_, download_manager); 374 new ManagerContext(read_runner_, write_runner_, download_manager);
375 } 375 }
376 376
377 void DownloadMetadataManager::SetRequest(content::DownloadItem* item, 377 void DownloadMetadataManager::SetRequest(content::DownloadItem* item,
378 const ClientDownloadRequest* request) { 378 const ClientDownloadRequest* request) {
379 DCHECK(request); 379 DCHECK(request);
380 content::DownloadManager* download_manager = 380 content::DownloadManager* download_manager =
381 GetDownloadManagerForBrowserContext(item->GetBrowserContext()); 381 GetDownloadManagerForBrowserContext(item->GetBrowserContext());
382 DCHECK_EQ(contexts_.count(download_manager), 1U); 382 DCHECK_EQ(contexts_.count(download_manager), 1U);
383 contexts_[download_manager]->SetRequest( 383 contexts_[download_manager]->SetRequest(
384 item, base::WrapUnique(new ClientDownloadRequest(*request))); 384 item, base::MakeUnique<ClientDownloadRequest>(*request));
385 } 385 }
386 386
387 void DownloadMetadataManager::GetDownloadDetails( 387 void DownloadMetadataManager::GetDownloadDetails(
388 content::BrowserContext* browser_context, 388 content::BrowserContext* browser_context,
389 const GetDownloadDetailsCallback& callback) { 389 const GetDownloadDetailsCallback& callback) {
390 DCHECK(browser_context); 390 DCHECK(browser_context);
391 // The DownloadManager for |browser_context| may not have been created yet. In 391 // The DownloadManager for |browser_context| may not have been created yet. In
392 // this case, asking for it would cause history to load in the background and 392 // this case, asking for it would cause history to load in the background and
393 // wouldn't really help much. Instead, scan the contexts to see if one belongs 393 // wouldn't really help much. Instead, scan the contexts to see if one belongs
394 // to |browser_context|. If one is not found, read the metadata and return it. 394 // to |browser_context|. If one is not found, read the metadata and return it.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 DownloadItemData::SetRequestForDownload(download, std::move(request)); 486 DownloadItemData::SetRequestForDownload(download, std::move(request));
487 else 487 else
488 CommitRequest(download, std::move(request)); 488 CommitRequest(download, std::move(request));
489 } 489 }
490 490
491 void DownloadMetadataManager::ManagerContext::GetDownloadDetails( 491 void DownloadMetadataManager::ManagerContext::GetDownloadDetails(
492 const GetDownloadDetailsCallback& callback) { 492 const GetDownloadDetailsCallback& callback) {
493 if (state_ != LOAD_COMPLETE) { 493 if (state_ != LOAD_COMPLETE) {
494 get_details_callbacks_.push_back(callback); 494 get_details_callbacks_.push_back(callback);
495 } else { 495 } else {
496 callback.Run( 496 callback.Run(download_metadata_
497 download_metadata_ 497 ? base::MakeUnique<ClientIncidentReport_DownloadDetails>(
498 ? base::WrapUnique(new ClientIncidentReport_DownloadDetails( 498 download_metadata_->download())
499 download_metadata_->download())) 499 : nullptr);
500 : nullptr);
501 } 500 }
502 } 501 }
503 502
504 void DownloadMetadataManager::ManagerContext::OnDownloadUpdated( 503 void DownloadMetadataManager::ManagerContext::OnDownloadUpdated(
505 content::DownloadItem* download) { 504 content::DownloadItem* download) {
506 // Persist metadata for this download if it has just completed. 505 // Persist metadata for this download if it has just completed.
507 if (download->GetState() == content::DownloadItem::COMPLETE) { 506 if (download->GetState() == content::DownloadItem::COMPLETE) {
508 // Ignore downloads we don't have a ClientDownloadRequest for. 507 // Ignore downloads we don't have a ClientDownloadRequest for.
509 std::unique_ptr<ClientDownloadRequest> request = 508 std::unique_ptr<ClientDownloadRequest> request =
510 DownloadItemData::TakeRequestForDownload(download); 509 DownloadItemData::TakeRequestForDownload(download);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 RunCallbacks(); 596 RunCallbacks();
598 } 597 }
599 598
600 void DownloadMetadataManager::ManagerContext::ClearPendingItems() { 599 void DownloadMetadataManager::ManagerContext::ClearPendingItems() {
601 pending_items_.clear(); 600 pending_items_.clear();
602 } 601 }
603 602
604 void DownloadMetadataManager::ManagerContext::RunCallbacks() { 603 void DownloadMetadataManager::ManagerContext::RunCallbacks() {
605 while (!get_details_callbacks_.empty()) { 604 while (!get_details_callbacks_.empty()) {
606 const auto& callback = get_details_callbacks_.front(); 605 const auto& callback = get_details_callbacks_.front();
607 callback.Run( 606 callback.Run(download_metadata_
608 download_metadata_ 607 ? base::MakeUnique<ClientIncidentReport_DownloadDetails>(
609 ? base::WrapUnique(new ClientIncidentReport_DownloadDetails( 608 download_metadata_->download())
610 download_metadata_->download())) 609 : nullptr);
611 : nullptr);
612 get_details_callbacks_.pop_front(); 610 get_details_callbacks_.pop_front();
613 } 611 }
614 } 612 }
615 613
616 bool DownloadMetadataManager::ManagerContext::HasMetadataFor( 614 bool DownloadMetadataManager::ManagerContext::HasMetadataFor(
617 const content::DownloadItem* item) const { 615 const content::DownloadItem* item) const {
618 // There must not be metadata if the load is not complete. 616 // There must not be metadata if the load is not complete.
619 DCHECK(state_ == LOAD_COMPLETE || !download_metadata_); 617 DCHECK(state_ == LOAD_COMPLETE || !download_metadata_);
620 return (download_metadata_ && 618 return (download_metadata_ &&
621 download_metadata_->download_id() == item->GetId()); 619 download_metadata_->download_id() == item->GetId());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 656 }
659 657
660 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime( 658 void DownloadMetadataManager::ManagerContext::UpdateLastOpenedTime(
661 const base::Time& last_opened_time) { 659 const base::Time& last_opened_time) {
662 download_metadata_->mutable_download()->set_open_time_msec( 660 download_metadata_->mutable_download()->set_open_time_msec(
663 last_opened_time.ToJavaTime()); 661 last_opened_time.ToJavaTime());
664 WriteMetadata(); 662 WriteMetadata();
665 } 663 }
666 664
667 } // namespace safe_browsing 665 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698