Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Persistence.Persistence = class extends Common.Object { | 7 Persistence.Persistence = class extends Common.Object { |
| 8 /** | 8 /** |
| 9 * @param {!Workspace.Workspace} workspace | 9 * @param {!Workspace.Workspace} workspace |
| 10 * @param {!Bindings.BreakpointManager} breakpointManager | 10 * @param {!Bindings.BreakpointManager} breakpointManager |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 binding.network[Persistence.Persistence._binding] = binding; | 43 binding.network[Persistence.Persistence._binding] = binding; |
| 44 binding.fileSystem[Persistence.Persistence._binding] = binding; | 44 binding.fileSystem[Persistence.Persistence._binding] = binding; |
| 45 | 45 |
| 46 binding.fileSystem.forceLoadOnCheckContent(); | 46 binding.fileSystem.forceLoadOnCheckContent(); |
| 47 | 47 |
| 48 binding.network.addEventListener( | 48 binding.network.addEventListener( |
| 49 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); | 49 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); |
| 50 binding.fileSystem.addEventListener( | 50 binding.fileSystem.addEventListener( |
| 51 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); | 51 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); |
| 52 binding.network.addEventListener( | |
| 53 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); | |
| 54 binding.fileSystem.addEventListener( | |
| 55 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); | |
| 52 | 56 |
| 53 this._addFilePathBindingPrefixes(binding.fileSystem.url()); | 57 this._addFilePathBindingPrefixes(binding.fileSystem.url()); |
| 54 | 58 |
| 55 this._moveBreakpoints(binding.fileSystem, binding.network); | 59 this._moveBreakpoints(binding.fileSystem, binding.network); |
| 56 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding); | 60 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding); |
| 57 } | 61 } |
| 58 | 62 |
| 59 /** | 63 /** |
| 60 * @param {!Persistence.PersistenceBinding} binding | 64 * @param {!Persistence.PersistenceBinding} binding |
| 61 */ | 65 */ |
| 62 _onBindingRemoved(binding) { | 66 _onBindingRemoved(binding) { |
| 63 if (binding.network.isDirty()) | 67 if (binding.network.isDirty()) |
|
dgozman
2016/12/01 21:58:12
Let's remove this one?
lushnikov
2016/12/02 02:51:36
Done.
| |
| 64 binding.fileSystem.setWorkingCopy(binding.network.workingCopy()); | 68 binding.fileSystem.setWorkingCopy(binding.network.workingCopy()); |
| 65 | 69 |
| 66 binding.network[Persistence.Persistence._binding] = null; | 70 binding.network[Persistence.Persistence._binding] = null; |
| 67 binding.fileSystem[Persistence.Persistence._binding] = null; | 71 binding.fileSystem[Persistence.Persistence._binding] = null; |
| 68 | 72 |
| 69 binding.network.removeEventListener( | 73 binding.network.removeEventListener( |
| 70 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); | 74 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); |
| 71 binding.fileSystem.removeEventListener( | 75 binding.fileSystem.removeEventListener( |
| 72 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); | 76 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); |
| 77 binding.network.removeEventListener( | |
| 78 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); | |
| 79 binding.fileSystem.removeEventListener( | |
| 80 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); | |
| 73 | 81 |
| 74 this._removeFilePathBindingPrefixes(binding.fileSystem.url()); | 82 this._removeFilePathBindingPrefixes(binding.fileSystem.url()); |
| 75 | 83 |
| 76 this._breakpointManager.copyBreakpoints(binding.network.url(), binding.fileS ystem); | 84 this._breakpointManager.copyBreakpoints(binding.network.url(), binding.fileS ystem); |
| 77 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding); | 85 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding); |
| 78 } | 86 } |
| 79 | 87 |
| 80 /** | 88 /** |
| 81 * @param {!Common.Event} event | 89 * @param {!Common.Event} event |
| 82 */ | 90 */ |
| 91 _onWorkingCopyChanged(event) { | |
| 92 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); | |
| 93 var binding = uiSourceCode[Persistence.Persistence._binding]; | |
| 94 if (!binding || binding[Persistence.Persistence._muteWorkingCopy]) | |
| 95 return; | |
| 96 var other = binding.network === uiSourceCode ? binding.fileSystem : binding. network; | |
| 97 var target = Bindings.NetworkProject.targetForUISourceCode(binding.network); | |
| 98 if (target.isNodeJS()) { | |
| 99 var newContent = uiSourceCode.workingCopy(); | |
| 100 other.requestContent() | |
| 101 .then(currentContent => this._rewrapNodeJSContent(binding, other, curr entContent, newContent)) | |
|
dgozman
2016/12/01 21:58:12
Use workingCopy() instead of currentContent.
lushnikov
2016/12/02 02:51:36
Done.
| |
| 102 .then(newContent => setWorkingCopy.call(this, () => newContent)); | |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 setWorkingCopy.call(this, () => uiSourceCode.workingCopy()); | |
| 107 | |
| 108 /** | |
| 109 * @param {function():string} workingCopyGetter | |
| 110 * @this {Persistence.Persistence} | |
| 111 */ | |
| 112 function setWorkingCopy(workingCopyGetter) { | |
| 113 binding[Persistence.Persistence._muteWorkingCopy] = true; | |
| 114 other.setWorkingCopyGetter(() => uiSourceCode.workingCopy()); | |
|
dgozman
2016/12/01 21:58:12
workingCopyGetter
lushnikov
2016/12/02 02:51:36
Done.
| |
| 115 binding[Persistence.Persistence._muteWorkingCopy] = false; | |
| 116 this._contentSyncedForTest(); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 /** | |
| 121 * @param {!Common.Event} event | |
| 122 */ | |
| 83 _onWorkingCopyCommitted(event) { | 123 _onWorkingCopyCommitted(event) { |
| 84 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); | 124 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| 85 var binding = uiSourceCode[Persistence.Persistence._binding]; | 125 var binding = uiSourceCode[Persistence.Persistence._binding]; |
| 86 if (!binding || binding[Persistence.Persistence._muteCommit]) | 126 if (!binding || binding[Persistence.Persistence._muteCommit]) |
| 87 return; | 127 return; |
| 88 var newContent = /** @type {string} */ (event.data.content); | 128 var newContent = /** @type {string} */ (event.data.content); |
| 89 var other = binding.network === uiSourceCode ? binding.fileSystem : binding. network; | 129 var other = binding.network === uiSourceCode ? binding.fileSystem : binding. network; |
| 90 var target = Bindings.NetworkProject.targetForUISourceCode(binding.network); | 130 var target = Bindings.NetworkProject.targetForUISourceCode(binding.network); |
| 91 if (target.isNodeJS()) { | 131 if (target.isNodeJS()) { |
| 92 other.requestContent().then( | 132 other.requestContent() |
| 93 currentContent => this._syncNodeJSContent(binding, other, currentConte nt, newContent)); | 133 .then(currentContent => this._rewrapNodeJSContent(binding, other, curr entContent, newContent)) |
| 134 .then(newContent => setContent.call(this, newContent)); | |
|
dgozman
2016/12/01 21:58:12
Let's not chain sync calls.
lushnikov
2016/12/02 02:51:36
Done.
| |
| 94 return; | 135 return; |
| 95 } | 136 } |
| 96 binding[Persistence.Persistence._muteCommit] = true; | 137 setContent.call(this, newContent); |
| 97 other.addRevision(newContent); | 138 |
| 98 binding[Persistence.Persistence._muteCommit] = false; | 139 /** |
| 99 this._contentSyncedForTest(); | 140 * @param {string} newContent |
| 141 * @this {Persistence.Persistence} | |
| 142 */ | |
| 143 function setContent(newContent) { | |
| 144 binding[Persistence.Persistence._muteCommit] = true; | |
| 145 other.addRevision(newContent); | |
| 146 binding[Persistence.Persistence._muteCommit] = false; | |
| 147 this._contentSyncedForTest(); | |
| 148 } | |
| 100 } | 149 } |
| 101 | 150 |
| 102 /** | 151 /** |
| 103 * @param {!Persistence.PersistenceBinding} binding | 152 * @param {!Persistence.PersistenceBinding} binding |
| 104 * @param {!Workspace.UISourceCode} uiSourceCode | 153 * @param {!Workspace.UISourceCode} uiSourceCode |
| 105 * @param {string} currentContent | 154 * @param {string} currentContent |
| 106 * @param {string} newContent | 155 * @param {string} newContent |
| 156 * @return {string} | |
| 107 */ | 157 */ |
| 108 _syncNodeJSContent(binding, uiSourceCode, currentContent, newContent) { | 158 _rewrapNodeJSContent(binding, uiSourceCode, currentContent, newContent) { |
| 109 if (uiSourceCode === binding.fileSystem) { | 159 if (uiSourceCode === binding.fileSystem) { |
| 110 if (newContent.startsWith(Persistence.Persistence._NodePrefix) && | 160 if (newContent.startsWith(Persistence.Persistence._NodePrefix) && |
| 111 newContent.endsWith(Persistence.Persistence._NodeSuffix)) { | 161 newContent.endsWith(Persistence.Persistence._NodeSuffix)) { |
| 112 newContent = newContent.substring( | 162 newContent = newContent.substring( |
| 113 Persistence.Persistence._NodePrefix.length, newContent.length - Pers istence.Persistence._NodeSuffix.length); | 163 Persistence.Persistence._NodePrefix.length, newContent.length - Pers istence.Persistence._NodeSuffix.length); |
| 114 } | 164 } |
| 115 if (currentContent.startsWith(Persistence.Persistence._NodeShebang)) | 165 if (currentContent.startsWith(Persistence.Persistence._NodeShebang)) |
| 116 newContent = Persistence.Persistence._NodeShebang + newContent; | 166 newContent = Persistence.Persistence._NodeShebang + newContent; |
| 117 } else { | 167 } else { |
| 118 if (newContent.startsWith(Persistence.Persistence._NodeShebang)) | 168 if (newContent.startsWith(Persistence.Persistence._NodeShebang)) |
| 119 newContent = newContent.substring(Persistence.Persistence._NodeShebang.l ength); | 169 newContent = newContent.substring(Persistence.Persistence._NodeShebang.l ength); |
| 120 if (currentContent.startsWith(Persistence.Persistence._NodePrefix) && | 170 if (currentContent.startsWith(Persistence.Persistence._NodePrefix) && |
| 121 currentContent.endsWith(Persistence.Persistence._NodeSuffix)) | 171 currentContent.endsWith(Persistence.Persistence._NodeSuffix)) |
| 122 newContent = Persistence.Persistence._NodePrefix + newContent + Persiste nce.Persistence._NodeSuffix; | 172 newContent = Persistence.Persistence._NodePrefix + newContent + Persiste nce.Persistence._NodeSuffix; |
| 123 } | 173 } |
| 124 binding[Persistence.Persistence._muteCommit] = true; | 174 return newContent; |
| 125 uiSourceCode.addRevision(newContent); | |
| 126 binding[Persistence.Persistence._muteCommit] = false; | |
| 127 this._contentSyncedForTest(); | |
| 128 } | 175 } |
| 129 | 176 |
| 130 _contentSyncedForTest() { | 177 _contentSyncedForTest() { |
| 131 } | 178 } |
| 132 | 179 |
| 133 /** | 180 /** |
| 134 * @param {!Workspace.UISourceCode} from | 181 * @param {!Workspace.UISourceCode} from |
| 135 * @param {!Workspace.UISourceCode} to | 182 * @param {!Workspace.UISourceCode} to |
| 136 */ | 183 */ |
| 137 _moveBreakpoints(from, to) { | 184 _moveBreakpoints(from, to) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 return this._filePathPrefixesToBindingCount.has(filePath); | 260 return this._filePathPrefixesToBindingCount.has(filePath); |
| 214 } | 261 } |
| 215 | 262 |
| 216 dispose() { | 263 dispose() { |
| 217 this._mapping.dispose(); | 264 this._mapping.dispose(); |
| 218 } | 265 } |
| 219 }; | 266 }; |
| 220 | 267 |
| 221 Persistence.Persistence._binding = Symbol('Persistence.Binding'); | 268 Persistence.Persistence._binding = Symbol('Persistence.Binding'); |
| 222 Persistence.Persistence._muteCommit = Symbol('Persistence.MuteCommit'); | 269 Persistence.Persistence._muteCommit = Symbol('Persistence.MuteCommit'); |
| 270 Persistence.Persistence._muteWorkingCopy = Symbol('Persistence.MuteWorkingCopy') ; | |
| 223 | 271 |
| 224 Persistence.Persistence._NodePrefix = '(function (exports, require, module, __fi lename, __dirname) { '; | 272 Persistence.Persistence._NodePrefix = '(function (exports, require, module, __fi lename, __dirname) { '; |
| 225 Persistence.Persistence._NodeSuffix = '\n});'; | 273 Persistence.Persistence._NodeSuffix = '\n});'; |
| 226 Persistence.Persistence._NodeShebang = '#!/usr/bin/env node'; | 274 Persistence.Persistence._NodeShebang = '#!/usr/bin/env node'; |
| 227 | 275 |
| 228 Persistence.Persistence.Events = { | 276 Persistence.Persistence.Events = { |
| 229 BindingCreated: Symbol('BindingCreated'), | 277 BindingCreated: Symbol('BindingCreated'), |
| 230 BindingRemoved: Symbol('BindingRemoved') | 278 BindingRemoved: Symbol('BindingRemoved') |
| 231 }; | 279 }; |
| 232 | 280 |
| 233 /** | 281 /** |
| 234 * @unrestricted | 282 * @unrestricted |
| 235 */ | 283 */ |
| 236 Persistence.PersistenceBinding = class { | 284 Persistence.PersistenceBinding = class { |
| 237 /** | 285 /** |
| 238 * @param {!Workspace.UISourceCode} network | 286 * @param {!Workspace.UISourceCode} network |
| 239 * @param {!Workspace.UISourceCode} fileSystem | 287 * @param {!Workspace.UISourceCode} fileSystem |
| 240 * @param {boolean} exactMatch | 288 * @param {boolean} exactMatch |
| 241 */ | 289 */ |
| 242 constructor(network, fileSystem, exactMatch) { | 290 constructor(network, fileSystem, exactMatch) { |
| 243 this.network = network; | 291 this.network = network; |
| 244 this.fileSystem = fileSystem; | 292 this.fileSystem = fileSystem; |
| 245 this.exactMatch = exactMatch; | 293 this.exactMatch = exactMatch; |
| 246 } | 294 } |
| 247 }; | 295 }; |
| 248 | 296 |
| 249 /** @type {!Persistence.Persistence} */ | 297 /** @type {!Persistence.Persistence} */ |
| 250 Persistence.persistence; | 298 Persistence.persistence; |
| OLD | NEW |