chrome-devtools-frontend
Version:
Chrome DevTools UI
107 lines (89 loc) • 2.69 kB
text/typescript
// Copyright 2023 The Chromium Authors
// 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 * as Platform from '../../../core/platform/platform.js';
import type {UserFlow} from './Schema.js';
let instance: RecordingStorage|null = null;
interface IdGenerator {
next(): string;
}
class UUIDGenerator implements IdGenerator {
next(): string {
return crypto.randomUUID();
}
}
export class RecordingStorage {
constructor() {
this.
'recorder-recordings-ng',
[],
);
}
clearForTest(): void {
this.
this.
}
setIdGeneratorForTest(idGenerator: IdGenerator): void {
this.
}
async upsertRecording(
flow: UserFlow,
storageName?: string,
): Promise<StoredRecording> {
const release = await this.
try {
const recordings = await this.
flow.title = Platform.StringUtilities.trimEndWithMaxLength(flow.title, 300);
let recording = recordings.find(
recording => recording.storageName === storageName,
);
if (recording) {
recording.flow = flow;
} else {
recording = {
storageName: this.
flow,
};
recordings.push(recording);
}
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;
}