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

Unified 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: fixed eval 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dashboard/ui/endure_js/coordinates.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/ui/endure_js/common.js
diff --git a/dashboard/ui/endure_js/common.js b/dashboard/ui/endure_js/common.js
new file mode 100644
index 0000000000000000000000000000000000000000..88136b32c1ba0a9bb5849b21c3c771cd65c2d713
--- /dev/null
+++ b/dashboard/ui/endure_js/common.js
@@ -0,0 +1,87 @@
+/*
+ Copyright (c) 2012 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.
+*/
+
+/**
+ * @fileoverview Common methods for performance-plotting Javascript.
+ */
+
+/**
+ * Fetches a URL asynchronously and invokes a callback when complete.
+ *
+ * @param {string} url URL to fetch.
+ * @param {Function(string, ?string)} callback The function to invoke when the
+ * results of the URL fetch are complete. The function should accept two
+ * strings representing the URL data, and any errors, respectively.
+ */
+function Fetch(url, callback) {
+ var r = new XMLHttpRequest();
+ r.open('GET', url, true);
+ r.setRequestHeader('pragma', 'no-cache');
+ r.setRequestHeader('cache-control', 'no-cache');
+
+ r.onreadystatechange = function() {
+ if (r.readyState == 4) {
+ var text = r.responseText;
+ var error = null;
+ if (r.status != 200)
+ error = url + ': ' + r.status + ': ' + r.statusText;
+ else if (!text)
+ error = url + ': null response';
+ callback(text, error);
+ }
+ }
+
+ r.send(null);
+}
+
+/**
+ * Parses the parameters of the current page's URL.
+ *
+ * @return {Object.<string, (string|number)>} An object with properties given
+ * by the parameters specified in the URL's query string.
+ */
+function ParseParams() {
+ var result = {};
+
+ var query = window.location.search.substring(1);
+ if (query.slice(-1) == '/') {
+ query = query.slice(0, -1); // Strip trailing slash.
+ }
+ var s = query.split('&');
+
+ for (i = 0; i < s.length; ++i) {
+ var v = s[i].split('=');
+ var key = v[0];
+ var value = unescape(v[1]);
+ result[key] = value;
+ }
+
+ if ('history' in result) {
+ result['history'] = parseInt(result['history']);
+ result['history'] = Math.max(result['history'], 2);
+ }
+ if ('rev' in result) {
+ result['rev'] = parseInt(result['rev']);
+ }
+
+ return result;
+}
+
+/**
+ * Creates the URL constructed from the current pathname and the given params.
+ *
+ * @param {Object.<string, (string|number)>} params An object containing
+ * parameters for a URL query string.
+ * @return {string} The URL constructed from the given params.
+ */
+function MakeURL(params) {
+ var key_values = [];
+ for (key in params) {
+ // better to sanitize key here.
+ key_values.push(key + '=' + encodeURIComponent(params[key]));
+ }
+ return window.location.pathname + '?' + key_values.join('&');
+}
« no previous file with comments | « no previous file | dashboard/ui/endure_js/coordinates.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698