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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServiceWorkerCacheModel.js

Issue 2172753002: [DevTools] No longer store security origins in ResourceTreeModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extracted security origins from the ResourceTreeModel Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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 /** 5 /**
6 * Invariant: This model can only be constructed on a ServiceWorker target. 6 * Invariant: This model can only be constructed on a ServiceWorker target.
7 * @constructor 7 * @constructor
8 * @extends {WebInspector.SDKModel} 8 * @extends {WebInspector.SDKModel}
9 * @param {!WebInspector.Target} target
10 * @param {!WebInspector.SecurityOriginManager} securityOriginManager
9 */ 11 */
10 WebInspector.ServiceWorkerCacheModel = function(target) 12 WebInspector.ServiceWorkerCacheModel = function(target, securityOriginManager)
11 { 13 {
12 WebInspector.SDKModel.call(this, WebInspector.ServiceWorkerCacheModel, targe t); 14 WebInspector.SDKModel.call(this, WebInspector.ServiceWorkerCacheModel, targe t);
13 15
14 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */ 16 /** @type {!Map<string, !WebInspector.ServiceWorkerCacheModel.Cache>} */
15 this._caches = new Map(); 17 this._caches = new Map();
16 18
17 this._agent = target.cacheStorageAgent(); 19 this._agent = target.cacheStorageAgent();
18 20
21 this._securityOriginManager = securityOriginManager;
22
19 /** @type {boolean} */ 23 /** @type {boolean} */
20 this._enabled = false; 24 this._enabled = false;
21 } 25 }
22 26
23 WebInspector.ServiceWorkerCacheModel.EventTypes = { 27 WebInspector.ServiceWorkerCacheModel.EventTypes = {
24 CacheAdded: "CacheAdded", 28 CacheAdded: "CacheAdded",
25 CacheRemoved: "CacheRemoved" 29 CacheRemoved: "CacheRemoved"
26 } 30 }
27 31
28 WebInspector.ServiceWorkerCacheModel.prototype = { 32 WebInspector.ServiceWorkerCacheModel.prototype = {
29 enable: function() 33 enable: function()
30 { 34 {
31 if (this._enabled) 35 if (this._enabled)
32 return; 36 return;
33 37
34 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr eeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 38 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin Manager.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
35 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr eeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this); 39 this._securityOriginManager.addEventListener(WebInspector.SecurityOrigin Manager.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, this);
36 40
37 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); 41 var securityOrigins = this._securityOriginManager.securityOrigins();
38 for (var i = 0; i < securityOrigins.length; ++i) 42 for (var i = 0; i < securityOrigins.length; ++i)
39 this._addOrigin(securityOrigins[i]); 43 this._addOrigin(securityOrigins[i]);
40 this._enabled = true; 44 this._enabled = true;
41 }, 45 },
42 46
43 /** 47 /**
44 * @param {string} origin 48 * @param {string} origin
45 */ 49 */
46 clearForOrigin: function(origin) 50 clearForOrigin: function(origin)
47 { 51 {
48 this._removeOrigin(origin); 52 this._removeOrigin(origin);
49 this._addOrigin(origin); 53 this._addOrigin(origin);
50 }, 54 },
51 55
52 refreshCacheNames: function() 56 refreshCacheNames: function()
53 { 57 {
54 for (var cache of this._caches.values()) 58 for (var cache of this._caches.values())
55 this._cacheRemoved(cache); 59 this._cacheRemoved(cache);
56 this._caches.clear(); 60 this._caches.clear();
57 var securityOrigins = this.target().resourceTreeModel.securityOrigins(); 61 var securityOrigins = this._securityOriginManager.securityOrigins();
58 for (var securityOrigin of securityOrigins) 62 for (var securityOrigin of securityOrigins)
59 this._loadCacheNames(securityOrigin); 63 this._loadCacheNames(securityOrigin);
60 }, 64 },
61 65
62 /** 66 /**
63 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache 67 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
64 */ 68 */
65 deleteCache: function(cache) 69 deleteCache: function(cache)
66 { 70 {
67 /** 71 /**
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 caches.push(cache); 126 caches.push(cache);
123 return caches; 127 return caches;
124 }, 128 },
125 129
126 dispose: function() 130 dispose: function()
127 { 131 {
128 for (var cache of this._caches.values()) 132 for (var cache of this._caches.values())
129 this._cacheRemoved(cache); 133 this._cacheRemoved(cache);
130 this._caches.clear(); 134 this._caches.clear();
131 if (this._enabled) { 135 if (this._enabled) {
132 this.target().resourceTreeModel.removeEventListener(WebInspector.Res ourceTreeModel.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this); 136 this._securityOriginManager.removeEventListener(WebInspector.Securit yOriginManager.EventTypes.SecurityOriginAdded, this._securityOriginAdded, this);
133 this.target().resourceTreeModel.removeEventListener(WebInspector.Res ourceTreeModel.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, th is); 137 this._securityOriginManager.removeEventListener(WebInspector.Securit yOriginManager.EventTypes.SecurityOriginRemoved, this._securityOriginRemoved, th is);
134 } 138 }
135 }, 139 },
136 140
137 _addOrigin: function(securityOrigin) 141 _addOrigin: function(securityOrigin)
138 { 142 {
139 this._loadCacheNames(securityOrigin); 143 this._loadCacheNames(securityOrigin);
140 }, 144 },
141 145
142 /** 146 /**
143 * @param {string} securityOrigin 147 * @param {string} securityOrigin
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 toString: function() 322 toString: function()
319 { 323 {
320 return this.securityOrigin + this.cacheName; 324 return this.securityOrigin + this.cacheName;
321 } 325 }
322 } 326 }
323 327
324 328
325 WebInspector.ServiceWorkerCacheModel._symbol = Symbol("CacheStorageModel"); 329 WebInspector.ServiceWorkerCacheModel._symbol = Symbol("CacheStorageModel");
326 /** 330 /**
327 * @param {!WebInspector.Target} target 331 * @param {!WebInspector.Target} target
328 * @return {!WebInspector.ServiceWorkerCacheModel} 332 * @return {?WebInspector.ServiceWorkerCacheModel}
329 */ 333 */
330 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target) 334 WebInspector.ServiceWorkerCacheModel.fromTarget = function(target)
331 { 335 {
332 if (!target[WebInspector.ServiceWorkerCacheModel._symbol]) 336 if (!target[WebInspector.ServiceWorkerCacheModel._symbol]) {
dgozman 2016/07/22 03:27:03 Use the target.model(...) method.
eostroukhov-old 2016/07/22 23:27:44 Done.
333 target[WebInspector.ServiceWorkerCacheModel._symbol] = new WebInspector. ServiceWorkerCacheModel(target); 337 var securityOriginManager = WebInspector.SecurityOriginManager.fromTarge t(target);
338 if (!securityOriginManager)
dgozman 2016/07/22 03:27:03 It is never null. Instead, check for browser capab
eostroukhov-old 2016/07/22 23:27:44 Done.
339 return null;
340 target[WebInspector.ServiceWorkerCacheModel._symbol] = new WebInspector. ServiceWorkerCacheModel(target, securityOriginManager);
341 }
334 342
335 return target[WebInspector.ServiceWorkerCacheModel._symbol]; 343 return target[WebInspector.ServiceWorkerCacheModel._symbol];
336 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698