Commit c88d7a21 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate PeriodicSyncManager to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: Ia11cace00c6bfe2348cc5b1d60fd0c8b4411df68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134184Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756214}
parent 123ddc4d
...@@ -19,7 +19,9 @@ namespace blink { ...@@ -19,7 +19,9 @@ namespace blink {
PeriodicSyncManager::PeriodicSyncManager( PeriodicSyncManager::PeriodicSyncManager(
ServiceWorkerRegistration* registration, ServiceWorkerRegistration* registration,
scoped_refptr<base::SequencedTaskRunner> task_runner) scoped_refptr<base::SequencedTaskRunner> task_runner)
: registration_(registration), task_runner_(std::move(task_runner)) { : registration_(registration),
task_runner_(std::move(task_runner)),
background_sync_service_(registration_->GetExecutionContext()) {
DCHECK(registration_); DCHECK(registration_);
} }
...@@ -89,13 +91,13 @@ ScriptPromise PeriodicSyncManager::unregister(ScriptState* script_state, ...@@ -89,13 +91,13 @@ ScriptPromise PeriodicSyncManager::unregister(ScriptState* script_state,
return promise; return promise;
} }
const mojo::Remote<mojom::blink::PeriodicBackgroundSyncService>& mojom::blink::PeriodicBackgroundSyncService*
PeriodicSyncManager::GetBackgroundSyncServiceRemote() { PeriodicSyncManager::GetBackgroundSyncServiceRemote() {
if (!background_sync_service_.is_bound()) { if (!background_sync_service_.is_bound()) {
Platform::Current()->GetBrowserInterfaceBroker()->GetInterface( Platform::Current()->GetBrowserInterfaceBroker()->GetInterface(
background_sync_service_.BindNewPipeAndPassReceiver()); background_sync_service_.BindNewPipeAndPassReceiver(task_runner_));
} }
return background_sync_service_; return background_sync_service_.get();
} }
void PeriodicSyncManager::RegisterCallback( void PeriodicSyncManager::RegisterCallback(
...@@ -186,6 +188,7 @@ void PeriodicSyncManager::UnregisterCallback( ...@@ -186,6 +188,7 @@ void PeriodicSyncManager::UnregisterCallback(
void PeriodicSyncManager::Trace(Visitor* visitor) { void PeriodicSyncManager::Trace(Visitor* visitor) {
visitor->Trace(registration_); visitor->Trace(registration_);
visitor->Trace(background_sync_service_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
} }
......
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom-blink.h" #include "third_party/blink/public/mojom/background_sync/background_sync.mojom-blink.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink { namespace blink {
...@@ -43,8 +44,7 @@ class PeriodicSyncManager final : public ScriptWrappable { ...@@ -43,8 +44,7 @@ class PeriodicSyncManager final : public ScriptWrappable {
// mojo::Remote<mojom::blink::PeriodicBackgroundSyncService>. A connection // mojo::Remote<mojom::blink::PeriodicBackgroundSyncService>. A connection
// with the the browser's BackgroundSyncService is created the first time this // with the the browser's BackgroundSyncService is created the first time this
// method is called. // method is called.
const mojo::Remote<mojom::blink::PeriodicBackgroundSyncService>& mojom::blink::PeriodicBackgroundSyncService* GetBackgroundSyncServiceRemote();
GetBackgroundSyncServiceRemote();
// Callbacks // Callbacks
void RegisterCallback(ScriptPromiseResolver* resolver, void RegisterCallback(ScriptPromiseResolver* resolver,
...@@ -59,7 +59,8 @@ class PeriodicSyncManager final : public ScriptWrappable { ...@@ -59,7 +59,8 @@ class PeriodicSyncManager final : public ScriptWrappable {
Member<ServiceWorkerRegistration> registration_; Member<ServiceWorkerRegistration> registration_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
mojo::Remote<mojom::blink::PeriodicBackgroundSyncService> HeapMojoRemote<mojom::blink::PeriodicBackgroundSyncService,
HeapMojoWrapperMode::kWithoutContextObserver>
background_sync_service_; background_sync_service_;
}; };
......
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