0

blink: Let OneShotBackgroundSyncService be obtained via

ExecutionContent-scoped BIB

Migrated OneShotBackgroundSyncService interface; let it be obtained via
an ExecutionContent-scoped BrowserInterfaceBroker instead of a
Process-wide one. Then it can be controllable when prerendering a page.

Also fixed an error in webtest comments to make it be in accordance with
the error message.

Change-Id: I94ccdc65586b895f52f02972971338926e3b63a0
Bug: 1126758
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2395995
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Commit-Queue: Lingqi Chi <lingqi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807317}
This commit is contained in:
Lingqi Chi
2020-09-16 03:12:03 +00:00
committed by Commit Bot
parent 4723aeebae
commit bcc673eda8
7 changed files with 26 additions and 10 deletions
content
third_party/blink
renderer
modules
background_sync
web_tests
http
tests
background_sync

@@ -74,6 +74,7 @@
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom.h"
#include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom.h" #include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"
#include "third_party/blink/public/mojom/badging/badging.mojom.h" #include "third_party/blink/public/mojom/badging/badging.mojom.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h" #include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
@@ -679,6 +680,10 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, mojo::BinderMap* map) {
base::Unretained(host))); base::Unretained(host)));
#endif #endif
map->Add<blink::mojom::OneShotBackgroundSyncService>(
base::BindRepeating(&RenderProcessHost::CreateOneShotSyncService,
base::Unretained(host->GetProcess())));
map->Add<media::mojom::VideoDecodePerfHistory>( map->Add<media::mojom::VideoDecodePerfHistory>(
base::BindRepeating(&RenderProcessHost::BindVideoDecodePerfHistory, base::BindRepeating(&RenderProcessHost::BindVideoDecodePerfHistory,
base::Unretained(host->GetProcess()))); base::Unretained(host->GetProcess())));
@@ -1023,6 +1028,9 @@ void PopulateServiceWorkerBinders(ServiceWorkerHost* host,
// render process host binders // render process host binders
map->Add<media::mojom::VideoDecodePerfHistory>(BindServiceWorkerReceiver( map->Add<media::mojom::VideoDecodePerfHistory>(BindServiceWorkerReceiver(
&RenderProcessHostImpl::BindVideoDecodePerfHistory, host)); &RenderProcessHostImpl::BindVideoDecodePerfHistory, host));
map->Add<blink::mojom::OneShotBackgroundSyncService>(
BindServiceWorkerReceiver(
&RenderProcessHostImpl::CreateOneShotSyncService, host));
} }
void PopulateBinderMapWithContext( void PopulateBinderMapWithContext(

@@ -2311,10 +2311,6 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::BindRepeating(&RenderProcessHostImpl::BindCompositingModeReporter, base::BindRepeating(&RenderProcessHostImpl::BindCompositingModeReporter,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(&RenderProcessHostImpl::CreateOneShotSyncService,
weak_factory_.GetWeakPtr()));
AddUIThreadInterface( AddUIThreadInterface(
registry.get(), registry.get(),
base::BindRepeating(&RenderProcessHostImpl::CreatePeriodicSyncService, base::BindRepeating(&RenderProcessHostImpl::CreatePeriodicSyncService,
@@ -2665,6 +2661,7 @@ void RenderProcessHostImpl::BindAecDumpManager(
void RenderProcessHostImpl::CreateOneShotSyncService( void RenderProcessHostImpl::CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService> mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver) { receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
storage_partition_impl_->GetBackgroundSyncContext()->CreateOneShotSyncService( storage_partition_impl_->GetBackgroundSyncContext()->CreateOneShotSyncService(
std::move(receiver)); std::move(receiver));
} }

@@ -584,6 +584,13 @@ class CONTENT_EXPORT RenderProcessHostImpl
mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver) mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver)
override; override;
// Binds |receiver| to a OneShotBackgroundSyncService instance owned by the
// StoragePartition associated with the render process host, and is used by
// frames and service workers via BrowserInterfaceBroker.
void CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver) override;
// Binds |receiver| to a QuotaManagerHost instance indirectly owned by the // Binds |receiver| to a QuotaManagerHost instance indirectly owned by the
// StoragePartition associated with the render process host. Used by frames // StoragePartition associated with the render process host. Used by frames
// and workers via BrowserInterfaceBroker. // and workers via BrowserInterfaceBroker.
@@ -780,9 +787,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
mojo::PendingReceiver<blink::mojom::WebDatabaseHost> receiver); mojo::PendingReceiver<blink::mojom::WebDatabaseHost> receiver);
void BindAecDumpManager( void BindAecDumpManager(
mojo::PendingReceiver<blink::mojom::AecDumpManager> receiver); mojo::PendingReceiver<blink::mojom::AecDumpManager> receiver);
void CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver);
void CreatePeriodicSyncService( void CreatePeriodicSyncService(
mojo::PendingReceiver<blink::mojom::PeriodicBackgroundSyncService> mojo::PendingReceiver<blink::mojom::PeriodicBackgroundSyncService>
receiver); receiver);

@@ -33,6 +33,7 @@
#include "services/network/public/mojom/restricted_cookie_manager.mojom-forward.h" #include "services/network/public/mojom/restricted_cookie_manager.mojom-forward.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h" #include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-forward.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-forward.h"
#include "third_party/blink/public/mojom/filesystem/file_system.mojom-forward.h" #include "third_party/blink/public/mojom/filesystem/file_system.mojom-forward.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-forward.h" #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-forward.h"
@@ -503,6 +504,9 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
receiver) = 0; receiver) = 0;
virtual void BindVideoDecodePerfHistory( virtual void BindVideoDecodePerfHistory(
mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver) = 0; mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver) = 0;
virtual void CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver) = 0;
virtual void BindQuotaManagerHost( virtual void BindQuotaManagerHost(
int render_frame_id, int render_frame_id,
const url::Origin& origin, const url::Origin& origin,

@@ -199,6 +199,9 @@ class MockRenderProcessHost : public RenderProcessHost {
int render_frame_id, int render_frame_id,
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::LockManager> receiver) override {} mojo::PendingReceiver<blink::mojom::LockManager> receiver) override {}
void CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver) override {}
void CreatePermissionService( void CreatePermissionService(
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::PermissionService> receiver) mojo::PendingReceiver<blink::mojom::PermissionService> receiver)

@@ -4,7 +4,7 @@
#include "third_party/blink/renderer/modules/background_sync/sync_manager.h" #include "third_party/blink/renderer/modules/background_sync/sync_manager.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/callback_promise_adapter.h" #include "third_party/blink/renderer/bindings/core/v8/callback_promise_adapter.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
@@ -25,7 +25,7 @@ SyncManager::SyncManager(ServiceWorkerRegistration* registration,
: registration_(registration), : registration_(registration),
background_sync_service_(registration->GetExecutionContext()) { background_sync_service_(registration->GetExecutionContext()) {
DCHECK(registration); DCHECK(registration);
Platform::Current()->GetBrowserInterfaceBroker()->GetInterface( registration->GetExecutionContext()->GetBrowserInterfaceBroker().GetInterface(
background_sync_service_.BindNewPipeAndPassReceiver(task_runner)); background_sync_service_.BindNewPipeAndPassReceiver(task_runner));
} }

@@ -14,7 +14,7 @@ promise_test(function(t) {
const scope = '/resources/scope/background_sync/' + iframe_scope; const scope = '/resources/scope/background_sync/' + iframe_scope;
var sync_manager; var sync_manager;
// This test verifies that registration of one-shots fails from an iframe. // This test verifies that one-shot syncs can be registered from an iframe.
return PermissionsHelper.setPermission('background-sync', 'granted') return PermissionsHelper.setPermission('background-sync', 'granted')
.then(function() { .then(function() {
return service_worker_unregister_and_register(t, url, scope); return service_worker_unregister_and_register(t, url, scope);