Commit 63030b69 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert LockRequest to new Mojo types

This CL converts LockRequestAssociatedPtr,
LockRequestAssociatedPtrInfo, and LockRequestAssociatedRequest
to new Mojo types.
It also updates RequestLock from lock_manager.mojom.

Bug: 955171, 978694
Change-Id: Icb8a72f2758f1a604c6a687cc9488d7a8e1d6524
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768498Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#691527}
parent a7b3dded
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/guid.h" #include "base/guid.h"
#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/strong_associated_binding.h" #include "mojo/public/cpp/bindings/strong_associated_binding.h"
using blink::mojom::LockMode; using blink::mojom::LockMode;
...@@ -74,7 +75,7 @@ class LockManager::Lock { ...@@ -74,7 +75,7 @@ class LockManager::Lock {
LockMode mode, LockMode mode,
int64_t lock_id, int64_t lock_id,
const std::string& client_id, const std::string& client_id,
blink::mojom::LockRequestAssociatedPtr request) mojo::AssociatedRemote<blink::mojom::LockRequest> request)
: name_(name), : name_(name),
mode_(mode), mode_(mode),
client_id_(client_id), client_id_(client_id),
...@@ -89,7 +90,7 @@ class LockManager::Lock { ...@@ -89,7 +90,7 @@ class LockManager::Lock {
DCHECK(!handle_); DCHECK(!handle_);
request_->Abort(message); request_->Abort(message);
request_ = nullptr; request_.reset();
} }
// Grant a lock request. This mints a LockHandle and returns it over the // Grant a lock request. This mints a LockHandle and returns it over the
...@@ -103,7 +104,7 @@ class LockManager::Lock { ...@@ -103,7 +104,7 @@ class LockManager::Lock {
handle_ = handle_ =
LockHandleImpl::Create(std::move(context), origin, lock_id_, &ptr); LockHandleImpl::Create(std::move(context), origin, lock_id_, &ptr);
request_->Granted(ptr.PassInterface()); request_->Granted(ptr.PassInterface());
request_ = nullptr; request_.reset();
} }
// Break a granted lock. This terminates the connection, signaling an error // Break a granted lock. This terminates the connection, signaling an error
...@@ -135,7 +136,7 @@ class LockManager::Lock { ...@@ -135,7 +136,7 @@ class LockManager::Lock {
// Exactly one of the following is non-null at any given time. // Exactly one of the following is non-null at any given time.
// |request_| is valid until the lock is granted (or failure). // |request_| is valid until the lock is granted (or failure).
blink::mojom::LockRequestAssociatedPtr request_; mojo::AssociatedRemote<blink::mojom::LockRequest> request_;
// 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.
...@@ -170,7 +171,7 @@ class LockManager::OriginState { ...@@ -170,7 +171,7 @@ class LockManager::OriginState {
const std::string& name, const std::string& name,
LockMode mode, LockMode mode,
const std::string& client_id, const std::string& client_id,
blink::mojom::LockRequestAssociatedPtr request, mojo::AssociatedRemote<blink::mojom::LockRequest> request,
const url::Origin origin) { const url::Origin origin) {
// Preempting shared locks is not supported. // Preempting shared locks is not supported.
DCHECK_EQ(mode, LockMode::EXCLUSIVE); DCHECK_EQ(mode, LockMode::EXCLUSIVE);
...@@ -188,7 +189,7 @@ class LockManager::OriginState { ...@@ -188,7 +189,7 @@ class LockManager::OriginState {
const std::string& name, const std::string& name,
LockMode mode, LockMode mode,
const std::string& client_id, const std::string& client_id,
blink::mojom::LockRequestAssociatedPtr request, mojo::AssociatedRemote<blink::mojom::LockRequest> request,
WaitMode wait, WaitMode wait,
const url::Origin origin) { const url::Origin origin) {
DCHECK(wait != WaitMode::PREEMPT); DCHECK(wait != WaitMode::PREEMPT);
...@@ -321,7 +322,7 @@ void LockManager::RequestLock( ...@@ -321,7 +322,7 @@ void LockManager::RequestLock(
const std::string& name, const std::string& name,
LockMode mode, LockMode mode,
WaitMode wait, WaitMode wait,
blink::mojom::LockRequestAssociatedPtrInfo request_info) { mojo::PendingAssociatedRemote<blink::mojom::LockRequest> request_remote) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (wait == WaitMode::PREEMPT && mode != LockMode::EXCLUSIVE) { if (wait == WaitMode::PREEMPT && mode != LockMode::EXCLUSIVE) {
...@@ -341,9 +342,9 @@ void LockManager::RequestLock( ...@@ -341,9 +342,9 @@ void LockManager::RequestLock(
int64_t lock_id = NextLockId(); int64_t lock_id = NextLockId();
blink::mojom::LockRequestAssociatedPtr request; mojo::AssociatedRemote<blink::mojom::LockRequest> request(
request.Bind(std::move(request_info)); std::move(request_remote));
request.set_connection_error_handler(base::BindOnce(&LockManager::ReleaseLock, request.set_disconnect_handler(base::BindOnce(&LockManager::ReleaseLock,
base::Unretained(this), base::Unretained(this),
context.origin, lock_id)); context.origin, lock_id));
......
...@@ -34,7 +34,8 @@ class LockManager : public base::RefCountedThreadSafe<LockManager>, ...@@ -34,7 +34,8 @@ class LockManager : public base::RefCountedThreadSafe<LockManager>,
void RequestLock(const std::string& name, void RequestLock(const std::string& name,
blink::mojom::LockMode mode, blink::mojom::LockMode mode,
WaitMode wait, WaitMode wait,
blink::mojom::LockRequestAssociatedPtrInfo request) override; mojo::PendingAssociatedRemote<blink::mojom::LockRequest>
request) override;
// Called by a LockHandle's implementation when destructed. // Called by a LockHandle's implementation when destructed.
void ReleaseLock(const url::Origin& origin, int64_t lock_id); void ReleaseLock(const url::Origin& origin, int64_t lock_id);
......
...@@ -69,7 +69,7 @@ interface LockManager { ...@@ -69,7 +69,7 @@ interface LockManager {
RequestLock(string name, RequestLock(string name,
LockMode mode, LockMode mode,
WaitMode wait, WaitMode wait,
associated LockRequest request); pending_associated_remote<LockRequest> request);
// Produces a snapshot of the lock manager's state. Web applications // Produces a snapshot of the lock manager's state. Web applications
// can use this for diagnostic purposes. // can use this for diagnostic purposes.
......
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
#include <algorithm> #include <algorithm>
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
...@@ -60,28 +59,29 @@ class LockManager::LockRequestImpl final ...@@ -60,28 +59,29 @@ class LockManager::LockRequestImpl final
USING_PRE_FINALIZER(LockManager::LockRequestImpl, Dispose); USING_PRE_FINALIZER(LockManager::LockRequestImpl, Dispose);
public: public:
LockRequestImpl(V8LockGrantedCallback* callback, LockRequestImpl(
V8LockGrantedCallback* callback,
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
const String& name, const String& name,
mojom::blink::LockMode mode, mojom::blink::LockMode mode,
mojom::blink::LockRequestAssociatedRequest request, mojo::PendingAssociatedReceiver<mojom::blink::LockRequest> receiver,
LockManager* manager) LockManager* manager)
: callback_(callback), : callback_(callback),
resolver_(resolver), resolver_(resolver),
name_(name), name_(name),
mode_(mode), mode_(mode),
binding_( receiver_(
this, this,
std::move(request), std::move(receiver),
manager->GetExecutionContext()->GetTaskRunner(TaskType::kWebLocks)), manager->GetExecutionContext()->GetTaskRunner(TaskType::kWebLocks)),
manager_(manager) {} manager_(manager) {}
~LockRequestImpl() override = default; ~LockRequestImpl() override = default;
void Dispose() { void Dispose() {
// This Impl might still be bound to a LockRequest, so we close // This Impl might still be bound to a LockRequest, so we reset
// the binding before destroying the object. // the receiver before destroying the object.
binding_.Close(); receiver_.reset();
} }
void Trace(blink::Visitor* visitor) { void Trace(blink::Visitor* visitor) {
...@@ -96,7 +96,7 @@ class LockManager::LockRequestImpl final ...@@ -96,7 +96,7 @@ class LockManager::LockRequestImpl final
// Called to immediately close the pipe which signals the back-end, // Called to immediately close the pipe which signals the back-end,
// unblocking further requests, without waiting for GC finalize the object. // unblocking further requests, without waiting for GC finalize the object.
void Cancel() { binding_.Close(); } void Cancel() { receiver_.reset(); }
void Abort(const String& reason) override { void Abort(const String& reason) override {
// Abort signal after acquisition should be ignored. // Abort signal after acquisition should be ignored.
...@@ -104,7 +104,7 @@ class LockManager::LockRequestImpl final ...@@ -104,7 +104,7 @@ class LockManager::LockRequestImpl final
return; return;
manager_->RemovePendingRequest(this); manager_->RemovePendingRequest(this);
binding_.Close(); receiver_.reset();
if (!resolver_->GetScriptState()->ContextIsValid()) if (!resolver_->GetScriptState()->ContextIsValid())
return; return;
...@@ -117,7 +117,7 @@ class LockManager::LockRequestImpl final ...@@ -117,7 +117,7 @@ class LockManager::LockRequestImpl final
auto* callback = callback_.Release(); auto* callback = callback_.Release();
manager_->RemovePendingRequest(this); manager_->RemovePendingRequest(this);
binding_.Close(); receiver_.reset();
ScriptState* script_state = resolver_->GetScriptState(); ScriptState* script_state = resolver_->GetScriptState();
if (!script_state->ContextIsValid()) if (!script_state->ContextIsValid())
...@@ -136,7 +136,7 @@ class LockManager::LockRequestImpl final ...@@ -136,7 +136,7 @@ class LockManager::LockRequestImpl final
} }
void Granted(mojom::blink::LockHandleAssociatedPtrInfo handle_info) override { void Granted(mojom::blink::LockHandleAssociatedPtrInfo handle_info) override {
DCHECK(binding_.is_bound()); DCHECK(receiver_.is_bound());
mojom::blink::LockHandleAssociatedPtr handle; mojom::blink::LockHandleAssociatedPtr handle;
handle.Bind(std::move(handle_info)); handle.Bind(std::move(handle_info));
...@@ -144,7 +144,7 @@ class LockManager::LockRequestImpl final ...@@ -144,7 +144,7 @@ class LockManager::LockRequestImpl final
auto* callback = callback_.Release(); auto* callback = callback_.Release();
manager_->RemovePendingRequest(this); manager_->RemovePendingRequest(this);
binding_.Close(); receiver_.reset();
ScriptState* script_state = resolver_->GetScriptState(); ScriptState* script_state = resolver_->GetScriptState();
if (!script_state->ContextIsValid()) { if (!script_state->ContextIsValid()) {
...@@ -183,7 +183,7 @@ class LockManager::LockRequestImpl final ...@@ -183,7 +183,7 @@ class LockManager::LockRequestImpl final
// Held to stamp the Lock object's |mode| property. // Held to stamp the Lock object's |mode| property.
mojom::blink::LockMode mode_; mojom::blink::LockMode mode_;
mojo::AssociatedBinding<mojom::blink::LockRequest> binding_; mojo::AssociatedReceiver<mojom::blink::LockRequest> receiver_;
// The |manager_| keeps |this| alive until a response comes in and this is // The |manager_| keeps |this| alive until a response comes in and this is
// registered. If the context is destroyed then |manager_| will dispose of // registered. If the context is destroyed then |manager_| will dispose of
...@@ -302,13 +302,14 @@ ScriptPromise LockManager::request(ScriptState* script_state, ...@@ -302,13 +302,14 @@ ScriptPromise LockManager::request(ScriptState* script_state,
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
mojom::blink::LockRequestAssociatedPtrInfo request_info; mojo::PendingAssociatedRemote<mojom::blink::LockRequest> request_remote;
// 11.1. Let request be the result of running the steps to request a lock with // 11.1. Let request be the result of running the steps to request a lock with
// promise, the current agent, environment’s id, origin, callback, name, // promise, the current agent, environment’s id, origin, callback, name,
// options’ mode dictionary member, options’ ifAvailable dictionary member, // options’ mode dictionary member, options’ ifAvailable dictionary member,
// and options’ steal dictionary member. // and options’ steal dictionary member.
LockRequestImpl* request = MakeGarbageCollected<LockRequestImpl>( LockRequestImpl* request = MakeGarbageCollected<LockRequestImpl>(
callback, resolver, name, mode, mojo::MakeRequest(&request_info), this); callback, resolver, name, mode,
request_remote.InitWithNewEndpointAndPassReceiver(), this);
AddPendingRequest(request); AddPendingRequest(request);
// 11.2. If options’ signal dictionary member is present, then add the // 11.2. If options’ signal dictionary member is present, then add the
...@@ -322,7 +323,7 @@ ScriptPromise LockManager::request(ScriptState* script_state, ...@@ -322,7 +323,7 @@ ScriptPromise LockManager::request(ScriptState* script_state,
String(kRequestAbortedMessage))); String(kRequestAbortedMessage)));
} }
service_->RequestLock(name, mode, wait, std::move(request_info)); service_->RequestLock(name, mode, wait, std::move(request_remote));
// 12. Return promise. // 12. Return promise.
return promise; return promise;
......
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