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