1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {Store} from 'common/store'; 18import {WinscopeEvent} from 'messaging/winscope_event'; 19import {EmitEvent} from 'messaging/winscope_event_emitter'; 20import {Trace} from 'trace/trace'; 21import {Traces} from 'trace/traces'; 22import {TRACE_INFO} from 'trace/trace_info'; 23import {TraceType} from 'trace/trace_type'; 24import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 25import {View, Viewer, ViewType} from 'viewers/viewer'; 26import {Presenter} from './presenter'; 27import {UiData} from './ui_data'; 28 29class ViewerTransactions implements Viewer { 30 static readonly DEPENDENCIES: TraceType[] = [TraceType.TRANSACTIONS]; 31 32 private readonly trace: Trace<PropertyTreeNode>; 33 private readonly htmlElement: HTMLElement; 34 private readonly presenter: Presenter; 35 private readonly view: View; 36 37 constructor(trace: Trace<PropertyTreeNode>, traces: Traces, storage: Store) { 38 this.trace = trace; 39 this.htmlElement = document.createElement('viewer-transactions'); 40 const notifyViewCallback = (data: UiData) => { 41 (this.htmlElement as any).inputData = data; 42 }; 43 this.presenter = new Presenter(trace, storage, notifyViewCallback); 44 this.presenter.addEventListeners(this.htmlElement); 45 46 this.view = new View( 47 ViewType.TRACE_TAB, 48 this.getTraces(), 49 this.htmlElement, 50 TRACE_INFO[TraceType.TRANSACTIONS].name, 51 ); 52 } 53 54 async onWinscopeEvent(event: WinscopeEvent) { 55 await this.presenter.onAppEvent(event); 56 } 57 58 setEmitEvent(callback: EmitEvent) { 59 this.presenter.setEmitEvent(callback); 60 } 61 62 getViews(): View[] { 63 return [this.view]; 64 } 65 66 getTraces(): Array<Trace<PropertyTreeNode>> { 67 return [this.trace]; 68 } 69} 70 71export {ViewerTransactions}; 72