Commit 78707d18 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Remove BackgroundFetchRegistration's unitialized state

BackgroundFetchRegistration does lazy initialization, but that isn't really necessary because the initialization is done right after.

Change-Id: I3b762beaed14a01d729f413d2c6ccf438affc514
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2143882Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759632}
parent 32fc8b63
......@@ -78,17 +78,17 @@ void BackgroundFetchBridge::DidGetRegistration(
RegistrationCallback callback,
mojom::blink::BackgroundFetchError error,
mojom::blink::BackgroundFetchRegistrationPtr registration_ptr) {
BackgroundFetchRegistration* registration =
registration_ptr.To<BackgroundFetchRegistration*>();
if (registration) {
DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE);
DCHECK_EQ(registration->result(), "");
registration->Initialize(
GetSupplementable(),
std::move(registration_ptr->registration_interface));
if (!registration_ptr || !registration_ptr->registration_data) {
DCHECK_NE(error, mojom::blink::BackgroundFetchError::NONE);
std::move(callback).Run(error, nullptr);
return;
}
DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE);
BackgroundFetchRegistration* registration =
MakeGarbageCollected<blink::BackgroundFetchRegistration>(
GetSupplementable(), std::move(registration_ptr));
std::move(callback).Run(error, registration);
}
......
......@@ -27,22 +27,6 @@
namespace blink {
BackgroundFetchRegistration::BackgroundFetchRegistration(
const String& developer_id,
uint64_t upload_total,
uint64_t uploaded,
uint64_t download_total,
uint64_t downloaded,
mojom::BackgroundFetchResult result,
mojom::BackgroundFetchFailureReason failure_reason)
: developer_id_(developer_id),
upload_total_(upload_total),
uploaded_(uploaded),
download_total_(download_total),
downloaded_(downloaded),
result_(result),
failure_reason_(failure_reason) {}
BackgroundFetchRegistration::BackgroundFetchRegistration(
ServiceWorkerRegistration* service_worker_registration,
mojom::blink::BackgroundFetchRegistrationPtr registration)
......@@ -54,23 +38,8 @@ BackgroundFetchRegistration::BackgroundFetchRegistration(
result_(registration->registration_data->result),
failure_reason_(registration->registration_data->failure_reason) {
DCHECK(service_worker_registration);
Initialize(service_worker_registration,
std::move(registration->registration_interface));
}
BackgroundFetchRegistration::~BackgroundFetchRegistration() = default;
void BackgroundFetchRegistration::Initialize(
ServiceWorkerRegistration* registration,
mojo::PendingRemote<mojom::blink::BackgroundFetchRegistrationService>
registration_service) {
DCHECK(!registration_);
DCHECK(registration);
DCHECK(!registration_service_);
DCHECK(registration_service);
registration_ = registration;
registration_service_.Bind(std::move(registration_service));
registration_ = service_worker_registration;
registration_service_.Bind(std::move(registration->registration_interface));
ExecutionContext* context = GetExecutionContext();
if (!context || context->IsContextDestroyed())
......@@ -81,6 +50,8 @@ void BackgroundFetchRegistration::Initialize(
observer_receiver_.BindNewPipeAndPassRemote(task_runner));
}
BackgroundFetchRegistration::~BackgroundFetchRegistration() = default;
void BackgroundFetchRegistration::OnProgress(
uint64_t upload_total,
uint64_t uploaded,
......
......@@ -37,29 +37,12 @@ class BackgroundFetchRegistration final
USING_GARBAGE_COLLECTED_MIXIN(BackgroundFetchRegistration);
public:
BackgroundFetchRegistration(
const String& developer_id,
uint64_t upload_total,
uint64_t uploaded,
uint64_t download_total,
uint64_t downloaded,
mojom::BackgroundFetchResult result,
mojom::BackgroundFetchFailureReason failure_reason);
BackgroundFetchRegistration(
ServiceWorkerRegistration* service_worker_registration,
mojom::blink::BackgroundFetchRegistrationPtr registration);
~BackgroundFetchRegistration() override;
// Initializes the BackgroundFetchRegistration to be associated with the given
// ServiceWorkerRegistration. It will register itself as an observer for
// progress events, powering the `progress` JavaScript event.
void Initialize(
ServiceWorkerRegistration* registration,
mojo::PendingRemote<mojom::blink::BackgroundFetchRegistrationService>
registration_service);
// BackgroundFetchRegistrationObserver implementation.
void OnProgress(uint64_t upload_total,
uint64_t uploaded,
......
......@@ -13,24 +13,6 @@
namespace mojo {
blink::BackgroundFetchRegistration*
TypeConverter<blink::BackgroundFetchRegistration*,
blink::mojom::blink::BackgroundFetchRegistrationPtr>::
Convert(const blink::mojom::blink::BackgroundFetchRegistrationPtr&
mojo_registration) {
if (!mojo_registration || !mojo_registration->registration_data)
return nullptr;
return blink::MakeGarbageCollected<blink::BackgroundFetchRegistration>(
mojo_registration->registration_data->developer_id,
mojo_registration->registration_data->upload_total,
mojo_registration->registration_data->uploaded,
mojo_registration->registration_data->download_total,
mojo_registration->registration_data->downloaded,
mojo_registration->registration_data->result,
mojo_registration->registration_data->failure_reason);
}
blink::mojom::blink::BackgroundFetchOptionsPtr
TypeConverter<blink::mojom::blink::BackgroundFetchOptionsPtr,
const blink::BackgroundFetchOptions*>::
......
......@@ -8,20 +8,11 @@
#include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom-blink.h"
namespace blink {
class BackgroundFetchRegistration;
class BackgroundFetchOptions;
}
namespace mojo {
template <>
struct TypeConverter<blink::BackgroundFetchRegistration*,
blink::mojom::blink::BackgroundFetchRegistrationPtr> {
static blink::BackgroundFetchRegistration* Convert(
const blink::mojom::blink::BackgroundFetchRegistrationPtr&
mojo_registration);
};
template <>
struct TypeConverter<blink::mojom::blink::BackgroundFetchOptionsPtr,
const blink::BackgroundFetchOptions*> {
......
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