@@ -23,10 +23,10 @@ import {PluginManager} from './plugin_manager';
2323import { NewEngineMode } from '../trace_processor/engine' ;
2424import { RouteArgs } from '../public/route_schema' ;
2525import { SqlPackage } from '../public/extra_sql_packages' ;
26-
27- // The pseudo plugin id used for the core instance of AppImpl.
28-
29- export const CORE_PLUGIN_ID = '__core__ ';
26+ import { SerializedAppState } from '../public/state_serialization_schema' ;
27+ import { PostedTrace , TraceSource } from '../public/trace_source' ;
28+ import { loadTrace } from './load_trace' ;
29+ import { CORE_PLUGIN_ID } from './plugin_manager ';
3030
3131// The args that frontend/index.ts passes when calling AppImpl.initialize().
3232// This is to deal with injections that would otherwise cause circular deps.
@@ -160,6 +160,50 @@ export class AppImpl implements App {
160160 return this . appCtx . initialRouteArgs ;
161161 }
162162
163+ openTraceFromFile ( file : File ) : void {
164+ this . openTrace ( { type : 'FILE' , file} ) ;
165+ }
166+
167+ openTraceFromUrl ( url : string , serializedAppState ?: SerializedAppState ) {
168+ this . openTrace ( { type : 'URL' , url, serializedAppState} ) ;
169+ }
170+
171+ openTraceFromBuffer ( postMessageArgs : PostedTrace ) : void {
172+ this . openTrace ( { type : 'ARRAY_BUFFER' , ...postMessageArgs } ) ;
173+ }
174+
175+ openTraceFromHttpRpc ( ) : void {
176+ this . openTrace ( { type : 'HTTP_RPC' } ) ;
177+ }
178+
179+ private async openTrace ( src : TraceSource ) {
180+ assertTrue ( this . pluginId === CORE_PLUGIN_ID ) ;
181+ this . closeCurrentTrace ( ) ;
182+ this . appCtx . isLoadingTrace = true ;
183+ try {
184+ // loadTrace() in trace_loader.ts will do the following:
185+ // - Create a new engine.
186+ // - Pump the data from the TraceSource into the engine.
187+ // - Do the initial queries to build the TraceImpl object
188+ // - Call AppImpl.setActiveTrace(TraceImpl)
189+ // - Continue with the trace loading logic (track decider, plugins, etc)
190+ // - Resolve the promise when everything is done.
191+ await loadTrace ( this , src ) ;
192+ this . omnibox . reset ( /* focus= */ false ) ;
193+ // loadTrace() internally will call setActiveTrace() and change our
194+ // _currentTrace in the middle of its ececution. We cannot wait for
195+ // loadTrace to be finished before setting it because some internal
196+ // implementation details of loadTrace() rely on that trace to be current
197+ // to work properly (mainly the router hash uuid).
198+ } catch ( err ) {
199+ this . omnibox . showStatusMessage ( `${ err } ` ) ;
200+ throw err ;
201+ } finally {
202+ this . appCtx . isLoadingTrace = false ;
203+ raf . scheduleFullRedraw ( ) ;
204+ }
205+ }
206+
163207 closeCurrentTrace ( ) {
164208 // This method should be called only on the core instance, plugins don't
165209 // have access to openTrace*() methods.
@@ -190,13 +234,6 @@ export class AppImpl implements App {
190234 return this . appCtx . isLoadingTrace ;
191235 }
192236
193- // TODO(primiano): this is very temporary and will go away as soon as
194- // TraceController is turned into an async function.
195- setIsLoadingTrace ( loading : boolean ) {
196- this . appCtx . isLoadingTrace = loading ;
197- raf . scheduleFullRedraw ( ) ;
198- }
199-
200237 get rootUrl ( ) {
201238 return this . appCtx . initArgs . rootUrl ;
202239 }
0 commit comments