@@ -8,7 +8,6 @@ import * as i18n from '../../core/i18n/i18n.js';
88import type * as Platform from '../../core/platform/platform.js' ;
99import * as SDK from '../../core/sdk/sdk.js' ;
1010import type * as Protocol from '../../generated/protocol.js' ;
11- import * as Bindings from '../../models/bindings/bindings.js' ;
1211import * as Trace from '../../models/trace/trace.js' ;
1312
1413import * as RecordingMetadata from './RecordingMetadata.js' ;
@@ -25,18 +24,12 @@ const str_ = i18n.i18n.registerUIStrings('panels/timeline/TimelineLoader.ts', UI
2524const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
2625
2726/**
28- * This class handles loading traces from file and URL, and from the Lighthouse panel
29- * It also handles loading cpuprofiles from file, url and console.profileEnd()
30- *
31- * Meanwhile, the normal trace recording flow bypasses TimelineLoader entirely,
32- * as it's handled from TracingManager => TimelineController.
27+ * This class handles loading traces from URL, and from the Lighthouse panel
28+ * It also handles loading cpuprofiles from url and console.profileEnd()
3329 */
34- export class TimelineLoader implements Common . StringOutputStream . OutputStream {
30+ export class TimelineLoader {
3531 private client : Client | null ;
3632 private canceledCallback : ( ( ) => void ) | null ;
37- private buffer : string ;
38- private firstRawChunk : boolean ;
39- private totalSize ! : number ;
4033 private filter : Trace . Extras . TraceFilter . TraceFilter | null ;
4134 #traceIsCPUProfile: boolean ;
4235 #collectedEvents: Trace . Types . Events . Event [ ] = [ ] ;
@@ -48,8 +41,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
4841 constructor ( client : Client ) {
4942 this . client = client ;
5043 this . canceledCallback = null ;
51- this . buffer = '' ;
52- this . firstRawChunk = true ;
5344 this . filter = null ;
5445 this . #traceIsCPUProfile = false ;
5546 this . #metadata = null ;
@@ -59,23 +50,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
5950 } ) ;
6051 }
6152
62- static async loadFromFile ( file : File , client : Client ) : Promise < TimelineLoader > {
63- const loader = new TimelineLoader ( client ) ;
64- const fileReader = new Bindings . FileUtils . ChunkedFileReader ( file ) ;
65- loader . canceledCallback = fileReader . cancel . bind ( fileReader ) ;
66- loader . totalSize = file . size ;
67- // We'll resolve and return the loader instance before finalizing the trace.
68- setTimeout ( async ( ) => {
69- const success = await fileReader . read ( loader ) ;
70- if ( ! success && fileReader . error ( ) ) {
71- // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
72- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73- loader . reportErrorAndCancelLoading ( ( fileReader . error ( ) as any ) . message ) ;
74- }
75- } ) ;
76- return loader ;
77- }
78-
7953 static loadFromParsedJsonFile ( contents : ParsedJSONFile , client : Client ) : TimelineLoader {
8054 const loader = new TimelineLoader ( client ) ;
8155
@@ -224,42 +198,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
224198 }
225199 }
226200
227- /**
228- * As TimelineLoader implements `Common.StringOutputStream.OutputStream`, `write()` is called when a
229- * Common.StringOutputStream.StringOutputStream instance has decoded a chunk. This path is only used
230- * by `loadFromFile()`; it's NOT used by `loadFromEvents` or `loadFromURL`.
231- */
232- async write ( chunk : string , endOfFile : boolean ) : Promise < void > {
233- if ( ! this . client ) {
234- return await Promise . resolve ( ) ;
235- }
236- this . buffer += chunk ;
237- if ( this . firstRawChunk ) {
238- this . client . loadingStarted ( ) ;
239- // Ensure we paint the loading dialog before continuing
240- await new Promise ( resolve => requestAnimationFrame ( ( ) => requestAnimationFrame ( resolve ) ) ) ;
241- this . firstRawChunk = false ;
242- } else {
243- let progress = undefined ;
244- progress = this . buffer . length / this . totalSize ;
245- // For compressed traces, we can't provide a definite progress percentage. So, just keep it moving.
246- // For other traces, calculate a loaded part.
247- progress = progress > 1 ? progress - Math . floor ( progress ) : progress ;
248- this . client . loadingProgress ( progress ) ;
249- }
250-
251- if ( endOfFile ) {
252- let trace ;
253- try {
254- trace = JSON . parse ( this . buffer ) as ParsedJSONFile ;
255- this . #processParsedFile( trace ) ;
256- } catch ( e ) {
257- this . reportErrorAndCancelLoading ( i18nString ( UIStrings . malformedTimelineDataS , { PH1 : e . toString ( ) } ) ) ;
258- }
259- return ;
260- }
261- }
262-
263201 private reportErrorAndCancelLoading ( message ?: string ) : void {
264202 if ( message ) {
265203 Common . Console . Console . instance ( ) . error ( message ) ;
0 commit comments