Commit f43f03fe authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Revert "SuperSize: Fix missing access token for diffs"

This reverts commit a26b32ce.

Reason for revert: Missed an "await"

Original change's description:
> SuperSize: Fix missing access token for diffs
> 
> Also:
> * Throws a more explicit exception for failed fetch.
> * Stops setting Cache-Control: no-cache
> 
> Bug: None
> Change-Id: I380207b32497f1cb5467ff62bcd3c857dc03ff58
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418799
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Auto-Submit: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Mohamed Heikal <mheikal@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#808406}

TBR=agrieve@chromium.org,mheikal@chromium.org

Change-Id: I0a264d02d6066034e9eb23c854520c0e1c55672f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: None
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419122Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808441}
parent 0ae19723
...@@ -28,15 +28,10 @@ const _NAMES_TO_FLAGS = Object.freeze({ ...@@ -28,15 +28,10 @@ const _NAMES_TO_FLAGS = Object.freeze({
* Wrapper around fetch for requesting the same resource multiple times. * Wrapper around fetch for requesting the same resource multiple times.
*/ */
class DataFetcher { class DataFetcher {
constructor(accessToken) { constructor(input) {
/** @type {string | null} */
this._accessToken = accessToken;
/** @type {AbortController | null} */ /** @type {AbortController | null} */
this._controller = null; this._controller = null;
/** @type {string | null} */ this.setInput(input);
this._input = null;
/** @type {Uint8Array | null} */
this._cache = null;
} }
/** /**
...@@ -44,15 +39,26 @@ class DataFetcher { ...@@ -44,15 +39,26 @@ class DataFetcher {
* @param {string | Request} input URL to the resource you want to fetch. * @param {string | Request} input URL to the resource you want to fetch.
*/ */
setInput(input) { setInput(input) {
if (this._input && this._input.startsWith('blob:')) { if (typeof this._input === 'string' && this._input.startsWith('blob:')) {
// Revoke the previous Blob url to prevent memory leaks // Revoke the previous Blob url to prevent memory leaks
URL.revokeObjectURL(this._input); URL.revokeObjectURL(this._input);
} }
/** @type {Uint8Array | null} */
this._cache = null; this._cache = null;
this._input = input; this._input = input;
} }
/**
* Sets the access token to be used for authenticated requests. If accessToken
* is non-null and the URL is a google storage URL, an authenticated request
* is performed instead.
* @param {?string} accessToken
*/
setAccessToken(accessToken) {
this._accessToken = accessToken;
}
/** /**
* Starts a new request and aborts the previous one. * Starts a new request and aborts the previous one.
* @param {string | Request} url * @param {string | Request} url
...@@ -80,15 +86,12 @@ class DataFetcher { ...@@ -80,15 +86,12 @@ class DataFetcher {
if (!headers) { if (!headers) {
headers = new Headers(); headers = new Headers();
} }
let response = fetch(url, { headers.append('cache-control', 'no-cache');
return fetch(url, {
headers, headers,
credentials: 'same-origin', credentials: 'same-origin',
signal: this._controller.signal, signal: this._controller.signal,
}); });
if (!response.ok) {
throw new Error('Fetch failed.');
}
return response;
} }
/** /**
...@@ -132,7 +135,8 @@ async function Open(name) { ...@@ -132,7 +135,8 @@ async function Open(name) {
}); });
} }
let g_fetcher = null; // Placeholder input name until supplied via setInput()
const g_fetcher = new DataFetcher('data.ndjson');
let g_beforeFetcher = null; let g_beforeFetcher = null;
let g_sizeFileLoaded = false; let g_sizeFileLoaded = false;
...@@ -177,12 +181,7 @@ async function buildTree( ...@@ -177,12 +181,7 @@ async function buildTree(
if (g_beforeFetcher !== null) { if (g_beforeFetcher !== null) {
load_promises.push(loadSizeFile(true, g_beforeFetcher)); load_promises.push(loadSizeFile(true, g_beforeFetcher));
} }
try { await Promise.all(load_promises).then(loadSizeProperties);
await Promise.all(load_promises).then(loadSizeProperties);
} catch (e) {
onProgress({percent: 1, id: 0});
throw e;
}
onProgress({percent: 0.4, id: 0}); onProgress({percent: 0.4, id: 0});
g_sizeFileLoaded = true; g_sizeFileLoaded = true;
} }
...@@ -269,8 +268,8 @@ const actions = { ...@@ -269,8 +268,8 @@ const actions = {
url, url,
beforeUrl, beforeUrl,
} = parseOptions(options); } = parseOptions(options);
if (!g_fetcher) { if (accessToken) {
g_fetcher = new DataFetcher(accessToken); g_fetcher.setAccessToken(accessToken);
} }
if (input === 'from-url://' && url) { if (input === 'from-url://' && url) {
// Display the data from the `load_url` query parameter // Display the data from the `load_url` query parameter
...@@ -282,8 +281,7 @@ const actions = { ...@@ -282,8 +281,7 @@ const actions = {
} }
if (beforeUrl) { if (beforeUrl) {
g_beforeFetcher = new DataFetcher(accessToken); g_beforeFetcher = new DataFetcher(beforeUrl);
g_beforeFetcher.setInput(beforeUrl);
} }
return buildTree( return buildTree(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment