Commit 3669e7b2 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background fetch] Forward-fix test regression.

In the delegate proxy refactor (crrev.com/1422158), some if statements
where changed to DCHECKs. When aborted, some of the Download Service
callbacks can still be received due to race conditions.

This CL switches the DCHECKs back to if statements.

Bug: 850512
Change-Id: I4154070635d5434819c07b394fbfe323ca9fdb9e
Reviewed-on: https://chromium-review.googlesource.com/c/1456063Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629554}
parent 6aa9866c
...@@ -429,10 +429,11 @@ void BackgroundFetchDelegateProxy::OnJobCancelled( ...@@ -429,10 +429,11 @@ void BackgroundFetchDelegateProxy::OnJobCancelled(
reason_to_abort == reason_to_abort ==
blink::mojom::BackgroundFetchFailureReason::DOWNLOAD_TOTAL_EXCEEDED); blink::mojom::BackgroundFetchFailureReason::DOWNLOAD_TOTAL_EXCEEDED);
DCHECK(controller_map_.count(job_unique_id)); auto it = controller_map_.find(job_unique_id);
auto& controller = controller_map_[job_unique_id]; if (it == controller_map_.end())
return;
if (controller) if (const auto& controller = it->second)
controller->AbortFromDelegate(reason_to_abort); controller->AbortFromDelegate(reason_to_abort);
} }
...@@ -442,10 +443,11 @@ void BackgroundFetchDelegateProxy::DidStartRequest( ...@@ -442,10 +443,11 @@ void BackgroundFetchDelegateProxy::DidStartRequest(
std::unique_ptr<BackgroundFetchResponse> response) { std::unique_ptr<BackgroundFetchResponse> response) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(controller_map_.count(job_unique_id)); auto it = controller_map_.find(job_unique_id);
auto& controller = controller_map_[job_unique_id]; if (it == controller_map_.end())
return;
if (controller) if (const auto& controller = it->second)
controller->DidStartRequest(guid, std::move(response)); controller->DidStartRequest(guid, std::move(response));
} }
...@@ -458,9 +460,10 @@ void BackgroundFetchDelegateProxy::DidActivateUI( ...@@ -458,9 +460,10 @@ void BackgroundFetchDelegateProxy::DidActivateUI(
void BackgroundFetchDelegateProxy::DidUpdateUI( void BackgroundFetchDelegateProxy::DidUpdateUI(
const std::string& job_unique_id) { const std::string& job_unique_id) {
auto it = update_ui_callback_map_.find(job_unique_id); auto it = update_ui_callback_map_.find(job_unique_id);
DCHECK(it != update_ui_callback_map_.end()); if (it == update_ui_callback_map_.end())
DCHECK(it->second); return;
DCHECK(it->second);
std::move(it->second).Run(blink::mojom::BackgroundFetchError::NONE); std::move(it->second).Run(blink::mojom::BackgroundFetchError::NONE);
update_ui_callback_map_.erase(it); update_ui_callback_map_.erase(it);
} }
...@@ -472,12 +475,12 @@ void BackgroundFetchDelegateProxy::OnDownloadUpdated( ...@@ -472,12 +475,12 @@ void BackgroundFetchDelegateProxy::OnDownloadUpdated(
uint64_t bytes_downloaded) { uint64_t bytes_downloaded) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(controller_map_.count(job_unique_id)); auto it = controller_map_.find(job_unique_id);
auto& controller = controller_map_[job_unique_id]; if (it == controller_map_.end())
return;
if (controller) { if (const auto& controller = it->second)
controller->DidUpdateRequest(guid, bytes_uploaded, bytes_downloaded); controller->DidUpdateRequest(guid, bytes_uploaded, bytes_downloaded);
}
} }
void BackgroundFetchDelegateProxy::OnDownloadComplete( void BackgroundFetchDelegateProxy::OnDownloadComplete(
...@@ -486,10 +489,11 @@ void BackgroundFetchDelegateProxy::OnDownloadComplete( ...@@ -486,10 +489,11 @@ void BackgroundFetchDelegateProxy::OnDownloadComplete(
std::unique_ptr<BackgroundFetchResult> result) { std::unique_ptr<BackgroundFetchResult> result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(controller_map_.count(job_unique_id)); auto it = controller_map_.find(job_unique_id);
auto& controller = controller_map_[job_unique_id]; if (it == controller_map_.end())
return;
if (controller) if (const auto& controller = it->second)
controller->DidCompleteRequest(guid, std::move(result)); controller->DidCompleteRequest(guid, std::move(result));
} }
...@@ -497,10 +501,13 @@ void BackgroundFetchDelegateProxy::GetUploadData( ...@@ -497,10 +501,13 @@ void BackgroundFetchDelegateProxy::GetUploadData(
const std::string& job_unique_id, const std::string& job_unique_id,
const std::string& download_guid, const std::string& download_guid,
BackgroundFetchDelegate::GetUploadDataCallback callback) { BackgroundFetchDelegate::GetUploadDataCallback callback) {
DCHECK(controller_map_.count(job_unique_id)); auto it = controller_map_.find(job_unique_id);
auto& controller = controller_map_[job_unique_id]; if (it == controller_map_.end()) {
std::move(callback).Run(nullptr);
return;
}
if (controller) if (const auto& controller = it->second)
controller->GetUploadData(download_guid, std::move(callback)); controller->GetUploadData(download_guid, std::move(callback));
else else
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
......
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