| Index: chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| diff --git a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| index 49f2f77adfa41aee5ccd178af23d246110bd2f0b..955d4f443379c4fd4df160d55e1f594735fb1dd8 100644
|
| --- a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| +++ b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| @@ -6,12 +6,14 @@
|
|
|
| #include <math.h>
|
| #include <stddef.h>
|
| +
|
| #include <algorithm>
|
| #include <utility>
|
| #include <vector>
|
|
|
| #include "base/feature_list.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/metrics/field_trial.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/process/process_info.h"
|
| @@ -150,14 +152,14 @@ struct IncidentReportingService::ProfileContext {
|
|
|
| // The incidents collected for this profile pending creation and/or upload.
|
| // Will contain null values for pruned incidents.
|
| - std::vector<scoped_ptr<Incident>> incidents;
|
| + std::vector<std::unique_ptr<Incident>> incidents;
|
|
|
| // The incidents data of which should be cleared.
|
| - std::vector<scoped_ptr<Incident>> incidents_to_clear;
|
| + std::vector<std::unique_ptr<Incident>> incidents_to_clear;
|
|
|
| // State storage for this profile; null until PROFILE_ADDED notification is
|
| // received.
|
| - scoped_ptr<StateStore> state_store;
|
| + std::unique_ptr<StateStore> state_store;
|
|
|
| // False until PROFILE_ADDED notification is received.
|
| bool added;
|
| @@ -171,14 +173,14 @@ class IncidentReportingService::UploadContext {
|
| typedef std::map<ProfileContext*, std::vector<PersistentIncidentState>>
|
| PersistentIncidentStateCollection;
|
|
|
| - explicit UploadContext(scoped_ptr<ClientIncidentReport> report);
|
| + explicit UploadContext(std::unique_ptr<ClientIncidentReport> report);
|
| ~UploadContext();
|
|
|
| // The report being uploaded.
|
| - scoped_ptr<ClientIncidentReport> report;
|
| + std::unique_ptr<ClientIncidentReport> report;
|
|
|
| // The uploader in use. This is NULL until the CSD killswitch is checked.
|
| - scoped_ptr<IncidentReportUploader> uploader;
|
| + std::unique_ptr<IncidentReportUploader> uploader;
|
|
|
| // A mapping of profile contexts to the data to be persisted upon successful
|
| // upload.
|
| @@ -197,19 +199,19 @@ class IncidentReportingService::Receiver : public IncidentReceiver {
|
|
|
| // IncidentReceiver methods:
|
| void AddIncidentForProfile(Profile* profile,
|
| - scoped_ptr<Incident> incident) override;
|
| - void AddIncidentForProcess(scoped_ptr<Incident> incident) override;
|
| - void ClearIncidentForProcess(scoped_ptr<Incident> incident) override;
|
| + std::unique_ptr<Incident> incident) override;
|
| + void AddIncidentForProcess(std::unique_ptr<Incident> incident) override;
|
| + void ClearIncidentForProcess(std::unique_ptr<Incident> incident) override;
|
|
|
| private:
|
| static void AddIncidentOnMainThread(
|
| const base::WeakPtr<IncidentReportingService>& service,
|
| Profile* profile,
|
| - scoped_ptr<Incident> incident);
|
| + std::unique_ptr<Incident> incident);
|
| static void ClearIncidentOnMainThread(
|
| const base::WeakPtr<IncidentReportingService>& service,
|
| Profile* profile,
|
| - scoped_ptr<Incident> incident);
|
| + std::unique_ptr<Incident> incident);
|
|
|
| base::WeakPtr<IncidentReportingService> service_;
|
| scoped_refptr<base::SingleThreadTaskRunner> thread_runner_;
|
| @@ -228,14 +230,14 @@ IncidentReportingService::Receiver::~Receiver() {
|
|
|
| void IncidentReportingService::Receiver::AddIncidentForProfile(
|
| Profile* profile,
|
| - scoped_ptr<Incident> incident) {
|
| + std::unique_ptr<Incident> incident) {
|
| DCHECK(thread_runner_->BelongsToCurrentThread());
|
| DCHECK(profile);
|
| AddIncidentOnMainThread(service_, profile, std::move(incident));
|
| }
|
|
|
| void IncidentReportingService::Receiver::AddIncidentForProcess(
|
| - scoped_ptr<Incident> incident) {
|
| + std::unique_ptr<Incident> incident) {
|
| if (thread_runner_->BelongsToCurrentThread()) {
|
| AddIncidentOnMainThread(service_, nullptr, std::move(incident));
|
| } else {
|
| @@ -247,7 +249,7 @@ void IncidentReportingService::Receiver::AddIncidentForProcess(
|
| }
|
|
|
| void IncidentReportingService::Receiver::ClearIncidentForProcess(
|
| - scoped_ptr<Incident> incident) {
|
| + std::unique_ptr<Incident> incident) {
|
| if (thread_runner_->BelongsToCurrentThread()) {
|
| ClearIncidentOnMainThread(service_, nullptr, std::move(incident));
|
| } else {
|
| @@ -271,7 +273,7 @@ bool IncidentReportingService::HasIncidentsToUpload() const {
|
| void IncidentReportingService::Receiver::AddIncidentOnMainThread(
|
| const base::WeakPtr<IncidentReportingService>& service,
|
| Profile* profile,
|
| - scoped_ptr<Incident> incident) {
|
| + std::unique_ptr<Incident> incident) {
|
| if (service)
|
| service->AddIncident(profile, std::move(incident));
|
| else
|
| @@ -280,9 +282,9 @@ void IncidentReportingService::Receiver::AddIncidentOnMainThread(
|
|
|
| // static
|
| void IncidentReportingService::Receiver::ClearIncidentOnMainThread(
|
| - const base::WeakPtr<IncidentReportingService>& service,
|
| - Profile* profile,
|
| - scoped_ptr<Incident> incident) {
|
| + const base::WeakPtr<IncidentReportingService>& service,
|
| + Profile* profile,
|
| + std::unique_ptr<Incident> incident) {
|
| if (service)
|
| service->ClearIncident(profile, std::move(incident));
|
| }
|
| @@ -302,7 +304,7 @@ bool IncidentReportingService::ProfileContext::HasIncidents() const {
|
| }
|
|
|
| IncidentReportingService::UploadContext::UploadContext(
|
| - scoped_ptr<ClientIncidentReport> report)
|
| + std::unique_ptr<ClientIncidentReport> report)
|
| : report(std::move(report)) {}
|
|
|
| IncidentReportingService::UploadContext::~UploadContext() {
|
| @@ -385,17 +387,19 @@ IncidentReportingService::~IncidentReportingService() {
|
| STLDeleteValues(&profiles_);
|
| }
|
|
|
| -scoped_ptr<IncidentReceiver> IncidentReportingService::GetIncidentReceiver() {
|
| - return make_scoped_ptr(new Receiver(receiver_weak_ptr_factory_.GetWeakPtr()));
|
| +std::unique_ptr<IncidentReceiver>
|
| +IncidentReportingService::GetIncidentReceiver() {
|
| + return base::WrapUnique(
|
| + new Receiver(receiver_weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| -scoped_ptr<TrackedPreferenceValidationDelegate>
|
| +std::unique_ptr<TrackedPreferenceValidationDelegate>
|
| IncidentReportingService::CreatePreferenceValidationDelegate(Profile* profile) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| if (profile->IsOffTheRecord())
|
| - return scoped_ptr<TrackedPreferenceValidationDelegate>();
|
| - return scoped_ptr<TrackedPreferenceValidationDelegate>(
|
| + return std::unique_ptr<TrackedPreferenceValidationDelegate>();
|
| + return std::unique_ptr<TrackedPreferenceValidationDelegate>(
|
| new PreferenceValidationDelegate(profile, GetIncidentReceiver()));
|
| }
|
|
|
| @@ -555,7 +559,8 @@ void IncidentReportingService::OnProfileAdded(Profile* profile) {
|
| BeginDownloadCollection();
|
| }
|
|
|
| -scoped_ptr<LastDownloadFinder> IncidentReportingService::CreateDownloadFinder(
|
| +std::unique_ptr<LastDownloadFinder>
|
| +IncidentReportingService::CreateDownloadFinder(
|
| const LastDownloadFinder::LastDownloadCallback& callback) {
|
| return LastDownloadFinder::Create(
|
| base::Bind(&DownloadMetadataManager::GetDownloadDetails,
|
| @@ -563,7 +568,8 @@ scoped_ptr<LastDownloadFinder> IncidentReportingService::CreateDownloadFinder(
|
| callback);
|
| }
|
|
|
| -scoped_ptr<IncidentReportUploader> IncidentReportingService::StartReportUpload(
|
| +std::unique_ptr<IncidentReportUploader>
|
| +IncidentReportingService::StartReportUpload(
|
| const IncidentReportUploader::OnResultCallback& callback,
|
| const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
|
| const ClientIncidentReport& report) {
|
| @@ -599,7 +605,7 @@ void IncidentReportingService::OnProfileDestroyed(Profile* profile) {
|
| return;
|
|
|
| // Take ownership of the context.
|
| - scoped_ptr<ProfileContext> context(it->second);
|
| + std::unique_ptr<ProfileContext> context(it->second);
|
| it->second = nullptr;
|
|
|
| // TODO(grt): Persist incidents for upload on future profile load.
|
| @@ -641,7 +647,7 @@ Profile* IncidentReportingService::FindEligibleProfile() const {
|
| }
|
|
|
| void IncidentReportingService::AddIncident(Profile* profile,
|
| - scoped_ptr<Incident> incident) {
|
| + std::unique_ptr<Incident> incident) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| // Ignore incidents from off-the-record profiles.
|
| @@ -683,8 +689,9 @@ void IncidentReportingService::AddIncident(Profile* profile,
|
| BeginReportProcessing();
|
| }
|
|
|
| -void IncidentReportingService::ClearIncident(Profile* profile,
|
| - scoped_ptr<Incident> incident) {
|
| +void IncidentReportingService::ClearIncident(
|
| + Profile* profile,
|
| + std::unique_ptr<Incident> incident) {
|
| ProfileContext* context = GetOrCreateProfileContext(profile);
|
| context->incidents_to_clear.push_back(std::move(incident));
|
| // Begin processing to handle cleared incidents following collation.
|
| @@ -758,11 +765,10 @@ void IncidentReportingService::BeginEnvironmentCollection() {
|
| new ClientIncidentReport_EnvironmentData();
|
| environment_collection_pending_ =
|
| environment_collection_task_runner_->PostTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(collect_environment_data_fn_, environment_data),
|
| + FROM_HERE, base::Bind(collect_environment_data_fn_, environment_data),
|
| base::Bind(&IncidentReportingService::OnEnvironmentDataCollected,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(make_scoped_ptr(environment_data))));
|
| + base::Passed(base::WrapUnique(environment_data))));
|
|
|
| // Posting the task will fail if the runner has been shut down. This should
|
| // never happen since the blocking pool is shut down after this service.
|
| @@ -781,7 +787,7 @@ void IncidentReportingService::CancelEnvironmentCollection() {
|
| }
|
|
|
| void IncidentReportingService::OnEnvironmentDataCollected(
|
| - scoped_ptr<ClientIncidentReport_EnvironmentData> environment_data) {
|
| + std::unique_ptr<ClientIncidentReport_EnvironmentData> environment_data) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(environment_collection_pending_);
|
| DCHECK(report_ && !report_->has_environment());
|
| @@ -855,8 +861,8 @@ void IncidentReportingService::CancelDownloadCollection() {
|
| }
|
|
|
| void IncidentReportingService::OnLastDownloadFound(
|
| - scoped_ptr<ClientIncidentReport_DownloadDetails> last_binary_download,
|
| - scoped_ptr<ClientIncidentReport_NonBinaryDownloadDetails>
|
| + std::unique_ptr<ClientIncidentReport_DownloadDetails> last_binary_download,
|
| + std::unique_ptr<ClientIncidentReport_NonBinaryDownloadDetails>
|
| last_non_binary_download) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(report_);
|
| @@ -889,7 +895,7 @@ void IncidentReportingService::ProcessIncidentsIfCollectionComplete() {
|
| }
|
|
|
| // Take ownership of the report and clear things for future reports.
|
| - scoped_ptr<ClientIncidentReport> report(std::move(report_));
|
| + std::unique_ptr<ClientIncidentReport> report(std::move(report_));
|
| first_incident_time_ = base::Time();
|
| last_incident_time_ = base::TimeTicks();
|
|
|
| @@ -1018,7 +1024,7 @@ void IncidentReportingService::ProcessIncidentsIfCollectionComplete() {
|
| // Perform final synchronous collection tasks for the report.
|
| DoExtensionCollection(report->mutable_extension_data());
|
|
|
| - scoped_ptr<UploadContext> context(new UploadContext(std::move(report)));
|
| + std::unique_ptr<UploadContext> context(new UploadContext(std::move(report)));
|
| context->profiles_to_state.swap(profiles_to_state);
|
| if (!database_manager_.get()) {
|
| // No database manager during testing. Take ownership of the context and
|
| @@ -1061,12 +1067,11 @@ void IncidentReportingService::OnKillSwitchResult(UploadContext* context,
|
| if (!context->uploader) {
|
| OnReportUploadResult(context,
|
| IncidentReportUploader::UPLOAD_INVALID_REQUEST,
|
| - scoped_ptr<ClientIncidentResponse>());
|
| + std::unique_ptr<ClientIncidentResponse>());
|
| }
|
| } else {
|
| - OnReportUploadResult(context,
|
| - IncidentReportUploader::UPLOAD_SUPPRESSED,
|
| - scoped_ptr<ClientIncidentResponse>());
|
| + OnReportUploadResult(context, IncidentReportUploader::UPLOAD_SUPPRESSED,
|
| + std::unique_ptr<ClientIncidentResponse>());
|
| }
|
| }
|
|
|
| @@ -1083,7 +1088,7 @@ void IncidentReportingService::HandleResponse(const UploadContext& context) {
|
| void IncidentReportingService::OnReportUploadResult(
|
| UploadContext* context,
|
| IncidentReportUploader::Result result,
|
| - scoped_ptr<ClientIncidentResponse> response) {
|
| + std::unique_ptr<ClientIncidentResponse> response) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| UMA_HISTOGRAM_ENUMERATION(
|
| @@ -1091,12 +1096,13 @@ void IncidentReportingService::OnReportUploadResult(
|
|
|
| // The upload is no longer outstanding, so take ownership of the context (from
|
| // the collection of outstanding uploads) in this scope.
|
| - auto it = std::find_if(uploads_.begin(), uploads_.end(),
|
| - [context] (const scoped_ptr<UploadContext>& value) {
|
| - return value.get() == context;
|
| - });
|
| + auto it =
|
| + std::find_if(uploads_.begin(), uploads_.end(),
|
| + [context](const std::unique_ptr<UploadContext>& value) {
|
| + return value.get() == context;
|
| + });
|
| DCHECK(it != uploads_.end());
|
| - scoped_ptr<UploadContext> upload(std::move(*it));
|
| + std::unique_ptr<UploadContext> upload(std::move(*it));
|
| uploads_.erase(it);
|
|
|
| if (result == IncidentReportUploader::UPLOAD_SUCCESS)
|
|
|