Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServerTimingParser.js

Issue 1794783006: Add Server-Timing support to devtools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2016 Steven Roussey. All rights reserved.
pfeldman 2016/03/14 22:54:34 Could you use a new 3 line header style? Also, yo
3 * Copyright (C) 2016 The Chromium Authors. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /**
33 * @constructor
34 * @param {!WebInspector.Target} target
35 */
36 WebInspector.ServerTimingParser = function(target)
37 {
38 this._target = target;
39 }
40
41 WebInspector.ServerTimingParser.prototype = {
42 /**
43 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers
44 * @return {?Array.<!WebInspector.ServerTiming>}
45 */
46 parseHeaders: function(headers)
47 {
48 if (!this._initialize(headers))
49 return null;
50
51 this._serverTimings = this._headers.map(item => this._extractMetric(item .value), this).filter(item => item);
pfeldman 2016/03/14 22:54:34 This is hard to read - it might be easier to imple
52 return this._serverTimings;
53 },
54
55 /**
56 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers
57 * @return {boolean}
58 */
59 _initialize: function(headers)
60 {
61 this._headers = headers.filter(item => item.name.toLowerCase() == 'serve r-timing');
pfeldman 2016/03/14 22:54:34 == -> ===
62 if (this._headers.length == 0)
63 return false;
64
65 this._headers.sort((a, b) => a.value.toLowerCase().compareTo(b.value.toL owerCase()));
pfeldman 2016/03/14 22:54:35 Why do you have to sort it?
sroussey 2016/04/22 00:55:08 Related to a my experience writing a Server-Timing
66 return true;
67 },
68
69 /**
70 * @param {string} valueString
71 * @return {?WebInspector.ServerTiming}
72 */
73 _extractMetric: function(valueString)
74 {
75 if (valueString == '')
76 return null;
77 var metricMatch = /\s*(\w+)\s*=\s*(\d+(?:\.\d+)?)\s*(?:;\s*(?:"(.*)"|(.* )))\s*/.exec(valueString);
78 if (!metricMatch) {
79 console.log("Failed parsing server-timing metric: ", valueString);
80 return null;
81 }
82
83 var result = new WebInspector.ServerTiming(this._target, metricMatch[1], parseFloat(metricMatch[2]), metricMatch[3] || metricMatch[4]);
84 return result;
85 }
86 };
87
88 /**
89 * @param {!WebInspector.Target} target
90 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers
91 * @return {?Array.<!WebInspector.ServerTiming>}
92 */
93 WebInspector.ServerTimingParser.parseHeaders = function(target, headers)
94 {
95 return (new WebInspector.ServerTimingParser(target)).parseHeaders(headers);
96 }
97
98 /**
99 * @constructor
100 * @param {!WebInspector.Target} target
101 * @param {string} metric
102 * @param {number} value
103 * @param {string} description
104 */
105 WebInspector.ServerTiming = function(target, metric, value, description)
106 {
107 this._target = target;
108 this.metric = metric;
109 this.value = value;
110 this.description = description;
111 }
112
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698