 Chromium Code Reviews
 Chromium Code Reviews Issue 2928833002:
  [CacheStorage] [DevTools] Added "Time Received" column to cache storage data grid  (Closed)
    
  
    Issue 2928833002:
  [CacheStorage] [DevTools] Added "Time Received" column to cache storage data grid  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @unrestricted | 5 * @unrestricted | 
| 6 */ | 6 */ | 
| 7 SDK.ServiceWorkerCacheModel = class extends SDK.SDKModel { | 7 SDK.ServiceWorkerCacheModel = class extends SDK.SDKModel { | 
| 8 /** | 8 /** | 
| 9 * Invariant: This model can only be constructed on a ServiceWorker target. | 9 * Invariant: This model can only be constructed on a ServiceWorker target. | 
| 10 * @param {!SDK.Target} target | 10 * @param {!SDK.Target} target | 
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 */ | 208 */ | 
| 209 _cacheRemoved(cache) { | 209 _cacheRemoved(cache) { | 
| 210 this.dispatchEventToListeners(SDK.ServiceWorkerCacheModel.Events.CacheRemove d, {model: this, cache: cache}); | 210 this.dispatchEventToListeners(SDK.ServiceWorkerCacheModel.Events.CacheRemove d, {model: this, cache: cache}); | 
| 211 } | 211 } | 
| 212 | 212 | 
| 213 /** | 213 /** | 
| 214 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache | 214 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache | 
| 215 * @param {number} skipCount | 215 * @param {number} skipCount | 
| 216 * @param {number} pageSize | 216 * @param {number} pageSize | 
| 217 * @param {function(!Array<!SDK.ServiceWorkerCacheModel.Entry>, boolean)} call back | 217 * @param {function(!Array<!SDK.ServiceWorkerCacheModel.Entry>, boolean)} call back | 
| 218 * @this {SDK.ServiceWorkerCacheModel} | |
| 
dgozman
2017/06/07 21:32:06
It's already an instance method, no need for @this
 | |
| 218 */ | 219 */ | 
| 219 async _requestEntries(cache, skipCount, pageSize, callback) { | 220 async _requestEntries(cache, skipCount, pageSize, callback) { | 
| 220 var response = await this._agent.invoke_requestEntries({cacheId: cache.cache Id, skipCount, pageSize}); | 221 var response = await this._agent.invoke_requestEntries({cacheId: cache.cache Id, skipCount, pageSize}); | 
| 221 if (response[Protocol.Error]) { | 222 if (response[Protocol.Error]) { | 
| 222 console.error('ServiceWorkerCacheAgent error while requesting entries: ', response[Protocol.Error]); | 223 console.error('ServiceWorkerCacheAgent error while requesting entries: ', response[Protocol.Error]); | 
| 223 return; | 224 return; | 
| 224 } | 225 } | 
| 225 var entries = response.cacheDataEntries.map( | 226 var entries = response.cacheDataEntries.map( | 
| 226 dataEntry => new SDK.ServiceWorkerCacheModel.Entry(dataEntry.request, da taEntry.response)); | 227 dataEntry => new SDK.ServiceWorkerCacheModel.Entry( | 
| 228 dataEntry.request, dataEntry.response, this._formatTimestamp(dataEnt ry.responseTime))); | |
| 
dgozman
2017/06/07 21:32:06
new Date(dataEntry.responseTime * 1000).toLocaleSt
 
kristipark
2017/06/07 22:42:37
Done.
 | |
| 227 callback(entries, response.hasMore); | 229 callback(entries, response.hasMore); | 
| 228 } | 230 } | 
| 231 | |
| 232 /** | |
| 233 * @param {number} UNIX_timestamp | |
| 234 */ | |
| 235 _formatTimestamp(UNIX_timestamp) { // yyyy Mth dd, hh:mm:ss (24hr format) | |
| 236 /** | |
| 237 * @param {number} n | |
| 238 */ | |
| 239 function pad(n) { | |
| 240 return n < 10 ? '0' + n.toString(10) : n.toString(10); | |
| 241 } | |
| 242 | |
| 243 var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Se p', 'Oct', 'Nov', 'Dec']; | |
| 244 var date = new Date(UNIX_timestamp * 1000); | |
| 245 var time = [pad(date.getHours()), pad(date.getMinutes()), pad(date.getSecond s())].join(':'); | |
| 246 return [date.getFullYear(), monthName[date.getMonth()], date.getDate(), ',', time].join(' '); | |
| 247 } | |
| 229 }; | 248 }; | 
| 230 | 249 | 
| 231 SDK.SDKModel.register(SDK.ServiceWorkerCacheModel, SDK.Target.Capability.Browser , false); | 250 SDK.SDKModel.register(SDK.ServiceWorkerCacheModel, SDK.Target.Capability.Browser , false); | 
| 232 | 251 | 
| 233 /** @enum {symbol} */ | 252 /** @enum {symbol} */ | 
| 234 SDK.ServiceWorkerCacheModel.Events = { | 253 SDK.ServiceWorkerCacheModel.Events = { | 
| 235 CacheAdded: Symbol('CacheAdded'), | 254 CacheAdded: Symbol('CacheAdded'), | 
| 236 CacheRemoved: Symbol('CacheRemoved') | 255 CacheRemoved: Symbol('CacheRemoved') | 
| 237 }; | 256 }; | 
| 238 | 257 | 
| 239 /** | 258 /** | 
| 240 * @unrestricted | 259 * @unrestricted | 
| 241 */ | 260 */ | 
| 242 SDK.ServiceWorkerCacheModel.Entry = class { | 261 SDK.ServiceWorkerCacheModel.Entry = class { | 
| 243 /** | 262 /** | 
| 244 * @param {string} request | 263 * @param {string} request | 
| 245 * @param {string} response | 264 * @param {string} response | 
| 265 * @param {number} responseTime | |
| 246 */ | 266 */ | 
| 247 constructor(request, response) { | 267 constructor(request, response, responseTime) { | 
| 248 this.request = request; | 268 this.request = request; | 
| 249 this.response = response; | 269 this.response = response; | 
| 270 this.responseTime = responseTime; | |
| 250 } | 271 } | 
| 251 }; | 272 }; | 
| 252 | 273 | 
| 253 /** | 274 /** | 
| 254 * @unrestricted | 275 * @unrestricted | 
| 255 */ | 276 */ | 
| 256 SDK.ServiceWorkerCacheModel.Cache = class { | 277 SDK.ServiceWorkerCacheModel.Cache = class { | 
| 257 /** | 278 /** | 
| 258 * @param {string} securityOrigin | 279 * @param {string} securityOrigin | 
| 259 * @param {string} cacheName | 280 * @param {string} cacheName | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 274 } | 295 } | 
| 275 | 296 | 
| 276 /** | 297 /** | 
| 277 * @override | 298 * @override | 
| 278 * @return {string} | 299 * @return {string} | 
| 279 */ | 300 */ | 
| 280 toString() { | 301 toString() { | 
| 281 return this.securityOrigin + this.cacheName; | 302 return this.securityOrigin + this.cacheName; | 
| 282 } | 303 } | 
| 283 }; | 304 }; | 
| OLD | NEW |