Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: content/browser/background_fetch/background_fetch_context.cc

Issue 2816403004: Fire the `backgroundfetchfail` event for failed fetches (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_context.cc
diff --git a/content/browser/background_fetch/background_fetch_context.cc b/content/browser/background_fetch/background_fetch_context.cc
index f27666efc7abae886b1838eaba08b7b4ed69fa96..4823c20d15ff773160304f48676389efc0331d72 100644
--- a/content/browser/background_fetch/background_fetch_context.cc
+++ b/content/browser/background_fetch/background_fetch_context.cc
@@ -193,6 +193,7 @@ void BackgroundFetchContext::DidCompleteJob(
void BackgroundFetchContext::DidGetSettledFetches(
const BackgroundFetchRegistrationId& registration_id,
blink::mojom::BackgroundFetchError error,
+ bool background_fetch_succeeded,
std::vector<BackgroundFetchSettledFetch> settled_fetches,
std::vector<std::unique_ptr<BlobHandle>> blob_handles) {
if (error != blink::mojom::BackgroundFetchError::NONE) {
@@ -200,14 +201,20 @@ void BackgroundFetchContext::DidGetSettledFetches(
return;
}
- // TODO(peter): Distinguish between the `backgroundfetched` and
- // `backgroundfetchfail` events based on the status code of all fetches. We
- // don't populate that field yet, so always assume it's successful for now.
-
- event_dispatcher_->DispatchBackgroundFetchedEvent(
- registration_id, std::move(settled_fetches),
- base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
- registration_id, std::move(blob_handles)));
+ // The `backgroundfetched` event will be invoked when all requests in the
+ // registration have completed successfully. In all other cases, the
+ // `backgroundfetchfail` event will be invoked instead.
+ if (background_fetch_succeeded) {
+ event_dispatcher_->DispatchBackgroundFetchedEvent(
+ registration_id, std::move(settled_fetches),
+ base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
+ registration_id, std::move(blob_handles)));
+ } else {
+ event_dispatcher_->DispatchBackgroundFetchFailEvent(
+ registration_id, std::move(settled_fetches),
+ base::Bind(&BackgroundFetchContext::DeleteRegistration, this,
+ registration_id, std::move(blob_handles)));
+ }
}
void BackgroundFetchContext::DeleteRegistration(

Powered by Google App Engine
This is Rietveld 408576698