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

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

Issue 2868543002: DevTools: move FileSystemMapping under persistence/ module (Closed)
Patch Set: fix copyright Created 3 years, 7 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 /* 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 27 matching lines...) Expand all
79 var savedMapping = this._fileSystemMappingSetting.get(); 79 var savedMapping = this._fileSystemMappingSetting.get();
80 this._fileSystemMappings = {}; 80 this._fileSystemMappings = {};
81 for (var fileSystemPath in savedMapping) { 81 for (var fileSystemPath in savedMapping) {
82 var savedFileSystemMappings = savedMapping[fileSystemPath]; 82 var savedFileSystemMappings = savedMapping[fileSystemPath];
83 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); 83 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath);
84 this._fileSystemMappings[fileSystemPath] = []; 84 this._fileSystemMappings[fileSystemPath] = [];
85 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; 85 var fileSystemMappings = this._fileSystemMappings[fileSystemPath];
86 86
87 for (var i = 0; i < savedFileSystemMappings.length; ++i) { 87 for (var i = 0; i < savedFileSystemMappings.length; ++i) {
88 var savedEntry = savedFileSystemMappings[i]; 88 var savedEntry = savedFileSystemMappings[i];
89 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, savedE ntry.urlPrefix, savedEntry.pathPrefix); 89 var entry =
90 new Persistence.FileSystemMapping.Entry(fileSystemPath, savedEntry.u rlPrefix, savedEntry.pathPrefix);
90 fileSystemMappings.push(entry); 91 fileSystemMappings.push(entry);
91 } 92 }
92 } 93 }
93 94
94 this._rebuildIndexes(); 95 this._rebuildIndexes();
95 } 96 }
96 97
97 _saveToSettings() { 98 _saveToSettings() {
98 var setting = {}; 99 var setting = {};
99 for (var fileSystemPath in this._fileSystemMappings) { 100 for (var fileSystemPath in this._fileSystemMappings) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix); 159 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix);
159 this._saveToSettings(); 160 this._saveToSettings();
160 } 161 }
161 162
162 /** 163 /**
163 * @param {string} fileSystemPath 164 * @param {string} fileSystemPath
164 * @param {string} urlPrefix 165 * @param {string} urlPrefix
165 * @param {string} pathPrefix 166 * @param {string} pathPrefix
166 */ 167 */
167 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix) { 168 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix) {
168 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, urlPrefix, pathPrefix); 169 var entry = new Persistence.FileSystemMapping.Entry(fileSystemPath, urlPrefi x, pathPrefix);
169 this._fileSystemMappings[fileSystemPath].push(entry); 170 this._fileSystemMappings[fileSystemPath].push(entry);
170 this._rebuildIndexes(); 171 this._rebuildIndexes();
171 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Added, entry); 172 this.dispatchEventToListeners(Persistence.FileSystemMapping.Events.FileMappi ngAdded, entry);
172 } 173 }
173 174
174 /** 175 /**
175 * @param {string} fileSystemPath 176 * @param {string} fileSystemPath
176 * @param {string} urlPrefix 177 * @param {string} urlPrefix
177 * @param {string} pathPrefix 178 * @param {string} pathPrefix
178 */ 179 */
179 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) { 180 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) {
180 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path Prefix); 181 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path Prefix);
181 if (!entry) 182 if (!entry)
182 return; 183 return;
183 this._fileSystemMappings[fileSystemPath].remove(entry); 184 this._fileSystemMappings[fileSystemPath].remove(entry);
184 this._rebuildIndexes(); 185 this._rebuildIndexes();
185 this._saveToSettings(); 186 this._saveToSettings();
186 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping Removed, entry); 187 this.dispatchEventToListeners(Persistence.FileSystemMapping.Events.FileMappi ngRemoved, entry);
187 } 188 }
188 189
189 /** 190 /**
190 * @param {string} url 191 * @param {string} url
191 * @return {?Workspace.FileSystemMapping.Entry} 192 * @return {?Persistence.FileSystemMapping.Entry}
192 */ 193 */
193 _mappingEntryForURL(url) { 194 _mappingEntryForURL(url) {
194 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) { 195 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) {
195 var urlPrefix = this._urlPrefixes[i]; 196 var urlPrefix = this._urlPrefixes[i];
196 if (url.startsWith(urlPrefix)) 197 if (url.startsWith(urlPrefix))
197 return this._mappingForURLPrefix[urlPrefix]; 198 return this._mappingForURLPrefix[urlPrefix];
198 } 199 }
199 return null; 200 return null;
200 } 201 }
201 202
202 /** 203 /**
203 * @param {string} fileSystemPath 204 * @param {string} fileSystemPath
204 * @param {string} filePath 205 * @param {string} filePath
205 * @return {?Workspace.FileSystemMapping.Entry} 206 * @return {?Persistence.FileSystemMapping.Entry}
206 */ 207 */
207 _mappingEntryForPath(fileSystemPath, filePath) { 208 _mappingEntryForPath(fileSystemPath, filePath) {
208 var entries = this._fileSystemMappings[fileSystemPath]; 209 var entries = this._fileSystemMappings[fileSystemPath];
209 if (!entries) 210 if (!entries)
210 return null; 211 return null;
211 212
212 var entry = null; 213 var entry = null;
213 for (var i = 0; i < entries.length; ++i) { 214 for (var i = 0; i < entries.length; ++i) {
214 var pathPrefix = entries[i].pathPrefix; 215 var pathPrefix = entries[i].pathPrefix;
215 // We are looking for the longest pathPrefix match. 216 // We are looking for the longest pathPrefix match.
216 if (entry && entry.pathPrefix.length > pathPrefix.length) 217 if (entry && entry.pathPrefix.length > pathPrefix.length)
217 continue; 218 continue;
218 if (filePath.startsWith(pathPrefix)) 219 if (filePath.startsWith(pathPrefix))
219 entry = entries[i]; 220 entry = entries[i];
220 } 221 }
221 return entry; 222 return entry;
222 } 223 }
223 224
224 /** 225 /**
225 * @param {string} fileSystemPath 226 * @param {string} fileSystemPath
226 * @param {string} pathPrefix 227 * @param {string} pathPrefix
227 * @return {?Workspace.FileSystemMapping.Entry} 228 * @return {?Persistence.FileSystemMapping.Entry}
228 */ 229 */
229 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) { 230 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) {
230 var entries = this._fileSystemMappings[fileSystemPath]; 231 var entries = this._fileSystemMappings[fileSystemPath];
231 for (var i = 0; i < entries.length; ++i) { 232 for (var i = 0; i < entries.length; ++i) {
232 if (pathPrefix === entries[i].pathPrefix) 233 if (pathPrefix === entries[i].pathPrefix)
233 return entries[i]; 234 return entries[i];
234 } 235 }
235 return null; 236 return null;
236 } 237 }
237 238
238 /** 239 /**
239 * @param {string} fileSystemPath 240 * @param {string} fileSystemPath
240 * @return {!Array.<!Workspace.FileSystemMapping.Entry>} 241 * @return {!Array.<!Persistence.FileSystemMapping.Entry>}
241 */ 242 */
242 mappingEntries(fileSystemPath) { 243 mappingEntries(fileSystemPath) {
243 return this._fileSystemMappings[fileSystemPath].slice(); 244 return this._fileSystemMappings[fileSystemPath].slice();
244 } 245 }
245 246
246 /** 247 /**
247 * @param {string} url 248 * @param {string} url
248 * @return {boolean} 249 * @return {boolean}
249 */ 250 */
250 hasMappingForNetworkURL(url) { 251 hasMappingForNetworkURL(url) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 resetForTesting() { 318 resetForTesting() {
318 this._fileSystemMappings = {}; 319 this._fileSystemMappings = {};
319 } 320 }
320 321
321 dispose() { 322 dispose() {
322 Common.EventTarget.removeEventListeners(this._eventListeners); 323 Common.EventTarget.removeEventListeners(this._eventListeners);
323 } 324 }
324 }; 325 };
325 326
326 /** @enum {symbol} */ 327 /** @enum {symbol} */
327 Workspace.FileSystemMapping.Events = { 328 Persistence.FileSystemMapping.Events = {
328 FileMappingAdded: Symbol('FileMappingAdded'), 329 FileMappingAdded: Symbol('FileMappingAdded'),
329 FileMappingRemoved: Symbol('FileMappingRemoved') 330 FileMappingRemoved: Symbol('FileMappingRemoved')
330 }; 331 };
331 332
332 /** 333 /**
333 * @unrestricted 334 * @unrestricted
334 */ 335 */
335 Workspace.FileSystemMapping.Entry = class { 336 Persistence.FileSystemMapping.Entry = class {
336 /** 337 /**
337 * @param {string} fileSystemPath 338 * @param {string} fileSystemPath
338 * @param {string} urlPrefix 339 * @param {string} urlPrefix
339 * @param {string} pathPrefix 340 * @param {string} pathPrefix
340 */ 341 */
341 constructor(fileSystemPath, urlPrefix, pathPrefix) { 342 constructor(fileSystemPath, urlPrefix, pathPrefix) {
342 this.fileSystemPath = fileSystemPath; 343 this.fileSystemPath = fileSystemPath;
343 this.urlPrefix = urlPrefix; 344 this.urlPrefix = urlPrefix;
344 this.pathPrefix = pathPrefix; 345 this.pathPrefix = pathPrefix;
345 } 346 }
346 }; 347 };
347 348
348 /** 349 /**
349 * @type {!Workspace.FileSystemMapping} 350 * @type {!Persistence.FileSystemMapping}
350 */ 351 */
351 Workspace.fileSystemMapping; 352 Persistence.fileSystemMapping;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698