3e38cba66122947da9e994a6c66b3ddd6607dc16
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / filter.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7 <link rel="import" href="/tvcm.html">
8 <script>
9 'use strict';
10
11 tvcm.exportTo('tracing', function() {
12   /**
13    * @constructor The generic base class for filtering a TraceModel based on
14    * various rules. The base class returns true for everything.
15    */
16   function Filter() { }
17
18   Filter.prototype = {
19     __proto__: Object.prototype,
20
21     matchCounter: function(counter) {
22       return true;
23     },
24
25     matchCpu: function(cpu) {
26       return true;
27     },
28
29     matchProcess: function(process) {
30       return true;
31     },
32
33     matchSlice: function(slice) {
34       return true;
35     },
36
37     matchThread: function(thread) {
38       return true;
39     }
40   };
41
42   /**
43    * @constructor A filter that matches objects by their name case insensitive.
44    * .findAllObjectsMatchingFilter
45    */
46   function TitleFilter(text) {
47     Filter.call(this);
48     this.text_ = text.toLowerCase();
49
50     if (!text.length)
51       throw new Error('Filter text is empty.');
52   }
53   TitleFilter.prototype = {
54     __proto__: Filter.prototype,
55
56     matchSlice: function(slice) {
57       if (slice.title === undefined)
58         return false;
59       return slice.title.toLowerCase().indexOf(this.text_) !== -1;
60     }
61   };
62
63   /**
64    * @constructor A filter that matches objects with the exact given title.
65    */
66   function ExactTitleFilter(text) {
67     Filter.call(this);
68     this.text_ = text;
69
70     if (!text.length)
71       throw new Error('Filter text is empty.');
72   }
73   ExactTitleFilter.prototype = {
74     __proto__: Filter.prototype,
75
76     matchSlice: function(slice) {
77       return slice.title === this.text_;
78     }
79   };
80
81   return {
82     TitleFilter: TitleFilter,
83     ExactTitleFilter: ExactTitleFilter
84   };
85 });
86 </script>