Chromium Code Reviews| 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..416bcb0508f655a5672995da58fd1aba4a142db2 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,9 +618,7 @@ void IncidentReportingService::OnProfileDestroyed(Profile* profile) { |
| Profile* IncidentReportingService::FindEligibleProfile() const { |
| Profile* candidate = nullptr; |
| - for (ProfileContextCollection::const_iterator scan = profiles_.begin(); |
| - scan != profiles_.end(); |
| - ++scan) { |
| + for (auto scan = profiles_.begin(); scan != profiles_.end(); ++scan) { |
|
Nico
2016/10/24 18:41:02
nit: foreach?
Avi (use Gerrit)
2016/10/24 19:15:37
Done.
|
| // 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. |
| @@ -737,8 +730,7 @@ 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) { |
| + for (auto scan = profiles_.begin(); scan != profiles_.end(); ++scan) { |
|
Nico
2016/10/24 18:41:02
ditto
Avi (use Gerrit)
2016/10/24 19:15:37
Done.
|
| if (scan->first && !scan->second->added && scan->second->HasIncidents()) { |
| collation_timer_.Reset(); |
| return; |
| @@ -844,9 +836,7 @@ 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) { |
| + for (auto scan = profiles_.begin(); scan != profiles_.end(); ++scan) { |
|
Nico
2016/10/24 18:41:02
ditto
Avi (use Gerrit)
2016/10/24 19:15:37
Done.
|
| if (scan->first && !scan->second->added) |
| return true; |
| } |
| @@ -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()); |