1/* 2 * Copyright (C) 2024 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 {QueryResult} from 'trace_processor/query_result'; 25import {View, Viewer, ViewType} from 'viewers/viewer'; 26import {Presenter} from './presenter'; 27import {UiData} from './ui_data'; 28import {ViewerSearchComponent} from './viewer_search_component'; 29 30export class ViewerSearch implements Viewer { 31 static readonly DEPENDENCIES: TraceType[] = [TraceType.SEARCH]; 32 33 private readonly htmlElement: HTMLElement; 34 private readonly presenter: Presenter; 35 private readonly traces: Traces; 36 private readonly view: View; 37 38 constructor(traces: Traces, storage: Store) { 39 this.htmlElement = document.createElement('viewer-search'); 40 const notifyViewCallback = (data: UiData) => { 41 (this.htmlElement as unknown as ViewerSearchComponent).inputData = data; 42 }; 43 this.presenter = new Presenter(traces, storage, notifyViewCallback); 44 this.presenter.addEventListeners(this.htmlElement); 45 this.traces = traces; 46 this.view = new View( 47 ViewType.GLOBAL_SEARCH, 48 this.getTraces(), 49 this.htmlElement, 50 TRACE_INFO[TraceType.SEARCH].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<QueryResult>> { 67 return this.traces.getTraces(TraceType.SEARCH); 68 } 69} 70