Commit baef2429 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Update background fetch abort & fail dispatchers.

Update the backgroundfetchfail & backgroundfetchabort event types to
instantiate BackgroundFetchUpdateEvent & BackgroundFetchSettledEvent
respectively.
https://wicg.github.io/background-fetch/#service-worker-global-events

Bug: 822765
Change-Id: Iea5311fdbedf805ec8d4d54daca0257078dc050d
Reviewed-on: https://chromium-review.googlesource.com/1005177Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558313}
parent c2b04a4c
......@@ -244,7 +244,8 @@ void BackgroundFetchContext::DidMarkForDeletion(
CleanupRegistration(registration_id, {});
event_dispatcher_.DispatchBackgroundFetchAbortEvent(registration_id,
// TODO(rayankans): Send fetches to the event dispatcher.
event_dispatcher_.DispatchBackgroundFetchAbortEvent(registration_id, {},
base::DoNothing());
} else {
data_manager_.GetSettledFetchesForRegistration(
......@@ -263,7 +264,7 @@ void BackgroundFetchContext::DidGetSettledFetches(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (error != blink::mojom::BackgroundFetchError::NONE) {
CleanupRegistration(registration_id, {});
CleanupRegistration(registration_id, {} /* fetches */);
return;
}
......
......@@ -21,9 +21,13 @@ BackgroundFetchEmbeddedWorkerTestHelper::
void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) {
last_developer_id_ = developer_id;
last_unique_id_ = unique_id;
last_fetches_ = fetches;
if (fail_abort_event_) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED,
......@@ -59,10 +63,12 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) {
last_developer_id_ = developer_id;
last_unique_id_ = unique_id;
last_fetches_ = fetches;
if (fail_fetch_fail_event_) {
......
......@@ -68,6 +68,8 @@ class BackgroundFetchEmbeddedWorkerTestHelper
// EmbeddedWorkerTestHelper overrides:
void OnBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) override;
void OnBackgroundFetchClickEvent(
......@@ -77,6 +79,7 @@ class BackgroundFetchEmbeddedWorkerTestHelper
DispatchBackgroundFetchClickEventCallback callback) override;
void OnBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) override;
......
......@@ -76,6 +76,7 @@ BackgroundFetchEventDispatcher::~BackgroundFetchEventDispatcher() {
void BackgroundFetchEventDispatcher::DispatchBackgroundFetchAbortEvent(
const BackgroundFetchRegistrationId& registration_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
base::OnceClosure finished_closure) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
LoadServiceWorkerRegistrationForDispatch(
......@@ -83,16 +84,19 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchAbortEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchAbortEvent,
registration_id.developer_id()));
registration_id.developer_id(), registration_id.unique_id(),
fetches));
}
void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchAbortEvent(
developer_id,
developer_id, unique_id, fetches,
service_worker_version->CreateSimpleEventCallback(request_id));
}
......@@ -130,17 +134,19 @@ void BackgroundFetchEventDispatcher::DispatchBackgroundFetchFailEvent(
std::move(finished_closure),
base::Bind(
&BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchFailEvent,
registration_id.developer_id(), fetches));
registration_id.developer_id(), registration_id.unique_id(),
fetches));
}
void BackgroundFetchEventDispatcher::DoDispatchBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id) {
DCHECK(service_worker_version);
service_worker_version->event_dispatcher()->DispatchBackgroundFetchFailEvent(
developer_id, fetches,
developer_id, unique_id, fetches,
service_worker_version->CreateSimpleEventCallback(request_id));
}
......
......@@ -45,6 +45,7 @@ class CONTENT_EXPORT BackgroundFetchEventDispatcher {
// background fetch was aborted by the user or another external event.
void DispatchBackgroundFetchAbortEvent(
const BackgroundFetchRegistrationId& registration_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
base::OnceClosure finished_closure);
// Dispatches the `backgroundfetchclick` event, which indicates that the user
......@@ -113,6 +114,8 @@ class CONTENT_EXPORT BackgroundFetchEventDispatcher {
// Methods that actually invoke the event on an activated Service Worker.
static void DoDispatchBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id);
static void DoDispatchBackgroundFetchClickEvent(
......@@ -122,6 +125,7 @@ class CONTENT_EXPORT BackgroundFetchEventDispatcher {
int request_id);
static void DoDispatchBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
scoped_refptr<ServiceWorkerVersion> service_worker_version,
int request_id);
......
......@@ -44,8 +44,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchInvalidRegistration) {
kExampleUniqueId);
base::RunLoop run_loop;
event_dispatcher_.DispatchBackgroundFetchAbortEvent(invalid_registration_id,
run_loop.QuitClosure());
event_dispatcher_.DispatchBackgroundFetchAbortEvent(
invalid_registration_id, {}, run_loop.QuitClosure());
run_loop.Run();
......@@ -62,14 +62,17 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
ASSERT_NE(blink::mojom::kInvalidServiceWorkerRegistrationId,
service_worker_registration_id);
std::vector<BackgroundFetchSettledFetch> fetches;
fetches.push_back(BackgroundFetchSettledFetch());
BackgroundFetchRegistrationId registration_id(service_worker_registration_id,
origin(), kExampleDeveloperId,
kExampleUniqueId);
{
base::RunLoop run_loop;
event_dispatcher_.DispatchBackgroundFetchAbortEvent(registration_id,
run_loop.QuitClosure());
event_dispatcher_.DispatchBackgroundFetchAbortEvent(
registration_id, fetches, run_loop.QuitClosure());
run_loop.Run();
}
......@@ -77,6 +80,10 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value());
EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value());
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_fetches().has_value());
histogram_tester_.ExpectUniqueSample(
"BackgroundFetch.EventDispatchResult.AbortEvent",
......@@ -90,8 +97,8 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
{
base::RunLoop run_loop;
event_dispatcher_.DispatchBackgroundFetchAbortEvent(second_registration_id,
run_loop.QuitClosure());
event_dispatcher_.DispatchBackgroundFetchAbortEvent(
second_registration_id, fetches, run_loop.QuitClosure());
run_loop.Run();
}
......@@ -99,6 +106,10 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value());
EXPECT_EQ(kExampleDeveloperId2,
embedded_worker_test_helper()->last_developer_id().value());
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId2,
embedded_worker_test_helper()->last_unique_id().value());
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
histogram_tester_.ExpectBucketCount(
"BackgroundFetch.EventDispatchResult.AbortEvent",
......
......@@ -198,10 +198,13 @@ class EmbeddedWorkerTestHelper::MockServiceWorkerEventDispatcher
void DispatchBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchAbortEventCallback callback) override {
if (!helper_)
return;
helper_->OnBackgroundFetchAbortEventStub(developer_id, std::move(callback));
helper_->OnBackgroundFetchAbortEventStub(developer_id, unique_id, fetches,
std::move(callback));
}
void DispatchBackgroundFetchClickEvent(
......@@ -216,11 +219,12 @@ class EmbeddedWorkerTestHelper::MockServiceWorkerEventDispatcher
void DispatchBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchFailEventCallback callback) override {
if (!helper_)
return;
helper_->OnBackgroundFetchFailEventStub(developer_id, fetches,
helper_->OnBackgroundFetchFailEventStub(developer_id, unique_id, fetches,
std::move(callback));
}
......@@ -570,6 +574,8 @@ void EmbeddedWorkerTestHelper::OnActivateEvent(
void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::COMPLETED,
......@@ -587,6 +593,7 @@ void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) {
......@@ -856,12 +863,15 @@ void EmbeddedWorkerTestHelper::OnActivateEventStub(
void EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEventStub(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&EmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent,
AsWeakPtr(), developer_id, std::move(callback)));
AsWeakPtr(), developer_id, unique_id, fetches,
std::move(callback)));
}
void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEventStub(
......@@ -877,13 +887,15 @@ void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEventStub(
void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEventStub(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent,
AsWeakPtr(), developer_id, fetches, std::move(callback)));
AsWeakPtr(), developer_id, unique_id, fetches,
std::move(callback)));
}
void EmbeddedWorkerTestHelper::OnBackgroundFetchedEventStub(
......
......@@ -197,6 +197,8 @@ class EmbeddedWorkerTestHelper : public IPC::Sender,
callback);
virtual void OnBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback);
virtual void OnBackgroundFetchClickEvent(
......@@ -206,6 +208,7 @@ class EmbeddedWorkerTestHelper : public IPC::Sender,
DispatchBackgroundFetchClickEventCallback callback);
virtual void OnBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback);
......@@ -295,6 +298,8 @@ class EmbeddedWorkerTestHelper : public IPC::Sender,
callback);
void OnBackgroundFetchAbortEventStub(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchAbortEventCallback callback);
void OnBackgroundFetchClickEventStub(
......@@ -304,6 +309,7 @@ class EmbeddedWorkerTestHelper : public IPC::Sender,
DispatchBackgroundFetchClickEventCallback callback);
void OnBackgroundFetchFailEventStub(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorkerEventDispatcher::
DispatchBackgroundFetchFailEventCallback callback);
......
......@@ -89,7 +89,9 @@ interface ServiceWorkerEventDispatcher {
// The callbacks are called once the event handler has run and waitUntil()
// promise has settled. |developer_id| and |unique_id| are documented in
// content::BackgroundFetchRegistrationId.
DispatchBackgroundFetchAbortEvent(string developer_id)
DispatchBackgroundFetchAbortEvent(string developer_id,
string unique_id,
array<BackgroundFetchSettledFetch> fetches)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchBackgroundFetchClickEvent(string developer_id,
......@@ -97,6 +99,7 @@ interface ServiceWorkerEventDispatcher {
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
DispatchBackgroundFetchFailEvent(string developer_id,
string unique_id,
array<BackgroundFetchSettledFetch> fetches)
=> (blink.mojom.ServiceWorkerEventStatus status,
mojo_base.mojom.Time dispatch_event_time);
......
......@@ -1366,6 +1366,8 @@ void ServiceWorkerContextClient::DispatchActivateEvent(
void ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchAbortEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent");
......@@ -1373,8 +1375,17 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchAbortEvent(
CreateAbortCallback(&context_->background_fetch_abort_event_callbacks));
context_->background_fetch_abort_event_callbacks.emplace(request_id,
std::move(callback));
blink::WebVector<blink::WebBackgroundFetchSettledFetch> web_fetches(
fetches.size());
for (size_t i = 0; i < fetches.size(); ++i) {
ToWebServiceWorkerRequest(fetches[i].request, &web_fetches[i].request);
ToWebServiceWorkerResponse(fetches[i].response, &web_fetches[i].response);
}
proxy_->DispatchBackgroundFetchAbortEvent(
request_id, blink::WebString::FromUTF8(developer_id));
request_id, blink::WebString::FromUTF8(developer_id),
blink::WebString::FromUTF8(unique_id), web_fetches);
}
void ServiceWorkerContextClient::DispatchBackgroundFetchClickEvent(
......@@ -1398,6 +1409,7 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchClickEvent(
void ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchFailEventCallback callback) {
TRACE_EVENT0("ServiceWorker",
......@@ -1415,7 +1427,8 @@ void ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent(
}
proxy_->DispatchBackgroundFetchFailEvent(
request_id, blink::WebString::FromUTF8(developer_id), web_fetches);
request_id, blink::WebString::FromUTF8(developer_id),
blink::WebString::FromUTF8(unique_id), web_fetches);
}
void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
......
......@@ -281,6 +281,8 @@ class CONTENT_EXPORT ServiceWorkerContextClient
void DispatchActivateEvent(DispatchActivateEventCallback callback) override;
void DispatchBackgroundFetchAbortEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchAbortEventCallback callback) override;
void DispatchBackgroundFetchClickEvent(
const std::string& developer_id,
......@@ -288,6 +290,7 @@ class CONTENT_EXPORT ServiceWorkerContextClient
DispatchBackgroundFetchClickEventCallback callback) override;
void DispatchBackgroundFetchFailEvent(
const std::string& developer_id,
const std::string& unique_id,
const std::vector<BackgroundFetchSettledFetch>& fetches,
DispatchBackgroundFetchFailEventCallback callback) override;
void DispatchBackgroundFetchedEvent(
......
......@@ -77,7 +77,10 @@ class MockWebServiceWorkerContextProxy
void DispatchActivateEvent(int event_id) override { NOTREACHED(); }
void DispatchBackgroundFetchAbortEvent(
int event_id,
const blink::WebString& developer_id) override {
const blink::WebString& developer_id,
const blink::WebString& unique_id,
const blink::WebVector<blink::WebBackgroundFetchSettledFetch>& fetches)
override {
NOTREACHED();
}
void DispatchBackgroundFetchClickEvent(int event_id,
......@@ -88,6 +91,7 @@ class MockWebServiceWorkerContextProxy
void DispatchBackgroundFetchFailEvent(
int event_id,
const blink::WebString& developer_id,
const blink::WebString& unique_id,
const blink::WebVector<blink::WebBackgroundFetchSettledFetch>& fetches)
override {
NOTREACHED();
......
......@@ -70,7 +70,9 @@ class WebServiceWorkerContextProxy {
virtual void DispatchBackgroundFetchAbortEvent(
int event_id,
const WebString& developer_id) = 0;
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) = 0;
virtual void DispatchBackgroundFetchClickEvent(
int event_id,
const WebString& developer_id,
......@@ -78,6 +80,7 @@ class WebServiceWorkerContextProxy {
virtual void DispatchBackgroundFetchFailEvent(
int event_id,
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) = 0;
virtual void DispatchBackgroundFetchedEvent(
int event_id,
......
......@@ -9,8 +9,16 @@ namespace blink {
BackgroundFetchSettledEvent::BackgroundFetchSettledEvent(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer,
const String& unique_id,
WaitUntilObserver* observer)
: BackgroundFetchEvent(type, initializer, observer),
unique_id_(unique_id),
fetches_(*initializer.fetches()) {}
BackgroundFetchSettledEvent::BackgroundFetchSettledEvent(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer)
: BackgroundFetchEvent(type, initializer, nullptr),
fetches_(*initializer.fetches()) {}
BackgroundFetchSettledEvent::~BackgroundFetchSettledEvent() = default;
......
......@@ -26,6 +26,15 @@ class MODULES_EXPORT BackgroundFetchSettledEvent : public BackgroundFetchEvent {
return new BackgroundFetchSettledEvent(type, initializer);
}
static BackgroundFetchSettledEvent* Create(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer,
const String& unique_id,
WaitUntilObserver* observer = nullptr) {
return new BackgroundFetchSettledEvent(type, initializer, unique_id,
observer);
}
~BackgroundFetchSettledEvent() override;
// Web Exposed attribute defined in the IDL file.
......@@ -37,8 +46,18 @@ class MODULES_EXPORT BackgroundFetchSettledEvent : public BackgroundFetchEvent {
BackgroundFetchSettledEvent(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer,
const String& unique_id,
WaitUntilObserver* observer = nullptr);
BackgroundFetchSettledEvent(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer);
// Globally unique ID for the registration, generated in content/. Used to
// distinguish registrations in case a developer re-uses |developer_id_|s. Not
// exposed to JavaScript.
String unique_id_;
private:
Member<BackgroundFetchSettledFetches> fetches_;
};
......
......@@ -29,9 +29,8 @@ BackgroundFetchUpdateEvent::BackgroundFetchUpdateEvent(
ScriptState* script_state,
WaitUntilObserver* observer,
ServiceWorkerRegistration* registration)
: BackgroundFetchSettledEvent(type, initializer, observer),
registration_(registration),
unique_id_(unique_id) {}
: BackgroundFetchSettledEvent(type, initializer, unique_id, observer),
registration_(registration) {}
BackgroundFetchUpdateEvent::~BackgroundFetchUpdateEvent() = default;
......
......@@ -45,6 +45,7 @@ class MODULES_EXPORT BackgroundFetchUpdateEvent final
BackgroundFetchUpdateEvent(
const AtomicString& type,
const BackgroundFetchSettledEventInit& initializer);
BackgroundFetchUpdateEvent(const AtomicString& type,
const BackgroundFetchSettledEventInit&,
const String& unique_id,
......@@ -56,11 +57,6 @@ class MODULES_EXPORT BackgroundFetchUpdateEvent final
mojom::blink::BackgroundFetchError error);
Member<ServiceWorkerRegistration> registration_;
// Globally unique ID for the registration, generated in content/. Used to
// distinguish registrations in case a developer re-uses |developer_id_|s. Not
// exposed to JavaScript.
String unique_id_;
};
} // namespace blink
......
......@@ -139,16 +139,22 @@ void ServiceWorkerGlobalScopeProxy::SetRegistration(
void ServiceWorkerGlobalScopeProxy::DispatchBackgroundFetchAbortEvent(
int event_id,
const WebString& developer_id) {
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) {
DCHECK(WorkerGlobalScope()->IsContextThread());
WaitUntilObserver* observer = WaitUntilObserver::Create(
WorkerGlobalScope(), WaitUntilObserver::kBackgroundFetchAbort, event_id);
BackgroundFetchClickEventInit init;
ScriptState* script_state =
WorkerGlobalScope()->ScriptController()->GetScriptState();
BackgroundFetchSettledEventInit init;
init.setId(developer_id);
init.setFetches(BackgroundFetchSettledFetches::Create(script_state, fetches));
BackgroundFetchEvent* event = BackgroundFetchEvent::Create(
EventTypeNames::backgroundfetchabort, init, observer);
BackgroundFetchSettledEvent* event = BackgroundFetchSettledEvent::Create(
EventTypeNames::backgroundfetchabort, init, unique_id, observer);
WorkerGlobalScope()->DispatchExtendableEvent(event, observer);
}
......@@ -185,21 +191,22 @@ void ServiceWorkerGlobalScopeProxy::DispatchBackgroundFetchClickEvent(
void ServiceWorkerGlobalScopeProxy::DispatchBackgroundFetchFailEvent(
int event_id,
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) {
DCHECK(WorkerGlobalScope()->IsContextThread());
WaitUntilObserver* observer = WaitUntilObserver::Create(
WorkerGlobalScope(), WaitUntilObserver::kBackgroundFetchFail, event_id);
BackgroundFetchFailEventInit init;
init.setId(developer_id);
ScriptState* script_state =
WorkerGlobalScope()->ScriptController()->GetScriptState();
ScriptState::Scope scope(script_state);
BackgroundFetchFailEvent* event =
BackgroundFetchFailEvent::Create(EventTypeNames::backgroundfetchfail,
init, fetches, script_state, observer);
BackgroundFetchSettledEventInit init;
init.setId(developer_id);
init.setFetches(BackgroundFetchSettledFetches::Create(script_state, fetches));
BackgroundFetchUpdateEvent* event = BackgroundFetchUpdateEvent::Create(
EventTypeNames::backgroundfetched, init, unique_id, script_state,
observer, worker_global_scope_->registration());
WorkerGlobalScope()->DispatchExtendableEvent(event, observer);
}
......
......@@ -83,13 +83,16 @@ class ServiceWorkerGlobalScopeProxy final
void DispatchActivateEvent(int) override;
void DispatchBackgroundFetchAbortEvent(
int event_id,
const WebString& developer_id) override;
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) override;
void DispatchBackgroundFetchClickEvent(int event_id,
const WebString& developer_id,
BackgroundFetchState) override;
void DispatchBackgroundFetchFailEvent(
int event_id,
const WebString& developer_id,
const WebString& unique_id,
const WebVector<WebBackgroundFetchSettledFetch>& fetches) override;
void DispatchBackgroundFetchedEvent(
int event_id,
......
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