| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | |
| 6 * @typedef {{ | |
| 7 * onlineUrl: string, | |
| 8 * creationTime: number, | |
| 9 * id: string, | |
| 10 * namespace: string, | |
| 11 * size: string, | |
| 12 * filePath: string, | |
| 13 * lastAccessTime: number, | |
| 14 * accessCount: number | |
| 15 * }} | |
| 16 */ | |
| 17 var OfflinePage; | |
| 18 | |
| 19 /** | |
| 20 * @typedef {{ | |
| 21 * status: string, | |
| 22 * onlineUrl: string, | |
| 23 * creationTime: number, | |
| 24 * id: string, | |
| 25 * namespace: string, | |
| 26 * lastAttempt: number | |
| 27 * }} | |
| 28 */ | |
| 29 var SavePageRequest; | |
| 30 | |
| 31 cr.define('offlineInternals', function() { | 5 cr.define('offlineInternals', function() { |
| 32 'use strict'; | 6 'use strict'; |
| 33 | 7 |
| 34 /** @type {!Array<OfflinePage>} */ | 8 /** @type {!Array<OfflinePage>} */ |
| 35 var offlinePages = []; | 9 var offlinePages = []; |
| 36 | 10 |
| 37 /** @type {!Array<SavePageRequest>} */ | 11 /** @type {!Array<SavePageRequest>} */ |
| 38 var savePageRequests = []; | 12 var savePageRequests = []; |
| 39 | 13 |
| 14 /** @type {offlineInternals.OfflineInternalsBrowserProxy} */ |
| 15 var browserProxy_; |
| 16 |
| 40 /** | 17 /** |
| 41 * Fill stored pages table. | 18 * Fill stored pages table. |
| 42 * @param {!Array<OfflinePage>} pages An array object representing | 19 * @param {!Array<OfflinePage>} pages An array object representing |
| 43 * stored offline pages. | 20 * stored offline pages. |
| 44 */ | 21 */ |
| 45 function fillStoredPages(pages) { | 22 function fillStoredPages(pages) { |
| 46 var storedPagesTable = $('stored-pages'); | 23 var storedPagesTable = $('stored-pages'); |
| 47 storedPagesTable.textContent = ''; | 24 storedPagesTable.textContent = ''; |
| 48 | 25 |
| 49 for (var i = 0; i < pages.length; i++) { | 26 for (var i = 0; i < pages.length; i++) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 78 |
| 102 requestQueueTable.appendChild(row); | 79 requestQueueTable.appendChild(row); |
| 103 } | 80 } |
| 104 savePageRequests = requests; | 81 savePageRequests = requests; |
| 105 } | 82 } |
| 106 | 83 |
| 107 /** | 84 /** |
| 108 * Refresh all displayed information. | 85 * Refresh all displayed information. |
| 109 */ | 86 */ |
| 110 function refreshAll() { | 87 function refreshAll() { |
| 111 cr.sendWithPromise('getStoredPagesInfo').then(fillStoredPages); | 88 browserProxy_.getStoredPages().then(fillStoredPages); |
| 112 cr.sendWithPromise('getRequestQueueInfo').then(fillRequestQueue); | 89 browserProxy_.getRequestQueue().then(fillRequestQueue); |
| 113 } | 90 } |
| 114 | 91 |
| 115 /** | 92 /** |
| 116 * Delete all pages in the offline store. | 93 * Delete all pages in the offline store. |
| 117 */ | 94 */ |
| 118 function deleteAllPages() { | 95 function deleteAllPages() { |
| 119 cr.sendWithPromise('deleteAllPages').then(pagesDeleted); | 96 browserProxy_.deleteAllPages().then(pagesDeleted); |
| 120 } | 97 } |
| 121 | 98 |
| 122 /** | 99 /** |
| 123 * Callback when pages are deleted. | 100 * Callback when pages are deleted. |
| 124 * @param {string} status The status of the request. | 101 * @param {string} status The status of the request. |
| 125 */ | 102 */ |
| 126 function pagesDeleted(status) { | 103 function pagesDeleted(status) { |
| 127 $('page-actions-info').textContent = status; | 104 $('page-actions-info').textContent = status; |
| 128 cr.sendWithPromise('getStoredPagesInfo').then(fillStoredPages); | 105 browserProxy_.getStoredPages().then(fillStoredPages); |
| 129 } | 106 } |
| 130 | 107 |
| 131 /** | 108 /** |
| 132 * Helper function to JSON-escape and add quotes around a string. | |
| 133 * @param {string} strObj The obj to escape and add quotes around. | |
| 134 * @return {string} The escaped string. | |
| 135 */ | |
| 136 function escapeString(strObj) { | |
| 137 // CSV single quotes are encoded as "". There can also be commas. | |
| 138 return '"' + strObj.replace(/"/g, '""') + '"'; | |
| 139 } | |
| 140 | |
| 141 /** | |
| 142 * Downloads all the stored page and request queue information into a file. | 109 * Downloads all the stored page and request queue information into a file. |
| 143 * TODO(chili): Create a CSV writer that can abstract out the line joining. | 110 * TODO(chili): Create a CSV writer that can abstract out the line joining. |
| 144 */ | 111 */ |
| 145 function download() { | 112 function download() { |
| 146 var json = JSON.stringify({ | 113 var json = JSON.stringify({ |
| 147 offlinePages: offlinePages, | 114 offlinePages: offlinePages, |
| 148 savePageRequests: savePageRequests | 115 savePageRequests: savePageRequests |
| 149 }, null, 2); | 116 }, null, 2); |
| 150 | 117 |
| 151 window.open( | 118 window.open( |
| 152 'data:application/json,' + encodeURIComponent(json), | 119 'data:application/json,' + encodeURIComponent(json), |
| 153 'dump.json'); | 120 'dump.json'); |
| 154 } | 121 } |
| 155 | 122 |
| 156 /** | 123 /** |
| 157 * Delete selected pages from the offline store. | 124 * Delete selected pages from the offline store. |
| 158 */ | 125 */ |
| 159 function deleteSelectedPages() { | 126 function deleteSelectedPages() { |
| 160 var checkboxes = document.getElementsByName('stored'); | 127 var checkboxes = document.getElementsByName('stored'); |
| 161 var selectedIds = []; | 128 var selectedIds = []; |
| 162 | 129 |
| 163 for (var i = 0; i < checkboxes.length; i++) { | 130 for (var i = 0; i < checkboxes.length; i++) { |
| 164 if (checkboxes[i].checked) | 131 if (checkboxes[i].checked) |
| 165 selectedIds.push(checkboxes[i].value); | 132 selectedIds.push(checkboxes[i].value); |
| 166 } | 133 } |
| 167 | 134 |
| 168 cr.sendWithPromise('deleteSelectedPages', selectedIds).then(pagesDeleted); | 135 browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted); |
| 169 } | 136 } |
| 170 | 137 |
| 171 function initialize() { | 138 function initialize() { |
| 172 $('clear-all').onclick = deleteAllPages; | 139 $('clear-all').onclick = deleteAllPages; |
| 173 $('clear-selected').onclick = deleteSelectedPages; | 140 $('clear-selected').onclick = deleteSelectedPages; |
| 174 $('refresh').onclick = refreshAll; | 141 $('refresh').onclick = refreshAll; |
| 175 $('download').onclick = download; | 142 $('download').onclick = download; |
| 143 browserProxy_ = |
| 144 offlineInternals.OfflineInternalsBrowserProxyImpl.getInstance(); |
| 176 refreshAll(); | 145 refreshAll(); |
| 177 } | 146 } |
| 178 | 147 |
| 179 // Return an object with all of the exports. | 148 // Return an object with all of the exports. |
| 180 return { | 149 return { |
| 181 initialize: initialize, | 150 initialize: initialize, |
| 182 }; | 151 }; |
| 183 }); | 152 }); |
| 184 | 153 |
| 185 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); | 154 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); |
| OLD | NEW |