mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-30 01:43:36 +08:00
To suppress the races, we mark these invocations with `void` per the instructions of `no-floating-promises`. This explicitly marks these statements as side-effect promises. Engineers can later analyze these void statements and determine whether the promise races are intentional or accidental. R=jacktfranklin@chromium.org Bug: 1239617 Change-Id: I6b7a24cf21029d6ff73b112b3e8255ebab8c60ec Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3366467 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org>
67 lines
2.8 KiB
TypeScript
67 lines
2.8 KiB
TypeScript
// Copyright 2019 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as SDK from '../../core/sdk/sdk.js';
|
|
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
|
|
import type * as Protocol from '../../generated/protocol.js';
|
|
|
|
export class BackgroundServiceModel extends SDK.SDKModel.SDKModel<EventTypes> implements
|
|
ProtocolProxyApi.BackgroundServiceDispatcher {
|
|
private readonly backgroundServiceAgent: ProtocolProxyApi.BackgroundServiceApi;
|
|
private readonly events:
|
|
Map<Protocol.BackgroundService.ServiceName, Protocol.BackgroundService.BackgroundServiceEvent[]>;
|
|
|
|
constructor(target: SDK.Target.Target) {
|
|
super(target);
|
|
this.backgroundServiceAgent = target.backgroundServiceAgent();
|
|
target.registerBackgroundServiceDispatcher(this);
|
|
|
|
this.events = new Map();
|
|
}
|
|
|
|
enable(service: Protocol.BackgroundService.ServiceName): void {
|
|
this.events.set(service, []);
|
|
void this.backgroundServiceAgent.invoke_startObserving({service});
|
|
}
|
|
|
|
setRecording(shouldRecord: boolean, service: Protocol.BackgroundService.ServiceName): void {
|
|
void this.backgroundServiceAgent.invoke_setRecording({shouldRecord, service});
|
|
}
|
|
|
|
clearEvents(service: Protocol.BackgroundService.ServiceName): void {
|
|
this.events.set(service, []);
|
|
void this.backgroundServiceAgent.invoke_clearEvents({service});
|
|
}
|
|
|
|
getEvents(service: Protocol.BackgroundService.ServiceName): Protocol.BackgroundService.BackgroundServiceEvent[] {
|
|
return this.events.get(service) || [];
|
|
}
|
|
|
|
recordingStateChanged({isRecording, service}: Protocol.BackgroundService.RecordingStateChangedEvent): void {
|
|
this.dispatchEventToListeners(Events.RecordingStateChanged, {isRecording, serviceName: service});
|
|
}
|
|
|
|
backgroundServiceEventReceived({backgroundServiceEvent}:
|
|
Protocol.BackgroundService.BackgroundServiceEventReceivedEvent): void {
|
|
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
|
|
// @ts-expect-error
|
|
this.events.get(backgroundServiceEvent.service).push(backgroundServiceEvent);
|
|
this.dispatchEventToListeners(Events.BackgroundServiceEventReceived, backgroundServiceEvent);
|
|
}
|
|
}
|
|
|
|
SDK.SDKModel.SDKModel.register(BackgroundServiceModel, {capabilities: SDK.Target.Capability.Browser, autostart: false});
|
|
|
|
// TODO(crbug.com/1167717): Make this a const enum again
|
|
// eslint-disable-next-line rulesdir/const_enum
|
|
export enum Events {
|
|
RecordingStateChanged = 'RecordingStateChanged',
|
|
BackgroundServiceEventReceived = 'BackgroundServiceEventReceived',
|
|
}
|
|
|
|
export type EventTypes = {
|
|
[Events.RecordingStateChanged]: {isRecording: boolean, serviceName: Protocol.BackgroundService.ServiceName},
|
|
[Events.BackgroundServiceEventReceived]: Protocol.BackgroundService.BackgroundServiceEvent,
|
|
};
|