1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 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
8<link rel="import" href="/tracing/model/event_set.html">
9
10<script>
11'use strict';
12
13tr.exportTo('tr.ui.analysis', function() {
14  var FLOW_IN = 0x1;
15  var FLOW_OUT = 0x2;
16  var FLOW_IN_OUT = FLOW_IN | FLOW_OUT;
17
18  function FlowClassifier() {
19    this.numEvents_ = 0;
20    this.eventsByGUID_ = {};
21  }
22
23  FlowClassifier.prototype = {
24    getFS_: function(event) {
25      var fs = this.eventsByGUID_[event.guid];
26      if (fs === undefined) {
27        this.numEvents_++;
28        fs = {
29          state: 0,
30          event: event
31        };
32        this.eventsByGUID_[event.guid] = fs;
33      }
34      return fs;
35    },
36
37    addInFlow: function(event) {
38      var fs = this.getFS_(event);
39      fs.state |= FLOW_IN;
40      return event;
41    },
42
43    addOutFlow: function(event) {
44      var fs = this.getFS_(event);
45      fs.state |= FLOW_OUT;
46      return event;
47    },
48
49    hasEvents: function() {
50      return this.numEvents_ > 0;
51    },
52
53    get inFlowEvents() {
54      var selection = new tr.model.EventSet();
55      for (var guid in this.eventsByGUID_) {
56        var fs = this.eventsByGUID_[guid];
57        if (fs.state === FLOW_IN)
58          selection.push(fs.event);
59      }
60      return selection;
61    },
62
63    get outFlowEvents() {
64      var selection = new tr.model.EventSet();
65      for (var guid in this.eventsByGUID_) {
66        var fs = this.eventsByGUID_[guid];
67        if (fs.state === FLOW_OUT)
68          selection.push(fs.event);
69      }
70      return selection;
71    },
72
73    get internalFlowEvents() {
74      var selection = new tr.model.EventSet();
75      for (var guid in this.eventsByGUID_) {
76        var fs = this.eventsByGUID_[guid];
77        if (fs.state === FLOW_IN_OUT)
78          selection.push(fs.event);
79      }
80      return selection;
81    }
82  };
83
84  return {
85    FlowClassifier: FlowClassifier
86  };
87});
88</script>
89
90