1// Copyright (C) 2018 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {raf} from '../core/raf_scheduler'; 16import {AppImpl} from '../core/app_impl'; 17 18/** 19 * Global accessors for state/dispatch in the frontend. 20 */ 21class Globals { 22 // This is normally undefined is injected in via is_internal_user.js. 23 // WARNING: do not change/rename/move without considering impact on the 24 // internal_user script. 25 private _isInternalUser: boolean | undefined = undefined; 26 27 // WARNING: do not change/rename/move without considering impact on the 28 // internal_user script. 29 get extraSqlPackages() { 30 return AppImpl.instance.extraSqlPackages; 31 } 32 33 // This variable is set by the is_internal_user.js script if the user is a 34 // googler. This is used to avoid exposing features that are not ready yet 35 // for public consumption. The gated features themselves are not secret. 36 // If a user has been detected as a Googler once, make that sticky in 37 // localStorage, so that we keep treating them as such when they connect over 38 // public networks. 39 get isInternalUser() { 40 if (this._isInternalUser === undefined) { 41 this._isInternalUser = localStorage.getItem('isInternalUser') === '1'; 42 } 43 return this._isInternalUser; 44 } 45 46 set isInternalUser(value: boolean) { 47 localStorage.setItem('isInternalUser', value ? '1' : '0'); 48 this._isInternalUser = value; 49 raf.scheduleFullRedraw(); 50 } 51 52 // Used when switching to the legacy TraceViewer UI. 53 // Most resources are cleaned up by replacing the current |window| object, 54 // however pending RAFs and workers seem to outlive the |window| and need to 55 // be cleaned up explicitly. 56 shutdown() { 57 raf.shutdown(); 58 } 59} 60 61export const globals = new Globals(); 62