| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/tracing/base/guid.html"> |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('pi.v', function() { |
| // This value must stay sync'd with the constant of the same name |
| // in runInfo.py. |
| var PI_VALUE_RUN_INFO_ID = 'perf_insights.value.RunInfo'; |
| |
| function RunInfo(url, opt_displayName, opt_runId, opt_metadata) { |
| if (opt_runId !== undefined) |
| this.runId = opt_runId; |
| else |
| this.runId = 'pi.v.RunInfo-' + tr.b.GUID.allocate(); |
| this.url = url; |
| |
| if (opt_displayName !== undefined) |
| this.displayName = opt_displayName; |
| else |
| this.displayName = this.url; |
| |
| if (opt_metadata !== undefined) |
| this.metadata = opt_metadata; |
| else |
| this.metadata = {}; |
| } |
| |
| RunInfo.fromDict = function(d) { |
| if (d.type !== PI_VALUE_RUN_INFO_ID) |
| throw new Error('Unsupported runInfo format: ' + d.type); |
| if (d.run_id === undefined) |
| throw new Error('Must contain run_id'); |
| if (d.url === undefined) |
| throw new Error('Must contain url'); |
| return new RunInfo(d.url, d.display_name, d.run_id, d.metadata); |
| }; |
| |
| RunInfo.prototype = { |
| asDict: function() { |
| var d = { |
| type: PI_VALUE_RUN_INFO_ID, |
| run_id: this.runId, |
| url: this.url, |
| metadata: this.metadata |
| }; |
| if (this.displayName !== this.url) |
| d.display_name = this.displayName; |
| return d; |
| } |
| }; |
| |
| return { |
| RunInfo: RunInfo |
| }; |
| }); |
| </script> |