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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/persistence/FileSystemMapping.js

Issue 2529303003: DevTools: move FileSystemMapping from Workspace to Persistence (Closed)
Patch Set: fix tests Created 4 years 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Workspace.FileSystemMapping = class extends Common.Object { 34 Persistence.FileSystemMapping = class extends Common.Object {
35 /** 35 /**
36 * @param {!Workspace.IsolatedFileSystemManager} fileSystemManager 36 * @param {!Workspace.IsolatedFileSystemManager} fileSystemManager
37 */ 37 */
38 constructor(fileSystemManager) { 38 constructor(fileSystemManager) {
39 super(); 39 super();
40 this._fileSystemMappingSetting = Common.settings.createLocalSetting('fileSys temMapping', {}); 40 this._fileSystemMappingSetting = Common.settings.createLocalSetting('fileSys temMapping', {});
41 /** @type {!Object.<string, !Array.<!Workspace.FileSystemMapping.Entry>>} */ 41 /** @type {!Object.<string, !Array.<!Persistence.FileSystemMapping.Entry>>} */
42 this._fileSystemMappings = {}; 42 this._fileSystemMappings = {};
43 this._loadFromSettings(); 43 this._loadFromSettings();
44 44
45 this._eventListeners = [ 45 this._eventListeners = [
46 fileSystemManager.addEventListener( 46 fileSystemManager.addEventListener(
47 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._file SystemAdded, this), 47 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._file SystemAdded, this),
48 fileSystemManager.addEventListener( 48 fileSystemManager.addEventListener(
49 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fi leSystemRemoved, this), 49 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fi leSystemRemoved, this),
50 ]; 50 ];
51 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi s)); 51 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi s));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 this._fileSystemMappings = {}; 99 this._fileSystemMappings = {};
100 for (var fileSystemPath in savedMapping) { 100 for (var fileSystemPath in savedMapping) {
101 var savedFileSystemMappings = savedMapping[fileSystemPath]; 101 var savedFileSystemMappings = savedMapping[fileSystemPath];
102 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); 102 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath);
103 this._fileSystemMappings[fileSystemPath] = []; 103 this._fileSystemMappings[fileSystemPath] = [];
104 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; 104 var fileSystemMappings = this._fileSystemMappings[fileSystemPath];
105 105
106 for (var i = 0; i < savedFileSystemMappings.length; ++i) { 106 for (var i = 0; i < savedFileSystemMappings.length; ++i) {
107 var savedEntry = savedFileSystemMappings[i]; 107 var savedEntry = savedFileSystemMappings[i];
108 var entry = 108 var entry =
109 new Workspace.FileSystemMapping.Entry(fileSystemPath, savedEntry.url Prefix, savedEntry.pathPrefix, true); 109 new Persistence.FileSystemMapping.Entry(fileSystemPath, savedEntry.u rlPrefix, savedEntry.pathPrefix, true);
110 fileSystemMappings.push(entry); 110 fileSystemMappings.push(entry);
111 } 111 }
112 } 112 }
113 113
114 this._rebuildIndexes(); 114 this._rebuildIndexes();
115 } 115 }
116 116
117 _saveToSettings() { 117 _saveToSettings() {
118 var setting = {}; 118 var setting = {};
119 for (var fileSystemPath in this._fileSystemMappings) { 119 for (var fileSystemPath in this._fileSystemMappings) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, false); 193 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, false);
194 } 194 }
195 195
196 /** 196 /**
197 * @param {string} fileSystemPath 197 * @param {string} fileSystemPath
198 * @param {string} urlPrefix 198 * @param {string} urlPrefix
199 * @param {string} pathPrefix 199 * @param {string} pathPrefix
200 * @param {boolean} configurable 200 * @param {boolean} configurable
201 */ 201 */
202 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, configurable) { 202 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, configurable) {
203 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, urlPrefix, pathPrefix, configurable); 203 var entry = new Persistence.FileSystemMapping.Entry(fileSystemPath, urlPrefi x, pathPrefix, configurable);
204 this._fileSystemMappings[fileSystemPath].push(entry); 204 this._fileSystemMappings[fileSystemPath].push(entry);
205 this._rebuildIndexes(); 205 this._rebuildIndexes();
206 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Added, entry); 206 this.dispatchEventToListeners(Persistence.FileSystemMapping.Events.FileMappi ngAdded, entry);
207 } 207 }
208 208
209 /** 209 /**
210 * @param {string} fileSystemPath 210 * @param {string} fileSystemPath
211 * @param {string} urlPrefix 211 * @param {string} urlPrefix
212 * @param {string} pathPrefix 212 * @param {string} pathPrefix
213 */ 213 */
214 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) { 214 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) {
215 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path Prefix); 215 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path Prefix);
216 if (!entry) 216 if (!entry)
217 return; 217 return;
218 this._fileSystemMappings[fileSystemPath].remove(entry); 218 this._fileSystemMappings[fileSystemPath].remove(entry);
219 this._rebuildIndexes(); 219 this._rebuildIndexes();
220 this._saveToSettings(); 220 this._saveToSettings();
221 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Removed, entry); 221 this.dispatchEventToListeners(Persistence.FileSystemMapping.Events.FileMappi ngRemoved, entry);
222 } 222 }
223 223
224 /** 224 /**
225 * @param {string} url 225 * @param {string} url
226 * @return {?Workspace.FileSystemMapping.Entry} 226 * @return {?Persistence.FileSystemMapping.Entry}
227 */ 227 */
228 _mappingEntryForURL(url) { 228 _mappingEntryForURL(url) {
229 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) { 229 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) {
230 var urlPrefix = this._urlPrefixes[i]; 230 var urlPrefix = this._urlPrefixes[i];
231 if (url.startsWith(urlPrefix)) 231 if (url.startsWith(urlPrefix))
232 return this._mappingForURLPrefix[urlPrefix]; 232 return this._mappingForURLPrefix[urlPrefix];
233 } 233 }
234 return null; 234 return null;
235 } 235 }
236 236
237 /** 237 /**
238 * @param {string} fileSystemPath 238 * @param {string} fileSystemPath
239 * @param {string} filePath 239 * @param {string} filePath
240 * @return {?Workspace.FileSystemMapping.Entry} 240 * @return {?Persistence.FileSystemMapping.Entry}
241 */ 241 */
242 _mappingEntryForPath(fileSystemPath, filePath) { 242 _mappingEntryForPath(fileSystemPath, filePath) {
243 var entries = this._fileSystemMappings[fileSystemPath]; 243 var entries = this._fileSystemMappings[fileSystemPath];
244 if (!entries) 244 if (!entries)
245 return null; 245 return null;
246 246
247 var entry = null; 247 var entry = null;
248 for (var i = 0; i < entries.length; ++i) { 248 for (var i = 0; i < entries.length; ++i) {
249 var pathPrefix = entries[i].pathPrefix; 249 var pathPrefix = entries[i].pathPrefix;
250 if (entry && entry.configurable && !entries[i].configurable) 250 if (entry && entry.configurable && !entries[i].configurable)
251 continue; 251 continue;
252 // We are looking for the longest pathPrefix match. 252 // We are looking for the longest pathPrefix match.
253 if (entry && entry.pathPrefix.length > pathPrefix.length) 253 if (entry && entry.pathPrefix.length > pathPrefix.length)
254 continue; 254 continue;
255 if (filePath.startsWith(pathPrefix)) 255 if (filePath.startsWith(pathPrefix))
256 entry = entries[i]; 256 entry = entries[i];
257 } 257 }
258 return entry; 258 return entry;
259 } 259 }
260 260
261 /** 261 /**
262 * @param {string} fileSystemPath 262 * @param {string} fileSystemPath
263 * @param {string} pathPrefix 263 * @param {string} pathPrefix
264 * @return {?Workspace.FileSystemMapping.Entry} 264 * @return {?Persistence.FileSystemMapping.Entry}
265 */ 265 */
266 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) { 266 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) {
267 var entries = this._fileSystemMappings[fileSystemPath]; 267 var entries = this._fileSystemMappings[fileSystemPath];
268 for (var i = 0; i < entries.length; ++i) { 268 for (var i = 0; i < entries.length; ++i) {
269 if (entries[i].configurable && pathPrefix === entries[i].pathPrefix) 269 if (entries[i].configurable && pathPrefix === entries[i].pathPrefix)
270 return entries[i]; 270 return entries[i];
271 } 271 }
272 return null; 272 return null;
273 } 273 }
274 274
275 /** 275 /**
276 * @param {string} fileSystemPath 276 * @param {string} fileSystemPath
277 * @return {!Array.<!Workspace.FileSystemMapping.Entry>} 277 * @return {!Array.<!Persistence.FileSystemMapping.Entry>}
278 */ 278 */
279 mappingEntries(fileSystemPath) { 279 mappingEntries(fileSystemPath) {
280 return this._fileSystemMappings[fileSystemPath].slice(); 280 return this._fileSystemMappings[fileSystemPath].slice();
281 } 281 }
282 282
283 /** 283 /**
284 * @param {string} url 284 * @param {string} url
285 * @return {boolean} 285 * @return {boolean}
286 */ 286 */
287 hasMappingForNetworkURL(url) { 287 hasMappingForNetworkURL(url) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 resetForTesting() { 354 resetForTesting() {
355 this._fileSystemMappings = {}; 355 this._fileSystemMappings = {};
356 } 356 }
357 357
358 dispose() { 358 dispose() {
359 Common.EventTarget.removeEventListeners(this._eventListeners); 359 Common.EventTarget.removeEventListeners(this._eventListeners);
360 } 360 }
361 }; 361 };
362 362
363 /** @enum {symbol} */ 363 /** @enum {symbol} */
364 Workspace.FileSystemMapping.Events = { 364 Persistence.FileSystemMapping.Events = {
365 FileMappingAdded: Symbol('FileMappingAdded'), 365 FileMappingAdded: Symbol('FileMappingAdded'),
366 FileMappingRemoved: Symbol('FileMappingRemoved') 366 FileMappingRemoved: Symbol('FileMappingRemoved')
367 }; 367 };
368 368
369 /** 369 /**
370 * @unrestricted 370 * @unrestricted
371 */ 371 */
372 Workspace.FileSystemMapping.Entry = class { 372 Persistence.FileSystemMapping.Entry = class {
373 /** 373 /**
374 * @param {string} fileSystemPath 374 * @param {string} fileSystemPath
375 * @param {string} urlPrefix 375 * @param {string} urlPrefix
376 * @param {string} pathPrefix 376 * @param {string} pathPrefix
377 * @param {boolean} configurable 377 * @param {boolean} configurable
378 */ 378 */
379 constructor(fileSystemPath, urlPrefix, pathPrefix, configurable) { 379 constructor(fileSystemPath, urlPrefix, pathPrefix, configurable) {
380 this.fileSystemPath = fileSystemPath; 380 this.fileSystemPath = fileSystemPath;
381 this.urlPrefix = urlPrefix; 381 this.urlPrefix = urlPrefix;
382 this.pathPrefix = pathPrefix; 382 this.pathPrefix = pathPrefix;
383 this.configurable = configurable; 383 this.configurable = configurable;
384 } 384 }
385 }; 385 };
386 386
387 /** 387 /**
388 * @type {!Workspace.FileSystemMapping} 388 * @type {!Persistence.FileSystemMapping}
389 */ 389 */
390 Workspace.fileSystemMapping; 390 Workspace.fileSystemMapping;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698