importer.html revision cef7893435aa41160dd1255c43cb8498279738cc
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/base.html">
8<link rel="import" href="/tracing/base/extension_registry.html">
9<script>
10'use strict';
11
12/**
13 * @fileoverview Base class for trace data importers.
14 */
15tr.exportTo('tr.importer', function() {
16  function Importer() { }
17
18  Importer.prototype = {
19    __proto__: Object.prototype,
20
21    get importerName() {
22      return 'Importer';
23    },
24
25    /**
26     * Called by the Model to check whether the importer type stores the actual
27     * trace data or just holds it as container for further extraction.
28     */
29    isTraceDataContainer: function() {
30      return false;
31    },
32
33    /**
34     * Called by the Model to extract one or more subtraces from the event data.
35     */
36    extractSubtraces: function() {
37      return [];
38    },
39
40    /**
41     * Called to import clock sync markers into the Model.
42     */
43    importClockSyncMarkers: function() {
44    },
45
46    /**
47     * Called to import events into the Model.
48     */
49    importEvents: function() {
50    },
51
52    /**
53     * Called to import sample data into the Model.
54     */
55    importSampleData: function() {
56    },
57
58    /**
59     * Called by the Model after all other importers have imported their
60     * events.
61     */
62    finalizeImport: function() {
63    }
64  };
65
66
67  var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE);
68  options.defaultMetadata = {};
69  options.mandatoryBaseClass = Importer;
70  tr.b.decorateExtensionRegistry(Importer, options);
71
72  Importer.findImporterFor = function(eventData) {
73    var typeInfo = Importer.findTypeInfoMatching(function(ti) {
74      return ti.constructor.canImport(eventData);
75    });
76    if (typeInfo)
77      return typeInfo.constructor;
78    return undefined;
79  };
80
81  return {
82    Importer: Importer
83  };
84});
85</script>
86