| OLD | NEW | 
|   1 <!DOCTYPE html> |   1 <!DOCTYPE html> | 
|   2 <!-- |   2 <!-- | 
|   3 Copyright 2016 The Chromium Authors. All rights reserved. |   3 Copyright 2016 The Chromium Authors. All rights reserved. | 
|   4 Use of this source code is governed by a BSD-style license that can be |   4 Use of this source code is governed by a BSD-style license that can be | 
|   5 found in the LICENSE file. |   5 found in the LICENSE file. | 
|   6 --> |   6 --> | 
|   7 <link rel="import" href="/tracing/base/base.html"> |   7 <link rel="import" href="/tracing/base/base.html"> | 
|   8 <link rel="import" href="/tracing/base/extension_registry.html"> |   8 <link rel="import" href="/tracing/base/extension_registry.html"> | 
|   9 <link rel="import" href="/tracing/base/iteration_helpers.html"> |   9 <link rel="import" href="/tracing/base/iteration_helpers.html"> | 
|  10  |  10  | 
|  11 <script> |  11 <script> | 
|  12 'use strict'; |  12 'use strict'; | 
|  13  |  13  | 
|  14 tr.exportTo('tr.metrics', function() { |  14 tr.exportTo('tr.metrics', function() { | 
|  15   function MetricRegistry() {} |  15   function MetricRegistry() {} | 
|  16  |  16  | 
|  17   var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE); |  17   var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE); | 
|  18   options.defaultMetadata = {}; |  18   options.defaultMetadata = {}; | 
|  19   tr.b.decorateExtensionRegistry(MetricRegistry, options); |  19   tr.b.decorateExtensionRegistry(MetricRegistry, options); | 
|  20  |  20  | 
|  21   MetricRegistry.addEventListener('will-register', function(e) { |  21   MetricRegistry.addEventListener('will-register', function(e) { | 
|  22     var metric = e.typeInfo.constructor; |  22     var metric = e.typeInfo.constructor; | 
|  23     if (!(metric instanceof Function)) |  23     var metadata = e.typeInfo.metadata; | 
 |  24  | 
 |  25     if (!(metric instanceof Function)) { | 
|  24       throw new Error('Metrics must be functions'); |  26       throw new Error('Metrics must be functions'); | 
 |  27     } | 
|  25  |  28  | 
|  26     if (metric.length < 2) { |  29     if (metric.length < 2) { | 
|  27       throw new Error('Metrics take a HistogramSet and a Model and ' + |  30       throw new Error('Metrics take a HistogramSet and a Model and ' + | 
|  28                       'optionally an options dictionary'); |  31                       'optionally an options dictionary'); | 
|  29     } |  32     } | 
 |  33  | 
 |  34     if (!(metadata.histogramNames instanceof Set)) { | 
 |  35       throw new Error('Metrics must register the set of Histogram names ' + | 
 |  36           'that they may produce'); | 
 |  37     } | 
 |  38  | 
 |  39     for (var typeInfo of MetricRegistry.getAllRegisteredTypeInfos()) { | 
 |  40       for (var name of metadata.histogramNames) { | 
 |  41         if (typeInfo.metadata.histogramNames.has(name)) { | 
 |  42           throw new Error('Multiple metrics cannot produce Histograms ' + | 
 |  43               'with the same name: ' + name + ' ' + metric.name + ' ' + | 
 |  44               typeInfo.constructor.name); | 
 |  45         } | 
 |  46       } | 
 |  47     } | 
|  30   }); |  48   }); | 
|  31  |  49  | 
|  32   return { |  50   return { | 
|  33     MetricRegistry, |  51     MetricRegistry, | 
|  34   }; |  52   }; | 
|  35 }); |  53 }); | 
|  36 </script> |  54 </script> | 
| OLD | NEW |