Home | History | Annotate | Download | only in analysis
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('ui');
      8 
      9 base.exportTo('tracing.analysis', function() {
     10   /**
     11    * Slice views allow customized visualization of specific slices, indexed by
     12    * title. If not registered, the default slice viewing logic is used.
     13    *
     14    * @constructor
     15    */
     16   var SliceView = ui.define('slice-view');
     17 
     18   SliceView.prototype = {
     19     __proto__: HTMLDivElement.prototype,
     20 
     21     decorate: function() {
     22       this.objectInstance_ = undefined;
     23     },
     24 
     25     set modelObject(obj) {
     26       this.slice = obj;
     27     },
     28 
     29     get modelObject() {
     30       return this.slice;
     31     },
     32 
     33     get slice() {
     34       return this.slice_;
     35     },
     36 
     37     set slice(s) {
     38       this.slice_ = s;
     39       this.updateContents();
     40     },
     41 
     42     updateContents: function() {
     43       throw new Error('Not implemented');
     44     }
     45   };
     46 
     47   SliceView.titleToViewInfoMap = {};
     48   SliceView.register = function(title, viewConstructor) {
     49     if (SliceView.titleToViewInfoMap[title])
     50       throw new Error('Handler already registerd for ' + title);
     51     SliceView.titleToViewInfoMap[title] = {
     52       constructor: viewConstructor
     53     };
     54   };
     55 
     56   SliceView.unregister = function(title) {
     57     if (SliceView.titleToViewInfoMap[title] === undefined)
     58       throw new Error(title + ' not registered');
     59     delete SliceView.titleToViewInfoMap[title];
     60   };
     61 
     62   SliceView.getViewInfo = function(title) {
     63     return SliceView.titleToViewInfoMap[title];
     64   };
     65 
     66   return {
     67     SliceView: SliceView
     68   };
     69 });
     70