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

Unified Diff: chrome/browser/resources/offline_pages/offline_internals.js

Issue 2038963002: [Offline Pages] Link the internals page with the offline model and request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try to fix patch dependency #2 Created 4 years, 6 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
Index: chrome/browser/resources/offline_pages/offline_internals.js
diff --git a/chrome/browser/resources/offline_pages/offline_internals.js b/chrome/browser/resources/offline_pages/offline_internals.js
index 5b914782f0acfc283ac35f3056024ab499afcef4..1b7dd375f70a5155433ceccec66740fa5c0055e8 100644
--- a/chrome/browser/resources/offline_pages/offline_internals.js
+++ b/chrome/browser/resources/offline_pages/offline_internals.js
@@ -9,7 +9,6 @@ cr.define('offlineInternals', function() {
* @typedef {{
* onlineUrl: string,
* creationTime: number,
- * status: number,
* id: string,
* namespace: string,
* size: string,
@@ -32,9 +31,12 @@ cr.define('offlineInternals', function() {
*/
var SavePageRequest;
+ var currentStoredPagesData = null;
dewittj 2016/06/03 23:12:05 needs /** @type {...} */
chili 2016/06/09 22:29:16 Done.
+ var currentRequestQueueData = null;
+
/**
* Clear the specified table.
- * @param {string} tableId id of the table to clear.
+ * @param {string} tableId ID of the table to clear.
*/
function clearTable(tableId) {
dewittj 2016/06/03 23:12:05 nit: make this take an element, then pass it in;
chili 2016/06/09 22:29:16 Done.
$(tableId).textContent = '';
@@ -42,11 +44,13 @@ cr.define('offlineInternals', function() {
/**
* Fill stored pages table.
- * @param {HTMLElement} element A HTML element.
- * @param {!Array<OfflinePageItem>} data An array object representing
+ * @param {!Array<OfflinePageItem} data An array object representing
dewittj 2016/06/03 23:12:06 Missing ">"
chili 2016/06/09 22:29:16 Done.
* stored offline pages.
*/
- function fillStoredPages(element, data) {
+ function fillStoredPages(data) {
+ clearTable('stored-pages');
+ var element = $('stored-pages');
+
for (var i = 0; i < data.length; i++) {
var row = document.createElement('tr');
@@ -68,20 +72,23 @@ cr.define('offlineInternals', function() {
row.appendChild(cell);
cell = document.createElement('td');
- cell.textContent = data[i].size;
+ cell.textContent = Math.round(data[i].size / 1024);
row.appendChild(cell);
element.appendChild(row);
}
+ currentStoredPagesData = data;
}
/**
* Fill requests table.
- * @param {HTMLElement} element A HTML element.
* @param {!Array<SavePageRequest>} data An array object representing
* the request queue.
*/
- function fillRequestQueue(element, data) {
+ function fillRequestQueue(data) {
+ clearTable('request-queue');
+ var element = $('request-queue');
+
for (var i = 0; i < data.length; i++) {
var row = document.createElement('tr');
@@ -99,13 +106,15 @@ cr.define('offlineInternals', function() {
element.appendChild(row);
}
+ currentRequestQueueData = data;
}
/**
* Refresh all displayed information.
*/
function refreshAll() {
- cr.sendWithPromise('getOfflineInternalsInfo').then(setOfflineInternalsInfo);
+ cr.sendWithPromise('getStoredPagesInfo').then(fillStoredPages);
+ cr.sendWithPromise('getRequestQueueInfo').then(fillRequestQueue);
}
/**
@@ -117,25 +126,64 @@ cr.define('offlineInternals', function() {
/**
* Callback when pages are deleted.
- * @param {string} deletePageStatus The status of delete page call.
+ * @param {string} status The status of the request.
*/
- function pagesDeleted(deletePageStatus) {
- // TODO(chili): decide what to do here. Perhaps a refresh of just
- // the stored pages table?
+ function pagesDeleted(status) {
+ $('random-info').textContent = status;
+ cr.sendWithPromise('getStoredPagesInfo').then(fillStoredPages);
}
/**
- * Callback when information is loaded.
- * @param {{AllPages: !Array<OfflinePageItem>,
- * Queue: !Array<SavePageRequest>}} info An object containing both
- * stored pages and request queue status.
+ * Helper function to add quotes around a string.
+ * @param {string} strObj The obj to add quotes around.
dewittj 2016/06/03 23:12:05 @return {string} the escaped string
chili 2016/06/09 22:29:16 Done.
*/
- function setOfflineInternalsInfo(info) {
- clearTable('stored-pages');
- clearTable('request-queue');
+ function addQuotes(strObj) {
dewittj 2016/06/03 23:12:06 need to escape backslashes and quotes in the incom
chili 2016/06/09 22:29:16 backslashes don't need to be escaped. Added escap
+ return '"' + strObj + '"';
+ }
+
+ /**
+ * Downloads all the stored page and request queue information into a file.
+ */
+ function download() {
+ var csv = '';
+ // Create header & csv for stored pages.
+ if (currentStoredPagesData && currentStoredPagesData.length > 0) {
+ csv += 'Online URL,Namespace,Size,ID,File Path,Creation Time,' +
+ 'Last Accessed Time,Access Count\n';
+ for (let obj of currentStoredPagesData) {
+ var objFieldArr = [
+ obj.onlineUrl,
+ obj.namespace,
+ obj.size,
+ obj.id,
+ obj.filePath,
+ new Date(obj.creationTime).toString(),
+ new Date(obj.lastAccessedTime).toString(),
+ obj.accessCount];
+ objFieldArr = objFieldArr.map(addQuotes);
+ csv += objFieldArr.join(',') + '\n';
+ }
+ }
+ csv += '\n';
+ // Create header & csv for request queue.
+ if (currentRequestQueueData && currentRequestQueueData.length > 0) {
+ csv += 'Online URL,Creation Time,Status,Namespace,Last Attempt Time,ID\n';
+
+ for (let obj of currentRequestQueueData) {
+ var objFieldArr = [
+ obj.onlineUrl,
+ new Date(obj.creationTime).toString(),
+ obj.status,
+ obj.namespace,
+ new Date(obj.lastAttempt).toString(),
+ obj.id];
+ objFieldArr = objFieldArr.map(addQuotes);
+ csv += objFieldArr.join(',') + '\n';
+ }
+ }
- fillStoredPages($('stored-pages'), info.AllPages);
- fillRequestQueue($('request-queue'), info.Queue);
+ var uriContent = 'data:text/csv,' + encodeURIComponent(csv);
+ window.open(uriContent, 'dump.csv');
dewittj 2016/06/03 23:12:06 Does this open a window, or does it cause a downlo
chili 2016/06/09 22:29:16 This will open a window that'll ask you to downloa
}
/**
@@ -156,6 +204,7 @@ cr.define('offlineInternals', function() {
$('clear-all').onclick = deleteAllPages;
$('clear-selected').onclick = deleteSelectedPages;
$('refresh').onclick = refreshAll;
+ $('download').onclick = download;
refreshAll();
}

Powered by Google App Engine
This is Rietveld 408576698