Commit 3226ce85 authored by peter's avatar peter Committed by Commit bot

Implement a Mojo service for Background Fetch

This CL lands the Mojo service that we intend to use for Background
Fetch. Everything but the fetch() event has been hooked up from the
renderer side, and will be received by a strongly binded service
implementation in the browser process.

The fetch() function will be implemented separately, as it will require
some plumbing to support the appropriate types for requests.

BUG=692534, 692535

Review-Url: https://codereview.chromium.org/2745243002
Cr-Commit-Position: refs/heads/master@{#457490}
parent d2ff1ae2
...@@ -334,6 +334,8 @@ source_set("browser") { ...@@ -334,6 +334,8 @@ source_set("browser") {
"background_fetch/background_fetch_job_info.h", "background_fetch/background_fetch_job_info.h",
"background_fetch/background_fetch_request_info.cc", "background_fetch/background_fetch_request_info.cc",
"background_fetch/background_fetch_request_info.h", "background_fetch/background_fetch_request_info.h",
"background_fetch/background_fetch_service_impl.cc",
"background_fetch/background_fetch_service_impl.h",
"background_sync/background_sync_context.cc", "background_sync/background_sync_context.cc",
"background_sync/background_sync_context.h", "background_sync/background_sync_context.h",
"background_sync/background_sync_manager.cc", "background_sync/background_sync_manager.cc",
......
include_rules = [
"+third_party/WebKit/public/platform/modules/background_fetch/background_fetch.mojom.h",
]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "content/browser/background_fetch/background_fetch_context.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace content {
// static
void BackgroundFetchServiceImpl::Create(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>(
std::move(background_fetch_context),
std::move(service_worker_context)),
std::move(request));
}
BackgroundFetchServiceImpl::BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: background_fetch_context_(std::move(background_fetch_context)),
service_worker_context_(std::move(service_worker_context)) {
DCHECK(background_fetch_context_);
DCHECK(service_worker_context_);
}
BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default;
void BackgroundFetchServiceImpl::UpdateUI(
int64_t service_worker_registration_id,
const std::string& tag,
const std::string& title,
const UpdateUICallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(peter): Get the BackgroundFetchJobController for the
// {service_worker_registration_id, tag} pair and call UpdateUI() on it.
callback.Run(blink::mojom::BackgroundFetchError::NONE);
}
void BackgroundFetchServiceImpl::Abort(int64_t service_worker_registration_id,
const std::string& tag) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(peter): Get the BackgroundFetchJobController for the
// {service_worker_registration_id, tag} pair and call Abort() on it.
}
void BackgroundFetchServiceImpl::GetRegistration(
int64_t service_worker_registration_id,
const std::string& tag,
const GetRegistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(peter): Get the registration for {service_worker_registration_id, tag}
// and construct a BackgroundFetchRegistrationPtr for it.
callback.Run(blink::mojom::BackgroundFetchError::NONE,
nullptr /* registration */);
}
void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id,
const GetTagsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(peter): Get the list of active Background Fetches associated with
// service_worker_registration_id and share their tags.
callback.Run(blink::mojom::BackgroundFetchError::NONE,
std::vector<std::string>());
}
} // namespace content
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_SERVICE_IMPL_H_
#define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_SERVICE_IMPL_H_
#include <string>
#include <utility>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "third_party/WebKit/public/platform/modules/background_fetch/background_fetch.mojom.h"
namespace content {
class BackgroundFetchContext;
class ServiceWorkerContextWrapper;
class BackgroundFetchServiceImpl : public blink::mojom::BackgroundFetchService {
public:
BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
~BackgroundFetchServiceImpl() override;
static void Create(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
blink::mojom::BackgroundFetchServiceRequest request);
// blink::mojom::BackgroundFetchService implementation.
void UpdateUI(int64_t service_worker_registration_id,
const std::string& tag,
const std::string& title,
const UpdateUICallback& callback) override;
void Abort(int64_t service_worker_registration_id,
const std::string& tag) override;
void GetRegistration(int64_t service_worker_registration_id,
const std::string& tag,
const GetRegistrationCallback& callback) override;
void GetTags(int64_t service_worker_registration_id,
const GetTagsCallback& callback) override;
private:
scoped_refptr<BackgroundFetchContext> background_fetch_context_;
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchServiceImpl);
};
} // namespace content
#endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_SERVICE_IMPL_H_
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "components/tracing/common/tracing_switches.h" #include "components/tracing/common/tracing_switches.h"
#include "content/browser/appcache/appcache_dispatcher_host.h" #include "content/browser/appcache/appcache_dispatcher_host.h"
#include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "content/browser/background_sync/background_sync_service_impl.h" #include "content/browser/background_sync/background_sync_service_impl.h"
#include "content/browser/bad_message.h" #include "content/browser/bad_message.h"
#include "content/browser/blob_storage/blob_dispatcher_host.h" #include "content/browser/blob_storage/blob_dispatcher_host.h"
...@@ -1315,6 +1316,11 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -1315,6 +1316,11 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::Bind(&PushMessagingManager::BindRequest, base::Bind(&PushMessagingManager::BindRequest,
base::Unretained(push_messaging_manager_.get()))); base::Unretained(push_messaging_manager_.get())));
registry->AddInterface(base::Bind(
&BackgroundFetchServiceImpl::Create,
make_scoped_refptr(storage_partition_impl_->GetBackgroundFetchContext()),
make_scoped_refptr(storage_partition_impl_->GetServiceWorkerContext())));
registry->AddInterface(base::Bind(&RenderProcessHostImpl::CreateMusGpuRequest, registry->AddInterface(base::Bind(&RenderProcessHostImpl::CreateMusGpuRequest,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -398,6 +398,9 @@ StoragePartitionImpl::~StoragePartitionImpl() { ...@@ -398,6 +398,9 @@ StoragePartitionImpl::~StoragePartitionImpl() {
if (GetPlatformNotificationContext()) if (GetPlatformNotificationContext())
GetPlatformNotificationContext()->Shutdown(); GetPlatformNotificationContext()->Shutdown();
if (GetBackgroundFetchContext())
GetBackgroundFetchContext()->Shutdown();
if (GetBackgroundSyncContext()) if (GetBackgroundSyncContext())
GetBackgroundSyncContext()->Shutdown(); GetBackgroundSyncContext()->Shutdown();
...@@ -489,6 +492,9 @@ std::unique_ptr<StoragePartitionImpl> StoragePartitionImpl::Create( ...@@ -489,6 +492,9 @@ std::unique_ptr<StoragePartitionImpl> StoragePartitionImpl::Create(
partition->service_worker_context_); partition->service_worker_context_);
partition->platform_notification_context_->Initialize(); partition->platform_notification_context_->Initialize();
partition->background_fetch_context_ = new BackgroundFetchContext(
context, partition.get(), partition->service_worker_context_);
partition->background_sync_context_ = new BackgroundSyncContext(); partition->background_sync_context_ = new BackgroundSyncContext();
partition->background_sync_context_->Init(partition->service_worker_context_); partition->background_sync_context_->Init(partition->service_worker_context_);
...@@ -566,6 +572,10 @@ StoragePartitionImpl::GetPlatformNotificationContext() { ...@@ -566,6 +572,10 @@ StoragePartitionImpl::GetPlatformNotificationContext() {
return platform_notification_context_.get(); return platform_notification_context_.get();
} }
BackgroundFetchContext* StoragePartitionImpl::GetBackgroundFetchContext() {
return background_fetch_context_.get();
}
BackgroundSyncContext* StoragePartitionImpl::GetBackgroundSyncContext() { BackgroundSyncContext* StoragePartitionImpl::GetBackgroundSyncContext() {
return background_sync_context_.get(); return background_sync_context_.get();
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/background_fetch/background_fetch_context.h"
#include "content/browser/background_sync/background_sync_context.h" #include "content/browser/background_sync/background_sync_context.h"
#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
#include "content/browser/broadcast_channel/broadcast_channel_provider.h" #include "content/browser/broadcast_channel/broadcast_channel_provider.h"
...@@ -78,6 +79,7 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -78,6 +79,7 @@ class CONTENT_EXPORT StoragePartitionImpl
PlatformNotificationContextImpl* GetPlatformNotificationContext() override; PlatformNotificationContextImpl* GetPlatformNotificationContext() override;
void ClearBluetoothAllowedDevicesMapForTesting() override; void ClearBluetoothAllowedDevicesMapForTesting() override;
BackgroundFetchContext* GetBackgroundFetchContext();
BackgroundSyncContext* GetBackgroundSyncContext(); BackgroundSyncContext* GetBackgroundSyncContext();
PaymentAppContextImpl* GetPaymentAppContext(); PaymentAppContextImpl* GetPaymentAppContext();
BroadcastChannelProvider* GetBroadcastChannelProvider(); BroadcastChannelProvider* GetBroadcastChannelProvider();
...@@ -220,6 +222,7 @@ class CONTENT_EXPORT StoragePartitionImpl ...@@ -220,6 +222,7 @@ class CONTENT_EXPORT StoragePartitionImpl
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
scoped_refptr<HostZoomLevelContext> host_zoom_level_context_; scoped_refptr<HostZoomLevelContext> host_zoom_level_context_;
scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_; scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_;
scoped_refptr<BackgroundFetchContext> background_fetch_context_;
scoped_refptr<BackgroundSyncContext> background_sync_context_; scoped_refptr<BackgroundSyncContext> background_sync_context_;
scoped_refptr<PaymentAppContextImpl> payment_app_context_; scoped_refptr<PaymentAppContextImpl> payment_app_context_;
scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider_; scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"ui::mojom::Gpu" "ui::mojom::Gpu"
], ],
"renderer": [ "renderer": [
"blink::mojom::BackgroundFetchService",
"blink::mojom::BackgroundSyncService", "blink::mojom::BackgroundSyncService",
"blink::mojom::BroadcastChannelProvider", "blink::mojom::BroadcastChannelProvider",
"blink::mojom::BudgetService", "blink::mojom::BudgetService",
......
...@@ -6,6 +6,8 @@ import("//third_party/WebKit/Source/modules/modules.gni") ...@@ -6,6 +6,8 @@ import("//third_party/WebKit/Source/modules/modules.gni")
blink_modules_sources("background_fetch") { blink_modules_sources("background_fetch") {
sources = [ sources = [
"BackgroundFetchBridge.cpp",
"BackgroundFetchBridge.h",
"BackgroundFetchClickEvent.cpp", "BackgroundFetchClickEvent.cpp",
"BackgroundFetchClickEvent.h", "BackgroundFetchClickEvent.h",
"BackgroundFetchEvent.cpp", "BackgroundFetchEvent.cpp",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modules/background_fetch/BackgroundFetchBridge.h"
#include <utility>
#include "modules/background_fetch/BackgroundFetchOptions.h"
#include "modules/background_fetch/BackgroundFetchRegistration.h"
#include "modules/background_fetch/IconDefinition.h"
#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
namespace blink {
namespace {
// Creates a new BackgroundFetchRegistration instance given a Service Worker
// Registration and a Mojo BackgroundFetchRegistrationPtr instance.
BackgroundFetchRegistration* CreateBackgroundFetchRegistration(
ServiceWorkerRegistration* serviceWorkerRegistration,
mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
HeapVector<IconDefinition> icons;
for (const auto& iconPtr : registrationPtr->icons) {
IconDefinition icon;
icon.setSrc(iconPtr->src);
icon.setSizes(iconPtr->sizes);
icon.setType(iconPtr->type);
icons.push_back(icon);
}
return new BackgroundFetchRegistration(
serviceWorkerRegistration, registrationPtr->tag, std::move(icons),
registrationPtr->total_download_size, registrationPtr->title);
}
} // namespace
// static
BackgroundFetchBridge* BackgroundFetchBridge::from(
ServiceWorkerRegistration* serviceWorkerRegistration) {
DCHECK(serviceWorkerRegistration);
BackgroundFetchBridge* bridge = static_cast<BackgroundFetchBridge*>(
Supplement<ServiceWorkerRegistration>::from(serviceWorkerRegistration,
supplementName()));
if (!bridge) {
bridge = new BackgroundFetchBridge(*serviceWorkerRegistration);
Supplement<ServiceWorkerRegistration>::provideTo(*serviceWorkerRegistration,
supplementName(), bridge);
}
return bridge;
}
// static
const char* BackgroundFetchBridge::supplementName() {
return "BackgroundFetchBridge";
}
BackgroundFetchBridge::BackgroundFetchBridge(
ServiceWorkerRegistration& registration)
: Supplement<ServiceWorkerRegistration>(registration) {}
BackgroundFetchBridge::~BackgroundFetchBridge() = default;
void BackgroundFetchBridge::abort(const String& tag) {
getService()->Abort(supplementable()->webRegistration()->registrationId(),
tag);
}
void BackgroundFetchBridge::updateUI(
const String& tag,
const String& title,
std::unique_ptr<UpdateUICallback> callback) {
getService()->UpdateUI(supplementable()->webRegistration()->registrationId(),
tag, title,
convertToBaseCallback(std::move(callback)));
}
void BackgroundFetchBridge::getRegistration(
const String& tag,
std::unique_ptr<GetRegistrationCallback> callback) {
getService()->GetRegistration(
supplementable()->webRegistration()->registrationId(), tag,
convertToBaseCallback(
WTF::bind(&BackgroundFetchBridge::didGetRegistration,
wrapPersistent(this), WTF::passed(std::move(callback)))));
}
void BackgroundFetchBridge::didGetRegistration(
std::unique_ptr<GetRegistrationCallback> callback,
mojom::blink::BackgroundFetchError error,
mojom::blink::BackgroundFetchRegistrationPtr registrationPtr) {
BackgroundFetchRegistration* registration = nullptr;
if (registrationPtr) {
DCHECK_EQ(error, mojom::blink::BackgroundFetchError::NONE);
registration = CreateBackgroundFetchRegistration(
supplementable(), std::move(registrationPtr));
}
(*callback)(error, registration);
}
void BackgroundFetchBridge::getTags(std::unique_ptr<GetTagsCallback> callback) {
getService()->GetTags(supplementable()->webRegistration()->registrationId(),
convertToBaseCallback(std::move(callback)));
}
mojom::blink::BackgroundFetchServicePtr& BackgroundFetchBridge::getService() {
if (!m_backgroundFetchService) {
Platform::current()->interfaceProvider()->getInterface(
mojo::MakeRequest(&m_backgroundFetchService));
}
return m_backgroundFetchService;
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BackgroundFetchBridge_h
#define BackgroundFetchBridge_h
#include <memory>
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "public/platform/modules/background_fetch/background_fetch.mojom-blink.h"
#include "wtf/Functional.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace blink {
class BackgroundFetchRegistration;
// The bridge is responsible for establishing and maintaining the Mojo
// connection to the BackgroundFetchService. It's keyed on an active Service
// Worker Registration.
class BackgroundFetchBridge final
: public GarbageCollectedFinalized<BackgroundFetchBridge>,
public Supplement<ServiceWorkerRegistration> {
USING_GARBAGE_COLLECTED_MIXIN(BackgroundFetchBridge);
WTF_MAKE_NONCOPYABLE(BackgroundFetchBridge);
public:
using UpdateUICallback = Function<void(mojom::blink::BackgroundFetchError)>;
using GetRegistrationCallback =
Function<void(mojom::blink::BackgroundFetchError,
BackgroundFetchRegistration*)>;
using GetTagsCallback =
Function<void(mojom::blink::BackgroundFetchError, const Vector<String>&)>;
static BackgroundFetchBridge* from(ServiceWorkerRegistration*);
static const char* supplementName();
virtual ~BackgroundFetchBridge();
// TODO(peter): Implement support for the `fetch()` function in the bridge.
// Updates the user interface for the Background Fetch identified by |tag|
// with the updated |title|. Will invoke the |callback| when the interface
// has been requested to update.
void updateUI(const String& tag,
const String& title,
std::unique_ptr<UpdateUICallback>);
// Aborts the active Background Fetch for |tag|. Does not respond.
void abort(const String& tag);
// Gets the Background Fetch registration for the given |tag|. Will invoke the
// |callback| with the Background Fetch registration, which may be a nullptr
// if the |tag| does not exist, when the Mojo call has completed.
void getRegistration(const String& tag,
std::unique_ptr<GetRegistrationCallback>);
// Gets the sequence of tags for active Background Fetch registrations. Will
// invoke the |callback| with the tags when the Mojo call has completed.
void getTags(std::unique_ptr<GetTagsCallback>);
private:
explicit BackgroundFetchBridge(ServiceWorkerRegistration&);
// Returns an initialized BackgroundFetchServicePtr. A connection will be
// established after the first call to this method.
mojom::blink::BackgroundFetchServicePtr& getService();
void didGetRegistration(std::unique_ptr<GetRegistrationCallback>,
mojom::blink::BackgroundFetchError,
mojom::blink::BackgroundFetchRegistrationPtr);
mojom::blink::BackgroundFetchServicePtr m_backgroundFetchService;
};
} // namespace blink
#endif // BackgroundFetchBridge_h
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "bindings/core/v8/ScriptPromiseResolver.h" #include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h" #include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/V8ThrowException.h" #include "bindings/core/v8/V8ThrowException.h"
#include "modules/background_fetch/BackgroundFetchBridge.h"
#include "modules/background_fetch/BackgroundFetchOptions.h" #include "modules/background_fetch/BackgroundFetchOptions.h"
#include "modules/background_fetch/BackgroundFetchRegistration.h" #include "modules/background_fetch/BackgroundFetchRegistration.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h" #include "modules/serviceworkers/ServiceWorkerRegistration.h"
...@@ -17,11 +18,12 @@ BackgroundFetchManager::BackgroundFetchManager( ...@@ -17,11 +18,12 @@ BackgroundFetchManager::BackgroundFetchManager(
ServiceWorkerRegistration* registration) ServiceWorkerRegistration* registration)
: m_registration(registration) { : m_registration(registration) {
DCHECK(registration); DCHECK(registration);
m_bridge = BackgroundFetchBridge::from(m_registration);
} }
ScriptPromise BackgroundFetchManager::fetch( ScriptPromise BackgroundFetchManager::fetch(
ScriptState* scriptState, ScriptState* scriptState,
String tag, const String& tag,
const RequestOrUSVStringOrRequestOrUSVStringSequence& requests, const RequestOrUSVStringOrRequestOrUSVStringSequence& requests,
const BackgroundFetchOptions& options) { const BackgroundFetchOptions& options) {
if (!m_registration->active()) { if (!m_registration->active()) {
...@@ -48,7 +50,7 @@ ScriptPromise BackgroundFetchManager::fetch( ...@@ -48,7 +50,7 @@ ScriptPromise BackgroundFetchManager::fetch(
} }
ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState, ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState,
String tag) { const String& tag) {
if (!m_registration->active()) { if (!m_registration->active()) {
return ScriptPromise::reject( return ScriptPromise::reject(
scriptState, scriptState,
...@@ -60,13 +62,29 @@ ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState, ...@@ -60,13 +62,29 @@ ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState,
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise(); ScriptPromise promise = resolver->promise();
// TODO(peter): Get the background fetch registration for `tag` from the m_bridge->getRegistration(
// browser process. There may not be one. tag, WTF::bind(&BackgroundFetchManager::didGetRegistration,
resolver->resolve(v8::Null(scriptState->isolate())); wrapPersistent(this), wrapPersistent(resolver)));
return promise; return promise;
} }
void BackgroundFetchManager::didGetRegistration(
ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error,
BackgroundFetchRegistration* registration) {
switch (error) {
case mojom::blink::BackgroundFetchError::NONE:
resolver->resolve(registration);
return;
case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
// Not applicable for this callback.
break;
}
NOTREACHED();
}
ScriptPromise BackgroundFetchManager::getTags(ScriptState* scriptState) { ScriptPromise BackgroundFetchManager::getTags(ScriptState* scriptState) {
if (!m_registration->active()) { if (!m_registration->active()) {
return ScriptPromise::reject( return ScriptPromise::reject(
...@@ -79,14 +97,31 @@ ScriptPromise BackgroundFetchManager::getTags(ScriptState* scriptState) { ...@@ -79,14 +97,31 @@ ScriptPromise BackgroundFetchManager::getTags(ScriptState* scriptState) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise(); ScriptPromise promise = resolver->promise();
// TODO(peter): Get a list of tags from the browser process. m_bridge->getTags(WTF::bind(&BackgroundFetchManager::didGetTags,
resolver->resolve(Vector<String>()); wrapPersistent(this), wrapPersistent(resolver)));
return promise; return promise;
} }
void BackgroundFetchManager::didGetTags(
ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error,
const Vector<String>& tags) {
switch (error) {
case mojom::blink::BackgroundFetchError::NONE:
resolver->resolve(tags);
return;
case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
// Not applicable for this callback.
break;
}
NOTREACHED();
}
DEFINE_TRACE(BackgroundFetchManager) { DEFINE_TRACE(BackgroundFetchManager) {
visitor->trace(m_registration); visitor->trace(m_registration);
visitor->trace(m_bridge);
} }
} // namespace blink } // namespace blink
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
#include "bindings/core/v8/ScriptWrappable.h" #include "bindings/core/v8/ScriptWrappable.h"
#include "platform/heap/GarbageCollected.h" #include "platform/heap/GarbageCollected.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/modules/background_fetch/background_fetch.mojom-blink.h"
namespace blink { namespace blink {
class BackgroundFetchBridge;
class BackgroundFetchOptions; class BackgroundFetchOptions;
class BackgroundFetchRegistration;
class RequestOrUSVStringOrRequestOrUSVStringSequence; class RequestOrUSVStringOrRequestOrUSVStringSequence;
class ScriptPromiseResolver;
class ScriptState; class ScriptState;
class ServiceWorkerRegistration; class ServiceWorkerRegistration;
...@@ -33,10 +37,10 @@ class BackgroundFetchManager final ...@@ -33,10 +37,10 @@ class BackgroundFetchManager final
// Web Exposed methods defined in the IDL file. // Web Exposed methods defined in the IDL file.
ScriptPromise fetch( ScriptPromise fetch(
ScriptState*, ScriptState*,
String tag, const String& tag,
const RequestOrUSVStringOrRequestOrUSVStringSequence& requests, const RequestOrUSVStringOrRequestOrUSVStringSequence& requests,
const BackgroundFetchOptions&); const BackgroundFetchOptions&);
ScriptPromise get(ScriptState*, String tag); ScriptPromise get(ScriptState*, const String& tag);
ScriptPromise getTags(ScriptState*); ScriptPromise getTags(ScriptState*);
DECLARE_TRACE(); DECLARE_TRACE();
...@@ -44,7 +48,15 @@ class BackgroundFetchManager final ...@@ -44,7 +48,15 @@ class BackgroundFetchManager final
private: private:
explicit BackgroundFetchManager(ServiceWorkerRegistration*); explicit BackgroundFetchManager(ServiceWorkerRegistration*);
void didGetRegistration(ScriptPromiseResolver*,
mojom::blink::BackgroundFetchError,
BackgroundFetchRegistration*);
void didGetTags(ScriptPromiseResolver*,
mojom::blink::BackgroundFetchError,
const Vector<String>& tags);
Member<ServiceWorkerRegistration> m_registration; Member<ServiceWorkerRegistration> m_registration;
Member<BackgroundFetchBridge> m_bridge;
}; };
} // namespace blink } // namespace blink
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "modules/background_fetch/BackgroundFetchRegistration.h" #include "modules/background_fetch/BackgroundFetchRegistration.h"
#include "modules/background_fetch/BackgroundFetchBridge.h"
#include "modules/background_fetch/IconDefinition.h" #include "modules/background_fetch/IconDefinition.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h" #include "modules/serviceworkers/ServiceWorkerRegistration.h"
...@@ -40,8 +41,7 @@ String BackgroundFetchRegistration::title() const { ...@@ -40,8 +41,7 @@ String BackgroundFetchRegistration::title() const {
} }
void BackgroundFetchRegistration::abort() { void BackgroundFetchRegistration::abort() {
// TODO(peter): Implement the ability to abort the active background fetch BackgroundFetchBridge::from(m_registration)->abort(m_tag);
// for the |m_registration| identified by the |m_tag|.
} }
DEFINE_TRACE(BackgroundFetchRegistration) { DEFINE_TRACE(BackgroundFetchRegistration) {
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "modules/background_fetch/BackgroundFetchedEvent.h" #include "modules/background_fetch/BackgroundFetchedEvent.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h" #include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMException.h" #include "core/dom/DOMException.h"
#include "modules/EventModulesNames.h" #include "modules/EventModulesNames.h"
#include "modules/background_fetch/BackgroundFetchBridge.h"
#include "modules/background_fetch/BackgroundFetchSettledRequest.h" #include "modules/background_fetch/BackgroundFetchSettledRequest.h"
#include "modules/background_fetch/BackgroundFetchedEventInit.h" #include "modules/background_fetch/BackgroundFetchedEventInit.h"
...@@ -14,9 +16,11 @@ namespace blink { ...@@ -14,9 +16,11 @@ namespace blink {
BackgroundFetchedEvent::BackgroundFetchedEvent( BackgroundFetchedEvent::BackgroundFetchedEvent(
const AtomicString& type, const AtomicString& type,
const BackgroundFetchedEventInit& init) const BackgroundFetchedEventInit& init,
ServiceWorkerRegistration* registration)
: BackgroundFetchEvent(type, init), : BackgroundFetchEvent(type, init),
m_completedFetches(init.completedFetches()) {} m_completedFetches(init.completedFetches()),
m_registration(registration) {}
BackgroundFetchedEvent::~BackgroundFetchedEvent() = default; BackgroundFetchedEvent::~BackgroundFetchedEvent() = default;
...@@ -26,10 +30,37 @@ BackgroundFetchedEvent::completedFetches() const { ...@@ -26,10 +30,37 @@ BackgroundFetchedEvent::completedFetches() const {
} }
ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState, ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState,
String title) { const String& title) {
return ScriptPromise::rejectWithDOMException( if (!m_registration) {
scriptState, // Return a Promise that will never settle when a developer calls this
DOMException::create(NotSupportedError, "Not implemented yet.")); // method on a BackgroundFetchedEvent instance they created themselves.
return ScriptPromise();
}
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
BackgroundFetchBridge::from(m_registration)
->updateUI(tag(), title,
WTF::bind(&BackgroundFetchedEvent::didUpdateUI,
wrapPersistent(this), wrapPersistent(resolver)));
return promise;
}
void BackgroundFetchedEvent::didUpdateUI(
ScriptPromiseResolver* resolver,
mojom::blink::BackgroundFetchError error) {
switch (error) {
case mojom::blink::BackgroundFetchError::NONE:
resolver->resolve();
return;
case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
// Not applicable for this callback.
break;
}
NOTREACHED();
} }
const AtomicString& BackgroundFetchedEvent::interfaceName() const { const AtomicString& BackgroundFetchedEvent::interfaceName() const {
...@@ -38,6 +69,7 @@ const AtomicString& BackgroundFetchedEvent::interfaceName() const { ...@@ -38,6 +69,7 @@ const AtomicString& BackgroundFetchedEvent::interfaceName() const {
DEFINE_TRACE(BackgroundFetchedEvent) { DEFINE_TRACE(BackgroundFetchedEvent) {
visitor->trace(m_completedFetches); visitor->trace(m_completedFetches);
visitor->trace(m_registration);
BackgroundFetchEvent::trace(visitor); BackgroundFetchEvent::trace(visitor);
} }
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
#include "bindings/core/v8/ScriptPromise.h" #include "bindings/core/v8/ScriptPromise.h"
#include "modules/background_fetch/BackgroundFetchEvent.h" #include "modules/background_fetch/BackgroundFetchEvent.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/modules/background_fetch/background_fetch.mojom-blink.h"
#include "wtf/text/AtomicString.h" #include "wtf/text/AtomicString.h"
namespace blink { namespace blink {
class BackgroundFetchSettledRequest; class BackgroundFetchSettledRequest;
class BackgroundFetchedEventInit; class BackgroundFetchedEventInit;
class ServiceWorkerRegistration;
class BackgroundFetchedEvent final : public BackgroundFetchEvent { class BackgroundFetchedEvent final : public BackgroundFetchEvent {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
...@@ -22,7 +24,15 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent { ...@@ -22,7 +24,15 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent {
static BackgroundFetchedEvent* create( static BackgroundFetchedEvent* create(
const AtomicString& type, const AtomicString& type,
const BackgroundFetchedEventInit& initializer) { const BackgroundFetchedEventInit& initializer) {
return new BackgroundFetchedEvent(type, initializer); return new BackgroundFetchedEvent(type, initializer,
nullptr /* registration */);
}
static BackgroundFetchedEvent* create(
const AtomicString& type,
const BackgroundFetchedEventInit& initializer,
ServiceWorkerRegistration* registration) {
return new BackgroundFetchedEvent(type, initializer, registration);
} }
~BackgroundFetchedEvent() override; ~BackgroundFetchedEvent() override;
...@@ -31,7 +41,7 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent { ...@@ -31,7 +41,7 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent {
HeapVector<Member<BackgroundFetchSettledRequest>> completedFetches() const; HeapVector<Member<BackgroundFetchSettledRequest>> completedFetches() const;
// Web Exposed method defined in the IDL file. // Web Exposed method defined in the IDL file.
ScriptPromise updateUI(ScriptState*, String title); ScriptPromise updateUI(ScriptState*, const String& title);
// ExtendableEvent interface. // ExtendableEvent interface.
const AtomicString& interfaceName() const override; const AtomicString& interfaceName() const override;
...@@ -40,9 +50,13 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent { ...@@ -40,9 +50,13 @@ class BackgroundFetchedEvent final : public BackgroundFetchEvent {
private: private:
BackgroundFetchedEvent(const AtomicString& type, BackgroundFetchedEvent(const AtomicString& type,
const BackgroundFetchedEventInit&); const BackgroundFetchedEventInit&,
ServiceWorkerRegistration*);
void didUpdateUI(ScriptPromiseResolver*, mojom::blink::BackgroundFetchError);
HeapVector<Member<BackgroundFetchSettledRequest>> m_completedFetches; HeapVector<Member<BackgroundFetchSettledRequest>> m_completedFetches;
Member<ServiceWorkerRegistration> m_registration;
}; };
} // namespace blink } // namespace blink
......
...@@ -653,6 +653,7 @@ mojom("mojo_bindings") { ...@@ -653,6 +653,7 @@ mojom("mojo_bindings") {
sources = [ sources = [
"platform/mime_registry.mojom", "platform/mime_registry.mojom",
"platform/modules/app_banner/app_banner.mojom", "platform/modules/app_banner/app_banner.mojom",
"platform/modules/background_fetch/background_fetch.mojom",
"platform/modules/background_sync/background_sync.mojom", "platform/modules/background_sync/background_sync.mojom",
"platform/modules/bluetooth/web_bluetooth.mojom", "platform/modules/bluetooth/web_bluetooth.mojom",
"platform/modules/broadcastchannel/broadcast_channel.mojom", "platform/modules/broadcastchannel/broadcast_channel.mojom",
......
peter@chromium.org
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
# TEAM: platform-capabilities@chromium.org
# COMPONENT: Blink>BackgroundFetch
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
enum BackgroundFetchError {
NONE,
DUPLICATED_TAG
};
struct IconDefinition {
string src;
string sizes;
string type;
};
struct BackgroundFetchRegistration {
string tag;
array<IconDefinition> icons;
int64 total_download_size = 0;
string title = "";
};
interface BackgroundFetchService {
// TODO(peter): Implement support for the `fetch()` function in Mojo.
// Updates the user interface for the Background Fetch identified by the
// |service_worker_registration_id| and the |tag|.
UpdateUI(int64 service_worker_registration_id, string tag, string title)
=> (BackgroundFetchError error);
// Aborts the Background Fetch registration identified by the
// |service_worker_registration_id| and the |tag|.
Abort(int64 service_worker_registration_id, string tag);
// Gets the Background Fetch registration identified by the
// |service_worker_registration_id| and the |tag|.
GetRegistration(int64 service_worker_registration_id, string tag)
=> (BackgroundFetchError error,
BackgroundFetchRegistration? registration);
// Gets the sequence of tags for active Background Fetch registrations given
// the |service_worker_registration_id|.
GetTags(int64 service_worker_registration_id)
=> (BackgroundFetchError error,
array<string> tags);
};
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