Commit 0f378fd1 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Part 1: Implement BackgroundFetchFailureReason.

This is step 1, everything needed to support this on the browser side.

Bug: 876691, 869918
Change-Id: I4c161ae404e24caae9d09b7ea4709a6eb161a95e
Reviewed-on: https://chromium-review.googlesource.com/1185006
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585835}
parent 3cbe9284
......@@ -11,13 +11,26 @@ package content.proto;
// Stores per-registration (as opposed to per-request) data.
// https://wicg.github.io/background-fetch/#background-fetch-registration
//
// Next Tag: 8
// Next Tag: 9
message BackgroundFetchRegistration {
enum BackgroundFetchState {
PENDING = 0; // Default value.
FAILURE = 1;
SUCCESS = 2;
}
// This should be kept in sync with blink.mojom.BackgroundFetchFailureReason.
enum BackgroundFetchFailureReason {
NONE = 0; // Default value.
CANCELLED_FROM_UI = 1;
CANCELLED_BY_DEVELOPER = 2;
BAD_STATUS = 3;
FETCH_ERROR = 4;
SERVICE_WORKER_UNAVAILABLE = 5;
QUOTA_EXCEEDED = 6;
TOTAL_DOWNLOAD_SIZE_EXCEEDED = 7;
}
// See definition of |unique_id| in BackgroundFetchRegistrationId.
optional string unique_id = 1;
......@@ -29,6 +42,7 @@ message BackgroundFetchRegistration {
optional uint64 download_total = 5;
optional uint64 downloaded = 6;
optional BackgroundFetchState state = 7;
optional BackgroundFetchFailureReason failure_reason = 8;
}
// Developer provided options.
......
......@@ -25,6 +25,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
last_developer_id_ = registration.developer_id;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
if (fail_abort_event_) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED,
......@@ -44,6 +45,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
last_developer_id_ = registration.developer_id;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
if (fail_click_event_) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED,
......@@ -64,6 +66,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
last_developer_id_ = registration.developer_id;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
last_fetches_ = fetches;
if (fail_fetch_fail_event_) {
......@@ -86,6 +89,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchSuccessEvent(
last_developer_id_ = registration.developer_id;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
last_fetches_ = fetches;
if (fail_fetched_event_) {
......
......@@ -55,6 +55,10 @@ class BackgroundFetchEmbeddedWorkerTestHelper
const base::Optional<blink::mojom::BackgroundFetchState>& last_state() const {
return last_state_;
}
const base::Optional<blink::mojom::BackgroundFetchFailureReason>&
last_failure_reason() const {
return last_failure_reason_;
}
const base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches()
const {
return last_fetches_;
......@@ -95,6 +99,8 @@ class BackgroundFetchEmbeddedWorkerTestHelper
base::Optional<std::string> last_developer_id_;
base::Optional<std::string> last_unique_id_;
base::Optional<blink::mojom::BackgroundFetchState> last_state_;
base::Optional<blink::mojom::BackgroundFetchFailureReason>
last_failure_reason_;
base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchEmbeddedWorkerTestHelper);
......
......@@ -48,7 +48,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchInvalidRegistration) {
auto registration = CreateBackgroundFetchRegistration(
invalid_registration_id.developer_id(),
invalid_registration_id.unique_id(),
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED);
event_dispatcher_.DispatchBackgroundFetchAbortEvent(
invalid_registration_id, std::move(registration), run_loop.QuitClosure());
......@@ -78,7 +79,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId, kExampleUniqueId,
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI);
event_dispatcher_.DispatchBackgroundFetchAbortEvent(
registration_id, std::move(registration), run_loop.QuitClosure());
......@@ -91,6 +93,9 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId,
embedded_worker_test_helper()->last_unique_id().value());
ASSERT_TRUE(embedded_worker_test_helper()->last_failure_reason().has_value());
EXPECT_EQ(blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI,
embedded_worker_test_helper()->last_failure_reason());
histogram_tester_.ExpectUniqueSample(
"BackgroundFetch.EventDispatchResult.AbortEvent",
......@@ -106,7 +111,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId2, kExampleUniqueId2,
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED);
event_dispatcher_.DispatchBackgroundFetchAbortEvent(second_registration_id,
std::move(registration),
run_loop.QuitClosure());
......@@ -145,7 +151,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId, kExampleUniqueId,
blink::mojom::BackgroundFetchState::PENDING);
blink::mojom::BackgroundFetchState::PENDING,
blink::mojom::BackgroundFetchFailureReason::NONE);
event_dispatcher_.DispatchBackgroundFetchClickEvent(
registration_id, std::move(registration), run_loop.QuitClosure());
......@@ -173,7 +180,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId2, kExampleUniqueId2,
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED);
event_dispatcher_.DispatchBackgroundFetchClickEvent(second_registration_id,
std::move(registration),
run_loop.QuitClosure());
......@@ -215,7 +223,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId, kExampleUniqueId,
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED);
event_dispatcher_.DispatchBackgroundFetchFailEvent(
registration_id, std::move(registration), fetches,
run_loop.QuitClosure());
......@@ -247,7 +256,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId2, kExampleUniqueId2,
blink::mojom::BackgroundFetchState::FAILURE);
blink::mojom::BackgroundFetchState::FAILURE,
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED);
event_dispatcher_.DispatchBackgroundFetchFailEvent(
second_registration_id, std::move(registration), fetches,
run_loop.QuitClosure());
......@@ -290,7 +300,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId, kExampleUniqueId,
blink::mojom::BackgroundFetchState::SUCCESS);
blink::mojom::BackgroundFetchState::SUCCESS,
blink::mojom::BackgroundFetchFailureReason::NONE);
event_dispatcher_.DispatchBackgroundFetchSuccessEvent(
registration_id, std::move(registration), fetches,
run_loop.QuitClosure());
......@@ -326,7 +337,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) {
base::RunLoop run_loop;
auto registration = CreateBackgroundFetchRegistration(
kExampleDeveloperId2, kExampleUniqueId2,
blink::mojom::BackgroundFetchState::SUCCESS);
blink::mojom::BackgroundFetchState::SUCCESS,
blink::mojom::BackgroundFetchFailureReason::NONE);
event_dispatcher_.DispatchBackgroundFetchSuccessEvent(
second_registration_id, std::move(registration), fetches,
run_loop.QuitClosure());
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "content/browser/background_fetch/background_fetch_job_controller.h"
#include "third_party/blink/public/platform/modules/background_fetch/background_fetch.mojom.h"
#include <utility>
......@@ -143,15 +144,40 @@ BackgroundFetchJobController::NewRegistration(
return std::make_unique<BackgroundFetchRegistration>(
registration_id().developer_id(), registration_id().unique_id(),
0 /* upload_total */, 0 /* uploaded */, total_downloads_size_,
complete_requests_downloaded_bytes_cache_, state);
complete_requests_downloaded_bytes_cache_, state, MojoFailureReason());
}
uint64_t BackgroundFetchJobController::GetInProgressDownloadedBytes() {
return active_request_downloaded_bytes_;
}
// TODO(crbug.com/876691): Get rid of BackgroundFetchReasonToAbort and remove
// this method.
blink::mojom::BackgroundFetchFailureReason
BackgroundFetchJobController::MojoFailureReason() const {
switch (reason_to_abort_) {
case BackgroundFetchReasonToAbort::NONE:
return blink::mojom::BackgroundFetchFailureReason::NONE;
case BackgroundFetchReasonToAbort::CANCELLED_FROM_UI:
return blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI;
case BackgroundFetchReasonToAbort::ABORTED_BY_DEVELOPER:
return blink::mojom::BackgroundFetchFailureReason::CANCELLED_BY_DEVELOPER;
case BackgroundFetchReasonToAbort::TOTAL_DOWNLOAD_SIZE_EXCEEDED:
return blink::mojom::BackgroundFetchFailureReason::
TOTAL_DOWNLOAD_SIZE_EXCEEDED;
case BackgroundFetchReasonToAbort::SERVICE_WORKER_UNAVAILABLE:
return blink::mojom::BackgroundFetchFailureReason::
SERVICE_WORKER_UNAVAILABLE;
case BackgroundFetchReasonToAbort::QUOTA_EXCEEDED:
return blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED;
}
NOTREACHED();
}
void BackgroundFetchJobController::Abort(
BackgroundFetchReasonToAbort reason_to_abort) {
reason_to_abort_ = reason_to_abort;
// Stop propagating any in-flight events to the scheduler.
active_request_finished_callback_.Reset();
......
......@@ -113,6 +113,10 @@ class CONTENT_EXPORT BackgroundFetchJobController final
void Abort(BackgroundFetchReasonToAbort reason_to_abort) override;
private:
// Returns reason_to_abort_ as blink::mojom::BackgroundFetchFailureReason.
// TODO(crbug.com/876691): Get rid of BackgroundFetchReasonToAbort and remove
// this converter.
blink::mojom::BackgroundFetchFailureReason MojoFailureReason() const;
// Options for the represented background fetch registration.
BackgroundFetchOptions options_;
......@@ -146,6 +150,10 @@ class CONTENT_EXPORT BackgroundFetchJobController final
// Number of the requests that have been completed so far.
int completed_downloads_ = 0;
// The reason background fetch was aborted.
BackgroundFetchReasonToAbort reason_to_abort_ =
BackgroundFetchReasonToAbort::NONE;
base::WeakPtrFactory<BackgroundFetchJobController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchJobController);
......
......@@ -167,10 +167,11 @@ std::unique_ptr<BackgroundFetchRegistration>
BackgroundFetchTestBase::CreateBackgroundFetchRegistration(
const std::string& developer_id,
const std::string& unique_id,
blink::mojom::BackgroundFetchState state) {
blink::mojom::BackgroundFetchState state,
blink::mojom::BackgroundFetchFailureReason failure_reason) {
auto registration = std::make_unique<BackgroundFetchRegistration>(
developer_id, unique_id, 0 /* upload_total */, 0 /* uploaded */,
0 /* download_total */, 0 /* downloaded */, state);
0 /* download_total */, 0 /* downloaded */, state, failure_reason);
return registration;
}
......
......@@ -57,10 +57,12 @@ class BackgroundFetchTestBase : public ::testing::Test {
std::unique_ptr<TestResponse> response);
// Creates a BackgroundFetchRegistration object.
static std::unique_ptr<BackgroundFetchRegistration>
CreateBackgroundFetchRegistration(const std::string& developer_id,
const std::string& unique_id,
blink::mojom::BackgroundFetchState state);
std::unique_ptr<BackgroundFetchRegistration>
CreateBackgroundFetchRegistration(
const std::string& developer_id,
const std::string& unique_id,
blink::mojom::BackgroundFetchState state,
blink::mojom::BackgroundFetchFailureReason failure_reason);
// Returns the embedded worker test helper instance, which can be used to
// influence the behavior of the Service Worker events.
......
......@@ -103,6 +103,8 @@ void CreateMetadataTask::InitializeMetadataProto() {
registration_proto->set_download_total(options_.download_total);
registration_proto->set_state(
proto::BackgroundFetchRegistration_BackgroundFetchState_PENDING);
registration_proto->set_failure_reason(
proto::BackgroundFetchRegistration_BackgroundFetchFailureReason_NONE);
// Set Options fields.
auto* options_proto = metadata_proto_->mutable_options();
......@@ -223,7 +225,14 @@ void CreateMetadataTask::FinishWithError(
if (error == blink::mojom::BackgroundFetchError::NONE) {
DCHECK(metadata_proto_);
registration = ToBackgroundFetchRegistration(*metadata_proto_);
bool converted =
ToBackgroundFetchRegistration(*metadata_proto_, &registration);
if (!converted) {
// Database corrupted.
SetStorageErrorAndFinish(
BackgroundFetchStorageError::kServiceWorkerStorageError);
return;
}
for (auto& observer : data_manager()->observers()) {
observer.OnRegistrationCreated(registration_id_, registration, options_,
......
......@@ -5,7 +5,6 @@
#include "content/browser/background_fetch/storage/database_helpers.h"
#include "base/strings/string_number_conversions.h"
#include "content/browser/background_fetch/background_fetch.pb.h"
#include "third_party/blink/public/platform/modules/background_fetch/background_fetch.mojom.h"
namespace content {
......@@ -89,31 +88,76 @@ DatabaseStatus ToDatabaseStatus(blink::ServiceWorkerStatusCode status) {
return DatabaseStatus::kFailed;
}
BackgroundFetchRegistration ToBackgroundFetchRegistration(
const proto::BackgroundFetchMetadata& metadata_proto) {
bool ToBackgroundFetchRegistration(
const proto::BackgroundFetchMetadata& metadata_proto,
BackgroundFetchRegistration* registration) {
DCHECK(registration);
const auto& registration_proto = metadata_proto.registration();
BackgroundFetchRegistration registration;
registration.developer_id = registration_proto.developer_id();
registration.unique_id = registration_proto.unique_id();
registration.upload_total = registration_proto.upload_total();
registration.uploaded = registration_proto.uploaded();
registration.download_total = registration_proto.download_total();
registration.downloaded = registration_proto.downloaded();
registration->developer_id = registration_proto.developer_id();
registration->unique_id = registration_proto.unique_id();
registration->upload_total = registration_proto.upload_total();
registration->uploaded = registration_proto.uploaded();
registration->download_total = registration_proto.download_total();
registration->downloaded = registration_proto.downloaded();
switch (registration_proto.state()) {
case proto::BackgroundFetchRegistration_BackgroundFetchState_PENDING:
registration.state = blink::mojom::BackgroundFetchState::PENDING;
registration->state = blink::mojom::BackgroundFetchState::PENDING;
break;
case proto::BackgroundFetchRegistration_BackgroundFetchState_FAILURE:
registration.state = blink::mojom::BackgroundFetchState::FAILURE;
registration->state = blink::mojom::BackgroundFetchState::FAILURE;
break;
case proto::BackgroundFetchRegistration_BackgroundFetchState_SUCCESS:
registration.state = blink::mojom::BackgroundFetchState::SUCCESS;
registration->state = blink::mojom::BackgroundFetchState::SUCCESS;
break;
default:
NOTREACHED();
}
return registration;
bool did_convert = MojoFailureReasonFromRegistrationProto(
registration_proto.failure_reason(), &registration->failure_reason);
return did_convert;
}
bool MojoFailureReasonFromRegistrationProto(
proto::BackgroundFetchRegistration::BackgroundFetchFailureReason
proto_failure_reason,
blink::mojom::BackgroundFetchFailureReason* failure_reason) {
DCHECK(failure_reason);
switch (proto_failure_reason) {
case proto::BackgroundFetchRegistration::NONE:
*failure_reason = blink::mojom::BackgroundFetchFailureReason::NONE;
return true;
case proto::BackgroundFetchRegistration::CANCELLED_FROM_UI:
*failure_reason =
blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI;
return true;
case proto::BackgroundFetchRegistration::CANCELLED_BY_DEVELOPER:
*failure_reason =
blink::mojom::BackgroundFetchFailureReason::CANCELLED_BY_DEVELOPER;
return true;
case proto::BackgroundFetchRegistration::SERVICE_WORKER_UNAVAILABLE:
*failure_reason = blink::mojom::BackgroundFetchFailureReason::
SERVICE_WORKER_UNAVAILABLE;
return true;
case proto::BackgroundFetchRegistration::QUOTA_EXCEEDED:
*failure_reason =
blink::mojom::BackgroundFetchFailureReason::QUOTA_EXCEEDED;
return true;
case proto::BackgroundFetchRegistration::TOTAL_DOWNLOAD_SIZE_EXCEEDED:
*failure_reason = blink::mojom::BackgroundFetchFailureReason::
TOTAL_DOWNLOAD_SIZE_EXCEEDED;
return true;
case proto::BackgroundFetchRegistration::FETCH_ERROR:
*failure_reason = blink::mojom::BackgroundFetchFailureReason::FETCH_ERROR;
return true;
case proto::BackgroundFetchRegistration::BAD_STATUS:
*failure_reason = blink::mojom::BackgroundFetchFailureReason::BAD_STATUS;
return true;
}
LOG(ERROR) << "BackgroundFetchFailureReason from the metadata proto doesn't"
<< " match any enum value. Possible database corruption.";
return false;
}
} // namespace background_fetch
......
......@@ -7,17 +7,15 @@
#include <string>
#include "content/browser/background_fetch/background_fetch.pb.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/background_fetch_delegate.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
namespace content {
namespace proto {
class BackgroundFetchMetadata;
}
namespace background_fetch {
// The database schema is content/browser/background_fetch/storage/README.md.
......@@ -61,8 +59,14 @@ enum class DatabaseStatus { kOk, kFailed, kNotFound };
DatabaseStatus ToDatabaseStatus(blink::ServiceWorkerStatusCode status);
// Converts the |metadata_proto| to a BackgroundFetchRegistration object.
BackgroundFetchRegistration ToBackgroundFetchRegistration(
const proto::BackgroundFetchMetadata& metadata_proto);
bool ToBackgroundFetchRegistration(
const proto::BackgroundFetchMetadata& metadata_proto,
BackgroundFetchRegistration* registration);
bool MojoFailureReasonFromRegistrationProto(
proto::BackgroundFetchRegistration_BackgroundFetchFailureReason
proto_failure_reason,
blink::mojom::BackgroundFetchFailureReason* failure_reason);
} // namespace background_fetch
......
......@@ -49,7 +49,14 @@ void GetRegistrationTask::FinishWithError(
if (error == blink::mojom::BackgroundFetchError::NONE) {
DCHECK(metadata_proto_);
registration = ToBackgroundFetchRegistration(*metadata_proto_);
bool converted =
ToBackgroundFetchRegistration(*metadata_proto_, &registration);
if (!converted) {
// Database corrupted.
SetStorageErrorAndFinish(
BackgroundFetchStorageError::kServiceWorkerStorageError);
return;
}
}
ReportStorageError();
......
......@@ -39,6 +39,7 @@ bool StructTraits<blink::mojom::BackgroundFetchRegistrationDataView,
registration->download_total = data.download_total();
registration->downloaded = data.downloaded();
registration->state = data.state();
registration->failure_reason = data.failure_reason();
return true;
}
......
......@@ -68,6 +68,10 @@ struct CONTENT_EXPORT
const content::BackgroundFetchRegistration& registration) {
return registration.state;
}
static blink::mojom::BackgroundFetchFailureReason failure_reason(
const content::BackgroundFetchRegistration& registration) {
return registration.failure_reason;
}
static bool Read(blink::mojom::BackgroundFetchRegistrationDataView data,
content::BackgroundFetchRegistration* registration);
......
......@@ -60,6 +60,8 @@ TEST(BackgroundFetchStructTraitsTest, BackgroundFetchRegistrationRoundTrip) {
registration.unique_id = "7e57ab1e-c0de-a150-ca75-1e75f005ba11";
registration.download_total = 9001;
registration.state = blink::mojom::BackgroundFetchState::FAILURE;
registration.failure_reason =
blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI;
BackgroundFetchRegistration roundtrip_registration;
ASSERT_TRUE(blink::mojom::BackgroundFetchRegistration::Deserialize(
......@@ -71,6 +73,7 @@ TEST(BackgroundFetchStructTraitsTest, BackgroundFetchRegistrationRoundTrip) {
EXPECT_EQ(roundtrip_registration.download_total, registration.download_total);
EXPECT_EQ(roundtrip_registration.state, registration.state);
EXPECT_EQ(roundtrip_registration.failure_reason, registration.failure_reason);
}
TEST(BackgroundFetchStructTraitsTest, ImageResourceRoundtrip) {
......
......@@ -29,7 +29,8 @@ BackgroundFetchOptions::BackgroundFetchOptions(
BackgroundFetchOptions::~BackgroundFetchOptions() = default;
BackgroundFetchRegistration::BackgroundFetchRegistration()
: state(blink::mojom::BackgroundFetchState::PENDING) {}
: state(blink::mojom::BackgroundFetchState::PENDING),
failure_reason(blink::mojom::BackgroundFetchFailureReason::NONE) {}
BackgroundFetchRegistration::BackgroundFetchRegistration(
const std::string& developer_id,
......@@ -38,14 +39,16 @@ BackgroundFetchRegistration::BackgroundFetchRegistration(
uint64_t uploaded,
uint64_t download_total,
uint64_t downloaded,
blink::mojom::BackgroundFetchState state)
blink::mojom::BackgroundFetchState state,
blink::mojom::BackgroundFetchFailureReason failure_reason)
: developer_id(developer_id),
unique_id(unique_id),
upload_total(upload_total),
uploaded(uploaded),
download_total(download_total),
downloaded(downloaded),
state(state) {}
state(state),
failure_reason(failure_reason) {}
BackgroundFetchRegistration::BackgroundFetchRegistration(
const BackgroundFetchRegistration& other) = default;
......
......@@ -16,6 +16,7 @@
namespace blink {
namespace mojom {
enum class BackgroundFetchFailureReason;
enum class BackgroundFetchState;
} // namespace mojom
} // namespace blink
......@@ -40,13 +41,15 @@ struct CONTENT_EXPORT BackgroundFetchOptions {
// https://wicg.github.io/background-fetch/#background-fetch-registration
struct CONTENT_EXPORT BackgroundFetchRegistration {
BackgroundFetchRegistration();
BackgroundFetchRegistration(const std::string& developer_id,
const std::string& unique_id,
uint64_t upload_total,
uint64_t uploaded,
uint64_t download_total,
uint64_t downloaded,
blink::mojom::BackgroundFetchState state);
BackgroundFetchRegistration(
const std::string& developer_id,
const std::string& unique_id,
uint64_t upload_total,
uint64_t uploaded,
uint64_t download_total,
uint64_t downloaded,
blink::mojom::BackgroundFetchState state,
blink::mojom::BackgroundFetchFailureReason failure_reason);
BackgroundFetchRegistration(const BackgroundFetchRegistration& other);
~BackgroundFetchRegistration();
......@@ -63,6 +66,7 @@ struct CONTENT_EXPORT BackgroundFetchRegistration {
uint64_t download_total = 0;
uint64_t downloaded = 0;
blink::mojom::BackgroundFetchState state;
blink::mojom::BackgroundFetchFailureReason failure_reason;
};
// Represents a request/response pair for a settled Background Fetch fetch.
......
......@@ -35,6 +35,29 @@ enum BackgroundFetchState {
SUCCESS
};
// https://wicg.github.io/background-fetch/#enumdef-backgroundfetchfailurereason
enum BackgroundFetchFailureReason {
// "":
NONE = 0,
// "aborted":
CANCELLED_FROM_UI = 1,
CANCELLED_BY_DEVELOPER = 2,
// "bad-status":
BAD_STATUS = 3,
// "fetch-error":
FETCH_ERROR = 4,
SERVICE_WORKER_UNAVAILABLE = 5,
// "quota-exceeded":
QUOTA_EXCEEDED = 6,
// "total-download-exceeded":
TOTAL_DOWNLOAD_SIZE_EXCEEDED = 7,
};
// Represents the optional options a developer can provide when starting a new
// Background Fetch fetch. Analogous to the following structure in the spec:
// https://wicg.github.io/background-fetch/#background-fetch-manager
......@@ -61,6 +84,7 @@ struct BackgroundFetchRegistration {
uint64 download_total;
uint64 downloaded;
BackgroundFetchState state;
BackgroundFetchFailureReason failure_reason;
};
interface BackgroundFetchRegistrationObserver {
......
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