1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7<link rel="import" href="/tracing/base/iteration_helpers.html"> 8<link rel="import" href="/tracing/base/event_target.html"> 9<link rel="import" href="/tracing/base/extension_registry_basic.html"> 10<link rel="import" href="/tracing/base/extension_registry_type_based.html"> 11<script> 12'use strict'; 13 14/** 15 * @fileoverview Helper code for defining extension registries, which can be 16 * used to make a part of trace-viewer extensible. 17 * 18 * This file provides two basic types of extension registries: 19 * - Generic: register a type with metadata, query for those types based on 20 * a predicate 21 * 22 * - TypeName-based: register a type that handles some combination 23 * of tracing categories or typeNames, then query 24 * for it based on a category, typeName or both. 25 * 26 * Use these for pure-JS classes or ui.define'd classes. For polymer element 27 * related registries, consult base/polymer_utils.html. 28 * 29 * When you register subtypes, you pass the constructor for the 30 * subtype, and any metadata you want associated with the subtype. Use metadata 31 * instead of stuffing fields onto the constructor. E.g.: 32 * registry.register(MySubclass, {titleWhenShownInTabStrip: 'MySub'}) 33 * 34 * Some registries want a default object that is returned when a more precise 35 * subtype has been registered. To provide one, set the defaultConstructor 36 * option on the registry options. 37 * 38 * TODO: Extension registry used to make reference to mandatoryBaseType but it 39 * was never enforced. We may want to add it back in the future in order to 40 * enforce the types that can be put into a given registry. 41 */ 42tr.exportTo('tr.b', function() { 43 44 function decorateExtensionRegistry(registry, registryOptions) { 45 if (registry.register) 46 throw new Error('Already has registry'); 47 48 registryOptions.freeze(); 49 if (registryOptions.mode == tr.b.BASIC_REGISTRY_MODE) { 50 tr.b._decorateBasicExtensionRegistry(registry, registryOptions); 51 } else if (registryOptions.mode == tr.b.TYPE_BASED_REGISTRY_MODE) { 52 tr.b._decorateTypeBasedExtensionRegistry(registry, registryOptions); 53 } else { 54 throw new Error('Unrecognized mode'); 55 } 56 57 // Make it an event target. 58 if (registry.addEventListener === undefined) 59 tr.b.EventTarget.decorate(registry); 60 } 61 62 return { 63 decorateExtensionRegistry: decorateExtensionRegistry 64 }; 65}); 66</script> 67