Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / event.html
index 3b47a36..b29efb6 100644 (file)
@@ -5,7 +5,7 @@ Use of this source code is governed by a BSD-style license that can be
 found in the LICENSE file.
 -->
 
-<link rel="import" href="/tvcm/guid.html">
+<link rel="import" href="/base/guid.html">
 
 <script>
 'use strict';
@@ -13,7 +13,7 @@ found in the LICENSE file.
 /**
  * @fileoverview Provides the Event class.
  */
-tvcm.exportTo('tracing.trace_model', function() {
+tv.exportTo('tracing.trace_model', function() {
 
   /**
    * The SelectionState enum defines how Events are displayed in the view.
@@ -25,6 +25,27 @@ tvcm.exportTo('tracing.trace_model', function() {
     DIMMED: 3
   };
 
+  // Cached values for getCategoryParts.
+  var categoryPartsFor = {};
+
+  /**
+   * Categories are stored in comma-separated form, e.g: 'a,b' meaning
+   * that the event is part of the a and b category.
+   *
+   * This function returns the category split by string, caching the
+   * array for performance.
+   *
+   * Do not mutate the returned array!!!!
+   */
+  function getCategoryParts(category) {
+    var parts = categoryPartsFor[category];
+    if (parts !== undefined)
+      return parts;
+    parts = category.split(',');
+    categoryPartsFor[category] = parts;
+    return parts;
+  }
+
   /**
    * An Event is the base type for any non-container, selectable piece
    * of data in the trace model.
@@ -32,7 +53,7 @@ tvcm.exportTo('tracing.trace_model', function() {
    * @constructor
    */
   function Event() {
-    this.guid_ = tvcm.GUID.allocate();
+    this.guid_ = tv.GUID.allocate();
     this.selectionState = SelectionState.NONE;
   }
 
@@ -46,6 +67,48 @@ tvcm.exportTo('tracing.trace_model', function() {
     }
   };
 
+  Event.decorateSubtype = function(baseConstructor) {
+    if (baseConstructor.register !== undefined ||
+        baseConstructor.unregister !== undefined ||
+        baseConstructor.getConstructor !== undefined) {
+      throw new Error('Already decorated: ' + baseConstructor);
+    }
+
+    baseConstructor.categoryToConstructorMap_ = {};
+    baseConstructor.nameToConstructorMap_ = {};
+
+    baseConstructor.register = function(name, constructor) {
+      if (baseConstructor.nameToConstructorMap_[name])
+        throw new Error('Constructor already registered for ' + name);
+      baseConstructor.nameToConstructorMap_[name] = constructor;
+    };
+
+    baseConstructor.unregister = function(name) {
+      delete baseConstructor.nameToConstructorMap_[name];
+    };
+
+    baseConstructor.registerCategory = function(category, constructor) {
+      if (baseConstructor.categoryToConstructorMap_[category])
+        throw new Error('Constructor already registered for ' + category);
+      baseConstructor.categoryToConstructorMap_[category] = constructor;
+    };
+    baseConstructor.unregisterCategory = function(category, constructor) {
+      delete baseConstructor.categoryToConstructorMap_[category];
+    };
+
+    baseConstructor.getConstructor = function(category, name) {
+      var categoryParts = getCategoryParts(category);
+      for (var i = 0; i < categoryParts.length; i++) {
+        var categoryPart = categoryParts[i];
+        if (baseConstructor.categoryToConstructorMap_[categoryPart])
+          return baseConstructor.categoryToConstructorMap_[categoryPart];
+      }
+      if (baseConstructor.nameToConstructorMap_[name])
+        return baseConstructor.nameToConstructorMap_[name];
+      return baseConstructor;
+    };
+  };
+
   return {
     Event: Event,
     SelectionState: SelectionState