Commit ff8b40b7 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

Add class to keep track of outstanding `XR:requestSession()` calls

This change adds PendingRequestSessionQuery class to encapsulate
outstanding `requestSession()` calls. It will automatically record
UKM entries when the request is resolved or rejected.

Rename PendingSessionQuery to PendingSupportsSessionQuery.

Bug: 968622
Change-Id: Id33524182eb555802d1ef02fc78741b4276ec290
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1648788Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667364}
parent 9982cd6a
This diff is collapsed.
...@@ -86,30 +86,81 @@ class XR final : public EventTargetWithInlineData, ...@@ -86,30 +86,81 @@ class XR final : public EventTargetWithInlineData,
kMaxValue = kOtherError, kMaxValue = kOtherError,
}; };
class PendingSessionQuery final // Encapsulates blink-side `XR::requestSession()` call. It is a wrapper around
: public GarbageCollected<PendingSessionQuery> { // ScriptPromiseResolver that allows us to add additional logic as certain
DISALLOW_COPY_AND_ASSIGN(PendingSessionQuery); // things related to promise's life cycle happen.
class PendingRequestSessionQuery final
: public GarbageCollected<PendingRequestSessionQuery> {
DISALLOW_COPY_AND_ASSIGN(PendingRequestSessionQuery);
public: public:
PendingSessionQuery(ScriptPromiseResolver*, XRSession::SessionMode); PendingRequestSessionQuery(int64_t ukm_source_id,
virtual ~PendingSessionQuery() = default; ScriptPromiseResolver* resolver,
XRSession::SessionMode mode);
virtual ~PendingRequestSessionQuery() = default;
// Resolves underlying promise with passed in XR session.
void Resolve(XRSession* session);
// Rejects underlying promise with passed in DOM exception.
void Reject(DOMException* exception);
// Rejects underlying promise with passed in v8 value. Used to raise
// TypeError which is not a DOM exception.
void Reject(v8::Local<v8::Value> value);
XRSession::SessionMode mode() const;
// Returns underlying resolver's script state.
ScriptState* GetScriptState() const;
virtual void Trace(blink::Visitor*);
private:
void ReportRequestSessionResult(SessionRequestStatus status);
Member<ScriptPromiseResolver> resolver_;
const XRSession::SessionMode mode_;
const int64_t ukm_source_id_;
};
// Encapsulates blink-side `XR::supportsSession()` call. It is a wrapper
// around ScriptPromiseResolver that allows us to add additional logic as
// certain things related to promise's life cycle happen.
class PendingSupportsSessionQuery final
: public GarbageCollected<PendingSupportsSessionQuery> {
DISALLOW_COPY_AND_ASSIGN(PendingSupportsSessionQuery);
public:
PendingSupportsSessionQuery(ScriptPromiseResolver*, XRSession::SessionMode);
virtual ~PendingSupportsSessionQuery() = default;
// Resolves underlying promise.
void Resolve();
// Rejects underlying promise with passed in DOM exception.
void Reject(DOMException* exception);
// Rejects underlying promise with passed in v8 value. Used to raise
// TypeError which is not a DOM exception.
void Reject(v8::Local<v8::Value> value);
XRSession::SessionMode mode() const;
virtual void Trace(blink::Visitor*); virtual void Trace(blink::Visitor*);
Member<ScriptPromiseResolver> resolver; private:
const XRSession::SessionMode mode; Member<ScriptPromiseResolver> resolver_;
bool has_user_activation = false; const XRSession::SessionMode mode_;
}; };
void OnRequestDeviceReturned(device::mojom::blink::XRDevicePtr device); void OnRequestDeviceReturned(device::mojom::blink::XRDevicePtr device);
void DispatchPendingSessionCalls(); void DispatchPendingSessionCalls();
void DispatchRequestSession(PendingSessionQuery*); void DispatchRequestSession(PendingRequestSessionQuery*);
void OnRequestSessionReturned(PendingSessionQuery*, void OnRequestSessionReturned(PendingRequestSessionQuery*,
device::mojom::blink::XRSessionPtr); device::mojom::blink::XRSessionPtr);
void DispatchSupportsSession(PendingSessionQuery*); void DispatchSupportsSession(PendingSupportsSessionQuery*);
void OnSupportsSessionReturned(PendingSessionQuery*, bool supports_session); void OnSupportsSessionReturned(PendingSupportsSessionQuery*,
bool supports_session);
void EnsureDevice(); void EnsureDevice();
void ReportImmersiveSupported(bool supported); void ReportImmersiveSupported(bool supported);
...@@ -148,11 +199,11 @@ class XR final : public EventTargetWithInlineData, ...@@ -148,11 +199,11 @@ class XR final : public EventTargetWithInlineData,
// Track calls that were made prior to the internal device successfully being // Track calls that were made prior to the internal device successfully being
// queried. Can be removed once the service has been updated to allow the // queried. Can be removed once the service has been updated to allow the
// respective calls to be made directly. // respective calls to be made directly.
HeapVector<Member<PendingSessionQuery>> pending_mode_queries_; HeapVector<Member<PendingSupportsSessionQuery>> pending_mode_queries_;
HeapVector<Member<PendingSessionQuery>> pending_session_requests_; HeapVector<Member<PendingRequestSessionQuery>> pending_session_requests_;
HeapHashSet<Member<PendingSessionQuery>> outstanding_support_queries_; HeapHashSet<Member<PendingSupportsSessionQuery>> outstanding_support_queries_;
HeapHashSet<Member<PendingSessionQuery>> outstanding_request_queries_; HeapHashSet<Member<PendingRequestSessionQuery>> outstanding_request_queries_;
Vector<EnvironmentProviderErrorCallback> Vector<EnvironmentProviderErrorCallback>
environment_provider_error_callbacks_; environment_provider_error_callbacks_;
......
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