Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 34 */ | 34 */ |
| 35 WebInspector.IsolatedFileSystemManager = function() | 35 WebInspector.IsolatedFileSystemManager = function() |
| 36 { | 36 { |
| 37 /** @type {!Map<string, !WebInspector.IsolatedFileSystem>} */ | 37 /** @type {!Map<string, !WebInspector.IsolatedFileSystem>} */ |
| 38 this._fileSystems = new Map(); | 38 this._fileSystems = new Map(); |
| 39 /** @type {!Map<number, function(!Array.<string>)>} */ | 39 /** @type {!Map<number, function(!Array.<string>)>} */ |
| 40 this._callbacks = new Map(); | 40 this._callbacks = new Map(); |
| 41 /** @type {!Map<number, !WebInspector.Progress>} */ | 41 /** @type {!Map<number, !WebInspector.Progress>} */ |
| 42 this._progresses = new Map(); | 42 this._progresses = new Map(); |
| 43 | 43 |
| 44 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemsLoaded, this._onFileSystemsLoaded, this); | |
| 45 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemRemoved, this._onFileSystemRemoved, this); | 44 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemRemoved, this._onFileSystemRemoved, this); |
| 46 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemAdded, this._onFileSystemAdded, this); | 45 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemAdded, this._onFileSystemAdded, this); |
| 47 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemFilesChanged, this._onFileSystemFilesChanged, this); | 46 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FileSystemFilesChanged, this._onFileSystemFilesChanged, this); |
| 48 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingTotalWorkCalculated, this._onIndexingTotalWorkCalculated, this); | 47 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingTotalWorkCalculated, this._onIndexingTotalWorkCalculated, this); |
| 49 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingWorked, this._onIndexingWorked, this); | 48 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingWorked, this._onIndexingWorked, this); |
| 50 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingDone, this._onIndexingDone, this); | 49 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.IndexingDone, this._onIndexingDone, this); |
| 51 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SearchCompleted, this._onSearchCompleted, this); | 50 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SearchCompleted, this._onSearchCompleted, this); |
| 52 | 51 |
| 53 this._initExcludePatterSetting(); | 52 this._initExcludePatterSetting(); |
| 53 | |
| 54 this._fileSystemsLoadedPromise = this._requestFileSystems(); | |
| 54 } | 55 } |
| 55 | 56 |
| 56 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string} } */ | 57 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string} } */ |
| 57 WebInspector.IsolatedFileSystemManager.FileSystem; | 58 WebInspector.IsolatedFileSystemManager.FileSystem; |
| 58 | 59 |
| 59 /** @enum {symbol} */ | 60 /** @enum {symbol} */ |
| 60 WebInspector.IsolatedFileSystemManager.Events = { | 61 WebInspector.IsolatedFileSystemManager.Events = { |
| 61 FileSystemAdded: Symbol("FileSystemAdded"), | 62 FileSystemAdded: Symbol("FileSystemAdded"), |
| 62 FileSystemRemoved: Symbol("FileSystemRemoved"), | 63 FileSystemRemoved: Symbol("FileSystemRemoved"), |
| 63 FileSystemsLoaded: Symbol("FileSystemsLoaded"), | |
| 64 FileSystemFilesChanged: Symbol("FileSystemFilesChanged"), | 64 FileSystemFilesChanged: Symbol("FileSystemFilesChanged"), |
| 65 ExcludedFolderAdded: Symbol("ExcludedFolderAdded"), | 65 ExcludedFolderAdded: Symbol("ExcludedFolderAdded"), |
| 66 ExcludedFolderRemoved: Symbol("ExcludedFolderRemoved") | 66 ExcludedFolderRemoved: Symbol("ExcludedFolderRemoved") |
| 67 } | 67 } |
| 68 | 68 |
| 69 WebInspector.IsolatedFileSystemManager._lastRequestId = 0; | 69 WebInspector.IsolatedFileSystemManager._lastRequestId = 0; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {string} fileSystemPath | 72 * @param {string} fileSystemPath |
| 73 * @return {string} | 73 * @return {string} |
| 74 */ | 74 */ |
| 75 WebInspector.IsolatedFileSystemManager.normalizePath = function(fileSystemPath) | 75 WebInspector.IsolatedFileSystemManager.normalizePath = function(fileSystemPath) |
| 76 { | 76 { |
| 77 fileSystemPath = fileSystemPath.replace(/\\/g, "/"); | 77 fileSystemPath = fileSystemPath.replace(/\\/g, "/"); |
| 78 if (!fileSystemPath.startsWith("file://")) { | 78 if (!fileSystemPath.startsWith("file://")) { |
| 79 if (fileSystemPath.startsWith("/")) | 79 if (fileSystemPath.startsWith("/")) |
| 80 fileSystemPath = "file://" + fileSystemPath; | 80 fileSystemPath = "file://" + fileSystemPath; |
| 81 else | 81 else |
| 82 fileSystemPath = "file:///" + fileSystemPath; | 82 fileSystemPath = "file:///" + fileSystemPath; |
| 83 } | 83 } |
| 84 return fileSystemPath; | 84 return fileSystemPath; |
| 85 } | 85 } |
| 86 | 86 |
| 87 WebInspector.IsolatedFileSystemManager.prototype = { | 87 WebInspector.IsolatedFileSystemManager.prototype = { |
| 88 /** | 88 /** |
| 89 * @param {function()} callback | 89 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} |
| 90 */ | 90 */ |
| 91 initialize: function(callback) | 91 _requestFileSystems: function() |
| 92 { | 92 { |
| 93 this._initializeCallback = callback; | 93 var fulfill; |
| 94 var promise = new Promise(f => fulfill = f); | |
| 94 InspectorFrontendHost.requestFileSystems(); | 95 InspectorFrontendHost.requestFileSystems(); |
| 96 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E vents.FileSystemsLoaded, onFileSystemsLoaded, this); | |
| 97 return promise; | |
| 98 | |
| 99 /** | |
| 100 * @param {!WebInspector.Event} event | |
| 101 * @this {WebInspector.IsolatedFileSystemManager} | |
| 102 */ | |
| 103 function onFileSystemsLoaded(event) | |
| 104 { | |
| 105 var fileSystems = /** @type {!Array.<!WebInspector.IsolatedFileSyste mManager.FileSystem>} */ (event.data); | |
| 106 var promises = []; | |
| 107 for (var i = 0; i < fileSystems.length; ++i) | |
| 108 promises.push(this._innerAddFileSystem(fileSystems[i], false)); | |
| 109 Promise.all(promises).then(fileSystems => fulfill(fileSystems.filter (fs => !!fs))); | |
|
dgozman
2016/08/31 20:28:46
style: no nested arrow functions please
lushnikov
2016/08/31 21:46:01
yikes. done.
| |
| 110 } | |
| 95 }, | 111 }, |
| 96 | 112 |
| 97 addFileSystem: function() | 113 addFileSystem: function() |
| 98 { | 114 { |
| 99 InspectorFrontendHost.addFileSystem(""); | 115 InspectorFrontendHost.addFileSystem(""); |
| 100 }, | 116 }, |
| 101 | 117 |
| 102 /** | 118 /** |
| 103 * @param {!WebInspector.IsolatedFileSystem} fileSystem | 119 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
| 104 */ | 120 */ |
| 105 removeFileSystem: function(fileSystem) | 121 removeFileSystem: function(fileSystem) |
| 106 { | 122 { |
| 107 | |
| 108 InspectorFrontendHost.removeFileSystem(fileSystem.embedderPath()); | 123 InspectorFrontendHost.removeFileSystem(fileSystem.embedderPath()); |
| 109 }, | 124 }, |
| 110 | 125 |
| 111 /** | 126 /** |
| 112 * @param {!WebInspector.Event} event | 127 * @return {!Promise<!Array<!WebInspector.IsolatedFileSystem>>} |
| 113 */ | 128 */ |
| 114 _onFileSystemsLoaded: function(event) | 129 waitForFileSystems: function() |
| 115 { | 130 { |
| 116 var fileSystems = /** @type {!Array.<!WebInspector.IsolatedFileSystemMan ager.FileSystem>} */ (event.data); | 131 return this._fileSystemsLoadedPromise; |
| 117 var promises = []; | |
| 118 for (var i = 0; i < fileSystems.length; ++i) | |
| 119 promises.push(this._innerAddFileSystem(fileSystems[i])); | |
| 120 Promise.all(promises).then(fireFileSystemsLoaded.bind(this)); | |
| 121 | |
| 122 /** | |
| 123 * @this {WebInspector.IsolatedFileSystemManager} | |
| 124 */ | |
| 125 function fireFileSystemsLoaded() | |
| 126 { | |
| 127 this._initializeCallback(); | |
| 128 delete this._initializeCallback; | |
| 129 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager .Events.FileSystemsLoaded); | |
| 130 } | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * @return {boolean} | |
| 135 */ | |
| 136 fileSystemsLoaded: function() | |
| 137 { | |
| 138 return !this._initializeCallback; | |
| 139 }, | 132 }, |
| 140 | 133 |
| 141 /** | 134 /** |
| 142 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem | 135 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem |
| 143 * @return {!Promise} | 136 * @param {boolean} dispatchEvent |
| 137 * @return {!Promise<?WebInspector.IsolatedFileSystem>} | |
| 144 */ | 138 */ |
| 145 _innerAddFileSystem: function(fileSystem) | 139 _innerAddFileSystem: function(fileSystem, dispatchEvent) |
| 146 { | 140 { |
| 147 var embedderPath = fileSystem.fileSystemPath; | 141 var embedderPath = fileSystem.fileSystemPath; |
| 148 var fileSystemPath = WebInspector.IsolatedFileSystemManager.normalizePat h(fileSystem.fileSystemPath); | 142 var fileSystemPath = WebInspector.IsolatedFileSystemManager.normalizePat h(fileSystem.fileSystemPath); |
| 149 var promise = WebInspector.IsolatedFileSystem.create(this, fileSystemPat h, embedderPath, fileSystem.fileSystemName, fileSystem.rootURL); | 143 var promise = WebInspector.IsolatedFileSystem.create(this, fileSystemPat h, embedderPath, fileSystem.fileSystemName, fileSystem.rootURL); |
| 150 return promise.then(storeFileSystem.bind(this)); | 144 return promise.then(storeFileSystem.bind(this)); |
| 151 | 145 |
| 152 /** | 146 /** |
| 153 * @param {?WebInspector.IsolatedFileSystem} fileSystem | 147 * @param {?WebInspector.IsolatedFileSystem} fileSystem |
| 154 * @this {WebInspector.IsolatedFileSystemManager} | 148 * @this {WebInspector.IsolatedFileSystemManager} |
| 155 */ | 149 */ |
| 156 function storeFileSystem(fileSystem) | 150 function storeFileSystem(fileSystem) |
| 157 { | 151 { |
| 158 if (!fileSystem) | 152 if (!fileSystem) |
| 159 return; | 153 return null; |
| 160 this._fileSystems.set(fileSystemPath, fileSystem); | 154 this._fileSystems.set(fileSystemPath, fileSystem); |
| 161 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager .Events.FileSystemAdded, fileSystem); | 155 if (dispatchEvent) |
| 156 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemMan ager.Events.FileSystemAdded, fileSystem); | |
| 157 return fileSystem; | |
| 162 } | 158 } |
| 163 }, | 159 }, |
| 164 | 160 |
| 165 /** | 161 /** |
| 166 * @param {!WebInspector.Event} event | 162 * @param {!WebInspector.Event} event |
| 167 */ | 163 */ |
| 168 _onFileSystemAdded: function(event) | 164 _onFileSystemAdded: function(event) |
| 169 { | 165 { |
| 170 var errorMessage = /** @type {string} */ (event.data["errorMessage"]); | 166 var errorMessage = /** @type {string} */ (event.data["errorMessage"]); |
| 171 var fileSystem = /** @type {?WebInspector.IsolatedFileSystemManager.File System} */ (event.data["fileSystem"]); | 167 var fileSystem = /** @type {?WebInspector.IsolatedFileSystemManager.File System} */ (event.data["fileSystem"]); |
| 172 if (errorMessage) | 168 if (errorMessage) |
| 173 WebInspector.console.error(errorMessage); | 169 WebInspector.console.error(errorMessage); |
| 174 else if (fileSystem) | 170 else if (fileSystem) |
| 175 this._innerAddFileSystem(fileSystem); | 171 this._innerAddFileSystem(fileSystem, true); |
| 176 }, | 172 }, |
| 177 | 173 |
| 178 /** | 174 /** |
| 179 * @param {!WebInspector.Event} event | 175 * @param {!WebInspector.Event} event |
| 180 */ | 176 */ |
| 181 _onFileSystemRemoved: function(event) | 177 _onFileSystemRemoved: function(event) |
| 182 { | 178 { |
| 183 this._fileSystemRemoved(/** @type {string} */ (event.data)); | 179 var embedderPath = /** @type {string} */ (event.data); |
| 180 var fileSystemPath = WebInspector.IsolatedFileSystemManager.normalizePat h(embedderPath); | |
| 181 var isolatedFileSystem = this._fileSystems.get(fileSystemPath); | |
| 182 if (!isolatedFileSystem) | |
| 183 return; | |
| 184 this._fileSystems.delete(fileSystemPath); | |
| 185 isolatedFileSystem.fileSystemRemoved(); | |
| 186 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve nts.FileSystemRemoved, isolatedFileSystem); | |
| 184 }, | 187 }, |
| 185 | 188 |
| 186 /** | 189 /** |
| 187 * @param {!WebInspector.Event} event | 190 * @param {!WebInspector.Event} event |
| 188 */ | 191 */ |
| 189 _onFileSystemFilesChanged: function(event) | 192 _onFileSystemFilesChanged: function(event) |
| 190 { | 193 { |
| 191 var embedderPaths = /** @type {!Array<string>} */ (event.data); | 194 var embedderPaths = /** @type {!Array<string>} */ (event.data); |
| 192 var paths = embedderPaths.map(embedderPath => WebInspector.IsolatedFileS ystemManager.normalizePath(embedderPath)); | 195 var paths = embedderPaths.map(embedderPath => WebInspector.IsolatedFileS ystemManager.normalizePath(embedderPath)); |
| 193 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve nts.FileSystemFilesChanged, paths); | 196 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve nts.FileSystemFilesChanged, paths); |
| 194 }, | 197 }, |
| 195 | 198 |
| 196 /** | 199 /** |
| 197 * @param {string} embedderPath | |
| 198 */ | |
| 199 _fileSystemRemoved: function(embedderPath) | |
| 200 { | |
| 201 var fileSystemPath = WebInspector.IsolatedFileSystemManager.normalizePat h(embedderPath); | |
| 202 var isolatedFileSystem = this._fileSystems.get(fileSystemPath); | |
| 203 if (!isolatedFileSystem) | |
| 204 return; | |
| 205 this._fileSystems.delete(fileSystemPath); | |
| 206 isolatedFileSystem.fileSystemRemoved(); | |
| 207 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Eve nts.FileSystemRemoved, isolatedFileSystem); | |
| 208 }, | |
| 209 | |
| 210 /** | |
| 211 * @return {!Array<!WebInspector.IsolatedFileSystem>} | 200 * @return {!Array<!WebInspector.IsolatedFileSystem>} |
| 212 */ | 201 */ |
| 213 fileSystems: function() | 202 fileSystems: function() |
| 214 { | 203 { |
| 215 return this._fileSystems.valuesArray(); | 204 return this._fileSystems.valuesArray(); |
| 216 }, | 205 }, |
| 217 | 206 |
| 218 /** | 207 /** |
| 219 * @param {string} fileSystemPath | 208 * @param {string} fileSystemPath |
| 220 * @return {?WebInspector.IsolatedFileSystem} | 209 * @return {?WebInspector.IsolatedFileSystem} |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 this._callbacks.delete(requestId); | 345 this._callbacks.delete(requestId); |
| 357 }, | 346 }, |
| 358 | 347 |
| 359 __proto__: WebInspector.Object.prototype | 348 __proto__: WebInspector.Object.prototype |
| 360 } | 349 } |
| 361 | 350 |
| 362 /** | 351 /** |
| 363 * @type {!WebInspector.IsolatedFileSystemManager} | 352 * @type {!WebInspector.IsolatedFileSystemManager} |
| 364 */ | 353 */ |
| 365 WebInspector.isolatedFileSystemManager; | 354 WebInspector.isolatedFileSystemManager; |
| OLD | NEW |