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

Unified Diff: content/browser/background_fetch/background_fetch_data_manager.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_data_manager.cc
diff --git a/content/browser/background_fetch/background_fetch_data_manager.cc b/content/browser/background_fetch/background_fetch_data_manager.cc
index 83e750964a1537095c2347ae76f0c9ea1a5aa364..2fcb85e21e19ebd5937f96b55a6da7ec01e73cbb 100644
--- a/content/browser/background_fetch/background_fetch_data_manager.cc
+++ b/content/browser/background_fetch/background_fetch_data_manager.cc
@@ -21,6 +21,14 @@
namespace content {
+// Returns whether the response contained in the Background Fetch |request| is
+// considered OK. See https://fetch.spec.whatwg.org/#ok-status aka a successful
+// 2xx status per https://tools.ietf.org/html/rfc7231#section-6.3.
+bool IsOK(const BackgroundFetchRequestInfo& request) {
+ int status = request.GetResponseCode();
+ return status >= 200 && status < 300;
+}
+
// The Registration Data class encapsulates the data stored for a particular
// Background Fetch registration. This roughly matches the on-disk format that
// will be adhered to in the future.
@@ -198,6 +206,8 @@ void BackgroundFetchDataManager::GetSettledFetchesForRegistration(
const std::vector<scoped_refptr<BackgroundFetchRequestInfo>>& requests =
registration_data->GetCompletedRequests();
+ bool background_fetch_succeeded = true;
+
std::vector<BackgroundFetchSettledFetch> settled_fetches;
settled_fetches.reserve(requests.size());
@@ -238,16 +248,23 @@ void BackgroundFetchDataManager::GetSettledFetchesForRegistration(
blob_handles.push_back(std::move(blob_handle));
}
}
+ } else {
+ // TODO(crbug.com/711354): Consider Background Fetches as failed when the
+ // response cannot be relayed to the developer.
+ background_fetch_succeeded = false;
}
// TODO: settled_fetch.response.error
settled_fetch.response.response_time = request->GetResponseTime();
// TODO: settled_fetch.response.cors_exposed_header_names
+ background_fetch_succeeded = background_fetch_succeeded && IsOK(*request);
+
settled_fetches.push_back(settled_fetch);
}
std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE,
+ background_fetch_succeeded,
std::move(settled_fetches), std::move(blob_handles));
}

Powered by Google App Engine
This is Rietveld 408576698