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

Side by Side Diff: dashboard/ui/endure_js/common.js

Issue 12094074: Support Chrome Endure graphs in perf dashboard. (Closed) Base URL: https://git.chromium.org/git/chromium/tools/perf.git@master
Patch Set: addressed the comments. Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 */
6
7 /**
8 * @fileoverview Common methods for performance-plotting Javascript.
9 */
10
11 /**
12 * Fetches a URL asynchronously and invokes a callback when complete.
13 *
14 * @param {string} url URL to fetch.
15 * @param {Function(string, ?string)} callback The function to invoke when the
16 * results of the URL fetch are complete. The function should accept two
17 * strings representing the URL data, and any errors, respectively.
18 */
19 function Fetch(url, callback) {
20 var r = new XMLHttpRequest();
21 r.open('GET', url, true);
22 r.setRequestHeader('pragma', 'no-cache');
23 r.setRequestHeader('cache-control', 'no-cache');
24
25 r.onreadystatechange = function() {
26 if (r.readyState == 4) {
27 var text = r.responseText;
28 var error = null;
29 if (r.status != 200)
30 error = url + ': ' + r.status + ': ' + r.statusText;
31 else if (!text)
32 error = url + ': null response';
33 callback(text, error);
34 }
35 }
36
37 r.send(null);
38 }
39
40 /**
41 * Parses the parameters of the current page's URL.
42 *
43 * @return {Object.<string, (string|number)>} An object with properties given
44 * by the parameters specified in the URL's query string.
45 */
46 function ParseParams() {
47 var result = {};
48
49 var query = window.location.search.substring(1);
50 if (query.slice(-1) == '/') {
51 query = query.slice(0, -1); // Strip trailing slash.
52 }
53 var s = query.split('&');
54
55 for (i = 0; i < s.length; ++i) {
56 var v = s[i].split('=');
57 var key = v[0];
58 var value = unescape(v[1]);
59 result[key] = value;
60 }
61
62 if ('history' in result) {
63 result['history'] = parseInt(result['history']);
64 result['history'] = Math.max(result['history'], 2);
65 }
66 if ('rev' in result) {
67 result['rev'] = parseInt(result['rev']);
68 result['rev'] = Math.max(result['rev'], -1);
69 }
70
71 return result;
72 }
73
74 /**
75 * Creates the URL constructed from the current pathname and the given params.
76 *
77 * @param {Object.<string, (string|number)>} params An object containing
78 * parameters for a URL query string.
79 * @return {string} The URL constructed from the given params.
80 */
81 function MakeURL(params) {
82 var url = window.location.pathname;
83 var sep = '?';
84 for (p in params) {
85 if (!p)
86 continue;
87 url += sep + p + '=' + params[p];
88 sep = '&';
89 }
90 return url;
91 }
OLDNEW
« no previous file with comments | « no previous file | dashboard/ui/endure_js/coordinates.js » ('j') | dashboard/ui/endure_js/endure_plotter.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698