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 f5bafc5eee4fcd780873baaa5c2bcdadf1ca0065..ac7b736c4002ed760bb5ab42d8eb39e660151c88 100644 |
--- a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc |
+++ b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc |
@@ -171,12 +171,17 @@ void CleanLegacyPruneState(Profile* profile) { |
void AddIncidentOnOriginThread( |
const AddIncidentCallback& callback, |
scoped_refptr<base::SingleThreadTaskRunner> thread_runner, |
+ Profile* profile, |
scoped_ptr<Incident> incident) { |
- if (thread_runner->BelongsToCurrentThread()) |
- callback.Run(incident.Pass()); |
- else |
+ if (thread_runner->BelongsToCurrentThread()) { |
+ callback.Run(profile, incident.Pass()); |
+ } else { |
+ // It is unsafe to bounce the profile from another thread. |
+ DCHECK(!profile); |
thread_runner->PostTask(FROM_HERE, |
- base::Bind(callback, base::Passed(&incident))); |
+ base::Bind(callback, nullptr, |
+ base::Passed(&incident))); |
+ } |
} |
} // namespace |
@@ -293,16 +298,9 @@ IncidentReportingService::~IncidentReportingService() { |
STLDeleteValues(&profiles_); |
} |
-AddIncidentCallback IncidentReportingService::GetAddIncidentCallback( |
- Profile* profile) { |
- // Force the context to be created so that incidents added before |
- // OnProfileAdded is called are held until the profile's preferences can be |
- // queried. |
- ignore_result(GetOrCreateProfileContext(profile)); |
- |
+AddIncidentCallback IncidentReportingService::GetAddIncidentCallback() { |
return base::Bind(&IncidentReportingService::AddIncident, |
- receiver_weak_ptr_factory_.GetWeakPtr(), |
- profile); |
+ receiver_weak_ptr_factory_.GetWeakPtr()); |
} |
scoped_ptr<TrackedPreferenceValidationDelegate> |
@@ -312,7 +310,7 @@ IncidentReportingService::CreatePreferenceValidationDelegate(Profile* profile) { |
if (profile->IsOffTheRecord()) |
return scoped_ptr<TrackedPreferenceValidationDelegate>(); |
return scoped_ptr<TrackedPreferenceValidationDelegate>( |
- new PreferenceValidationDelegate(GetAddIncidentCallback(profile))); |
+ new PreferenceValidationDelegate(profile, GetAddIncidentCallback())); |
} |
void IncidentReportingService::RegisterDelayedAnalysisCallback( |
@@ -325,7 +323,7 @@ void IncidentReportingService::RegisterDelayedAnalysisCallback( |
delayed_analysis_callbacks_.RegisterCallback( |
base::Bind(callback, |
base::Bind(&AddIncidentOnOriginThread, |
- GetAddIncidentCallback(NULL), |
+ GetAddIncidentCallback(), |
base::ThreadTaskRunnerHandle::Get()))); |
// Start running the callbacks if any profiles are participating in safe |
@@ -518,9 +516,11 @@ void IncidentReportingService::AddIncident(Profile* profile, |
scoped_ptr<Incident> incident) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- ProfileContext* context = GetProfileContext(profile); |
- // It is forbidden to call this function with a destroyed profile. |
- DCHECK(context); |
+ // Ignore incidents from off-the-record profiles. |
+ if (profile && profile->IsOffTheRecord()) |
+ return; |
+ |
+ ProfileContext* context = GetOrCreateProfileContext(profile); |
// If this is a process-wide incident, the context must not indicate that the |
// profile (which is NULL) has been added to the profile manager. |
DCHECK(profile || !context->added); |