Commit 5d9e017e authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert LockHandle to new Mojo types

This CL converts LockHandleAssociatedPtr and
LockHandleAssociatedPtrInfo to new Mojo types.
It also updates Granted from lock_manager.mojom.

Bug: 955171, 978694
Change-Id: I02ba0cdbe52f8f04b3e4514a1f335917db368559
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771365
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691596}
parent df939f0b
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/strong_associated_binding.h" #include "mojo/public/cpp/bindings/self_owned_associated_receiver.h"
using blink::mojom::LockMode; using blink::mojom::LockMode;
...@@ -32,14 +32,14 @@ constexpr int64_t kPreemptiveLockId = 0; ...@@ -32,14 +32,14 @@ constexpr int64_t kPreemptiveLockId = 0;
// connection can also be closed here when a lock is stolen. // connection can also be closed here when a lock is stolen.
class LockHandleImpl final : public blink::mojom::LockHandle { class LockHandleImpl final : public blink::mojom::LockHandle {
public: public:
static mojo::StrongAssociatedBindingPtr<blink::mojom::LockHandle> Create( static mojo::SelfOwnedAssociatedReceiverRef<blink::mojom::LockHandle> Create(
base::WeakPtr<LockManager> context, base::WeakPtr<LockManager> context,
const url::Origin& origin, const url::Origin& origin,
int64_t lock_id, int64_t lock_id,
blink::mojom::LockHandleAssociatedPtr* ptr) { mojo::PendingAssociatedRemote<blink::mojom::LockHandle>* remote) {
return mojo::MakeStrongAssociatedBinding( return mojo::MakeSelfOwnedAssociatedReceiver(
std::make_unique<LockHandleImpl>(std::move(context), origin, lock_id), std::make_unique<LockHandleImpl>(std::move(context), origin, lock_id),
mojo::MakeRequest(ptr)); remote->InitWithNewEndpointAndPassReceiver());
} }
LockHandleImpl(base::WeakPtr<LockManager> context, LockHandleImpl(base::WeakPtr<LockManager> context,
...@@ -100,10 +100,10 @@ class LockManager::Lock { ...@@ -100,10 +100,10 @@ class LockManager::Lock {
DCHECK(request_); DCHECK(request_);
DCHECK(!handle_); DCHECK(!handle_);
blink::mojom::LockHandleAssociatedPtr ptr; mojo::PendingAssociatedRemote<blink::mojom::LockHandle> remote;
handle_ = handle_ =
LockHandleImpl::Create(std::move(context), origin, lock_id_, &ptr); LockHandleImpl::Create(std::move(context), origin, lock_id_, &remote);
request_->Granted(ptr.PassInterface()); request_->Granted(std::move(remote));
request_.reset(); request_.reset();
} }
...@@ -140,7 +140,7 @@ class LockManager::Lock { ...@@ -140,7 +140,7 @@ class LockManager::Lock {
// Once granted, |handle_| holds this end of the pipe that lets us monitor // Once granted, |handle_| holds this end of the pipe that lets us monitor
// for the other end going away. // for the other end going away.
mojo::StrongAssociatedBindingPtr<blink::mojom::LockHandle> handle_; mojo::SelfOwnedAssociatedReceiverRef<blink::mojom::LockHandle> handle_;
}; };
LockManager::LockManager() {} LockManager::LockManager() {}
......
...@@ -15,7 +15,7 @@ interface LockHandle {}; ...@@ -15,7 +15,7 @@ interface LockHandle {};
interface LockRequest { interface LockRequest {
// Request was granted. Associated to maintain ordering within // Request was granted. Associated to maintain ordering within
// a LockManager, to match task queue behavior required by spec. // a LockManager, to match task queue behavior required by spec.
Granted(associated LockHandle lock_handle); Granted(pending_associated_remote<LockHandle> lock_handle);
// Request failed; e.g. request was only "if available" and it was not. // Request failed; e.g. request was only "if available" and it was not.
Failed(); Failed();
......
...@@ -62,11 +62,12 @@ class Lock::ThenFunction final : public ScriptFunction { ...@@ -62,11 +62,12 @@ class Lock::ThenFunction final : public ScriptFunction {
}; };
// static // static
Lock* Lock::Create(ScriptState* script_state, Lock* Lock::Create(
const String& name, ScriptState* script_state,
mojom::blink::LockMode mode, const String& name,
mojom::blink::LockHandleAssociatedPtr handle, mojom::blink::LockMode mode,
LockManager* manager) { mojo::PendingAssociatedRemote<mojom::blink::LockHandle> handle,
LockManager* manager) {
return MakeGarbageCollected<Lock>(script_state, name, mode, std::move(handle), return MakeGarbageCollected<Lock>(script_state, name, mode, std::move(handle),
manager); manager);
} }
...@@ -74,14 +75,14 @@ Lock* Lock::Create(ScriptState* script_state, ...@@ -74,14 +75,14 @@ Lock* Lock::Create(ScriptState* script_state,
Lock::Lock(ScriptState* script_state, Lock::Lock(ScriptState* script_state,
const String& name, const String& name,
mojom::blink::LockMode mode, mojom::blink::LockMode mode,
mojom::blink::LockHandleAssociatedPtr handle, mojo::PendingAssociatedRemote<mojom::blink::LockHandle> handle,
LockManager* manager) LockManager* manager)
: ContextLifecycleObserver(ExecutionContext::From(script_state)), : ContextLifecycleObserver(ExecutionContext::From(script_state)),
name_(name), name_(name),
mode_(mode), mode_(mode),
handle_(std::move(handle)), handle_(std::move(handle)),
manager_(manager) { manager_(manager) {
handle_.set_connection_error_handler( handle_.set_disconnect_handler(
WTF::Bind(&Lock::OnConnectionError, WrapWeakPersistent(this))); WTF::Bind(&Lock::OnConnectionError, WrapWeakPersistent(this)));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_LOCKS_LOCK_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_LOCKS_LOCK_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_LOCKS_LOCK_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_LOCKS_LOCK_H_
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/mojom/locks/lock_manager.mojom-blink.h" #include "third_party/blink/public/mojom/locks/lock_manager.mojom-blink.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -27,13 +28,13 @@ class Lock final : public ScriptWrappable, public ContextLifecycleObserver { ...@@ -27,13 +28,13 @@ class Lock final : public ScriptWrappable, public ContextLifecycleObserver {
static Lock* Create(ScriptState*, static Lock* Create(ScriptState*,
const String& name, const String& name,
mojom::blink::LockMode, mojom::blink::LockMode,
mojom::blink::LockHandleAssociatedPtr, mojo::PendingAssociatedRemote<mojom::blink::LockHandle>,
LockManager*); LockManager*);
Lock(ScriptState*, Lock(ScriptState*,
const String& name, const String& name,
mojom::blink::LockMode, mojom::blink::LockMode,
mojom::blink::LockHandleAssociatedPtr, mojo::PendingAssociatedRemote<mojom::blink::LockHandle>,
LockManager*); LockManager*);
~Lock() override; ~Lock() override;
...@@ -69,7 +70,7 @@ class Lock final : public ScriptWrappable, public ContextLifecycleObserver { ...@@ -69,7 +70,7 @@ class Lock final : public ScriptWrappable, public ContextLifecycleObserver {
// An opaque handle; this one end of a mojo pipe. When this is closed, // An opaque handle; this one end of a mojo pipe. When this is closed,
// the lock is released by the back end. // the lock is released by the back end.
mojom::blink::LockHandleAssociatedPtr handle_; mojo::AssociatedRemote<mojom::blink::LockHandle> handle_;
// LockManager::OnLockReleased() is called when this lock is released, to // LockManager::OnLockReleased() is called when this lock is released, to
// stop artificially keeping this instance alive. It is necessary in the // stop artificially keeping this instance alive. It is necessary in the
......
...@@ -135,12 +135,10 @@ class LockManager::LockRequestImpl final ...@@ -135,12 +135,10 @@ class LockManager::LockRequestImpl final
} }
} }
void Granted(mojom::blink::LockHandleAssociatedPtrInfo handle_info) override { void Granted(mojo::PendingAssociatedRemote<mojom::blink::LockHandle>
handle_remote) override {
DCHECK(receiver_.is_bound()); DCHECK(receiver_.is_bound());
mojom::blink::LockHandleAssociatedPtr handle;
handle.Bind(std::move(handle_info));
auto* callback = callback_.Release(); auto* callback = callback_.Release();
manager_->RemovePendingRequest(this); manager_->RemovePendingRequest(this);
...@@ -152,8 +150,8 @@ class LockManager::LockRequestImpl final ...@@ -152,8 +150,8 @@ class LockManager::LockRequestImpl final
return; return;
} }
Lock* lock = Lock* lock = Lock::Create(script_state, name_, mode_,
Lock::Create(script_state, name_, mode_, std::move(handle), manager_); std::move(handle_remote), manager_);
manager_->held_locks_.insert(lock); manager_->held_locks_.insert(lock);
ScriptState::Scope scope(script_state); ScriptState::Scope scope(script_state);
......
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