| 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 476079478343bc7b9835905dda4453c46c51a7ae..047310a383fcf53427c0eadf566005d301603916 100644
|
| --- a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| +++ b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
|
| @@ -18,7 +18,6 @@
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/process/process_info.h"
|
| #include "base/single_thread_task_runner.h"
|
| -#include "base/stl_util.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| @@ -391,8 +390,6 @@ IncidentReportingService::~IncidentReportingService() {
|
| CancelEnvironmentCollection();
|
| CancelDownloadCollection();
|
| CancelAllReportUploads();
|
| -
|
| - base::STLDeleteValues(&profiles_);
|
| }
|
|
|
| std::unique_ptr<IncidentReceiver>
|
| @@ -585,29 +582,27 @@ bool IncidentReportingService::IsProcessingReport() const {
|
|
|
| IncidentReportingService::ProfileContext*
|
| IncidentReportingService::GetOrCreateProfileContext(Profile* profile) {
|
| - ProfileContextCollection::iterator it =
|
| - profiles_.insert(ProfileContextCollection::value_type(profile, nullptr))
|
| - .first;
|
| - if (!it->second)
|
| - it->second = new ProfileContext();
|
| - return it->second;
|
| + std::unique_ptr<ProfileContext>& context = profiles_[profile];
|
| + if (!context)
|
| + context = base::MakeUnique<ProfileContext>();
|
| + return context.get();
|
| }
|
|
|
| IncidentReportingService::ProfileContext*
|
| IncidentReportingService::GetProfileContext(Profile* profile) {
|
| - ProfileContextCollection::iterator it = profiles_.find(profile);
|
| - return it != profiles_.end() ? it->second : nullptr;
|
| + auto it = profiles_.find(profile);
|
| + return it != profiles_.end() ? it->second.get() : nullptr;
|
| }
|
|
|
| void IncidentReportingService::OnProfileDestroyed(Profile* profile) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - ProfileContextCollection::iterator it = profiles_.find(profile);
|
| + auto it = profiles_.find(profile);
|
| if (it == profiles_.end())
|
| return;
|
|
|
| // Take ownership of the context.
|
| - std::unique_ptr<ProfileContext> context(it->second);
|
| + std::unique_ptr<ProfileContext> context = std::move(it->second);
|
| it->second = nullptr;
|
|
|
| // TODO(grt): Persist incidents for upload on future profile load.
|
| @@ -623,25 +618,23 @@ void IncidentReportingService::OnProfileDestroyed(Profile* profile) {
|
|
|
| Profile* IncidentReportingService::FindEligibleProfile() const {
|
| Profile* candidate = nullptr;
|
| - for (ProfileContextCollection::const_iterator scan = profiles_.begin();
|
| - scan != profiles_.end();
|
| - ++scan) {
|
| + for (const auto& scan : profiles_) {
|
| // Skip over profiles that have yet to be added to the profile manager.
|
| // This will also skip over the NULL-profile context used to hold
|
| // process-wide incidents.
|
| - if (!scan->second->added)
|
| + if (!scan.second->added)
|
| continue;
|
| // Also skip over profiles for which IncidentReporting is not enabled.
|
| - if (!IsEnabledForProfile(scan->first))
|
| + if (!IsEnabledForProfile(scan.first))
|
| continue;
|
| // If the current profile has Extended Reporting enabled, stop looking and
|
| // use that one.
|
| - if (IsExtendedReportingEnabled(*scan->first->GetPrefs())) {
|
| - return scan->first;
|
| + if (IsExtendedReportingEnabled(*scan.first->GetPrefs())) {
|
| + return scan.first;
|
| }
|
| // Otherwise, store this one as a candidate and keep looking (in case we
|
| // find one with Extended Reporting enabled).
|
| - candidate = scan->first;
|
| + candidate = scan.first;
|
| }
|
|
|
| return candidate;
|
| @@ -737,9 +730,8 @@ void IncidentReportingService::OnCollationTimeout() {
|
|
|
| // Wait another round if profile-bound incidents have come in from a profile
|
| // that has yet to complete creation.
|
| - for (ProfileContextCollection::iterator scan = profiles_.begin();
|
| - scan != profiles_.end(); ++scan) {
|
| - if (scan->first && !scan->second->added && scan->second->HasIncidents()) {
|
| + for (const auto& scan : profiles_) {
|
| + if (scan.first && !scan.second->added && scan.second->HasIncidents()) {
|
| collation_timer_.Reset();
|
| return;
|
| }
|
| @@ -844,10 +836,8 @@ bool IncidentReportingService::WaitingForMostRecentDownload() {
|
| if (!HasIncidentsToUpload())
|
| return false;
|
| // Harder case 2: waiting if a non-NULL profile has not yet been added.
|
| - for (ProfileContextCollection::const_iterator scan = profiles_.begin();
|
| - scan != profiles_.end();
|
| - ++scan) {
|
| - if (scan->first && !scan->second->added)
|
| + for (const auto& scan : profiles_) {
|
| + if (scan.first && !scan.second->added)
|
| return true;
|
| }
|
| // There is no most recent download and there's nothing more to wait for.
|
| @@ -944,7 +934,7 @@ void IncidentReportingService::ProcessIncidentsIfCollectionComplete() {
|
| profile_and_context.second->incidents_to_clear.empty()) {
|
| continue;
|
| }
|
| - ProfileContext* context = profile_and_context.second;
|
| + ProfileContext* context = profile_and_context.second.get();
|
| StateStore::Transaction transaction(context->state_store.get());
|
| for (const auto& incident : context->incidents_to_clear)
|
| transaction.Clear(incident->GetType(), incident->GetKey());
|
| @@ -967,7 +957,7 @@ void IncidentReportingService::ProcessIncidentsIfCollectionComplete() {
|
| // profile.
|
| if (!profile_and_context.first)
|
| continue;
|
| - ProfileContext* context = profile_and_context.second;
|
| + ProfileContext* context = profile_and_context.second.get();
|
| if (context->incidents.empty())
|
| continue;
|
| StateStore::Transaction transaction(context->state_store.get());
|
|
|