Commit 35bd0aec authored by Mingjing Zhang's avatar Mingjing Zhang Committed by Chromium LUCI CQ

Check for null history service before building DomainDiversityReporter

This CL checks if the |history_service| is valid before it is used to
build a DomainDiversityReporter. This is a guard against unexpected
crashes in DomainDiversityReporter which always requires a valid
history service.

Bug: 1161727
Change-Id: Ie946abe755f7a32bf7b7173e3b146326459edcf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611668Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Mingjing Zhang <mjzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841700}
parent 27e7442d
......@@ -39,6 +39,10 @@ std::unique_ptr<KeyedService> DomainDiversityReporterFactory::BuildInstanceFor(
HistoryServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS);
// Only build DomainDiversityReporter service with a valid |history_service|.
if (!history_service)
return nullptr;
return std::make_unique<DomainDiversityReporter>(
history_service, profile->GetPrefs(), base::DefaultClock::GetInstance());
}
......
......@@ -31,6 +31,8 @@ DomainDiversityReporter::DomainDiversityReporter(
clock_(clock),
history_service_observer_(this) {
DCHECK_NE(prefs_, nullptr);
DCHECK_NE(history_service_, nullptr);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::SequencedTaskRunnerHandle::Get()->PostTask(
......
......@@ -54,6 +54,10 @@ DomainDiversityReporterFactory::BuildServiceInstanceFor(
ios::HistoryServiceFactory::GetForBrowserState(
chrome_browser_state, ServiceAccessType::EXPLICIT_ACCESS);
// Only build DomainDiversityReporter service with a valid |history_service|.
if (!history_service)
return nullptr;
return std::make_unique<DomainDiversityReporter>(
history_service, chrome_browser_state->GetPrefs(),
base::DefaultClock::GetInstance());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment