chrome-devtools-frontend
Version:
Chrome DevTools UI
113 lines (96 loc) • 2.95 kB
text/typescript
// Copyright 2023 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 Common from '../../../core/common/common.js';
import {type UserFlow} from './Schema.js';
let instance: RecordingStorage|null = null;
interface IdGenerator {
next(): string;
}
class UUIDGenerator implements IdGenerator {
next(): string {
// @ts-ignore
return crypto.randomUUID();
}
}
export class RecordingStorage {
constructor() {
this.
'recorder_recordings_ng',
[],
);
}
clearForTest(): void {
this.
this.
}
setIdGeneratorForTest(idGenerator: IdGenerator): void {
this.
}
async saveRecording(flow: UserFlow): Promise<StoredRecording> {
const release = await this.
try {
const recordings = await this.
const storageName = this.
const recording = {storageName, flow};
recordings.push(recording);
this.
return recording;
} finally {
release();
}
}
async updateRecording(
storageName: string,
flow: UserFlow,
): Promise<StoredRecording> {
const release = await this.
try {
const recordings = await this.
const recording = recordings.find(
recording => recording.storageName === storageName,
);
if (!recording) {
throw new Error('No recording is found during updateRecording');
}
recording.flow = flow;
this.
return recording;
} finally {
release();
}
}
async deleteRecording(storageName: string): Promise<void> {
const release = await this.
try {
const recordings = await this.
this.
recordings.filter(recording => recording.storageName !== storageName),
);
} finally {
release();
}
}
getRecording(storageName: string): StoredRecording|undefined {
const recordings = this.
return recordings.find(
recording => recording.storageName === storageName,
);
}
getRecordings(): StoredRecording[] {
return this.
}
static instance(): RecordingStorage {
if (!instance) {
instance = new RecordingStorage();
}
return instance;
}
}
export interface StoredRecording {
storageName: string;
flow: UserFlow;
}