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.Automapping = class { | 7 Persistence.Automapping = class { |
8 /** | 8 /** |
9 * @param {!Workspace.Workspace} workspace | 9 * @param {!Workspace.Workspace} workspace |
10 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated | 10 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 networkSourceCode[Persistence.Automapping._processingPromise] = createBindin
gPromise; | 142 networkSourceCode[Persistence.Automapping._processingPromise] = createBindin
gPromise; |
143 | 143 |
144 /** | 144 /** |
145 * @param {?Persistence.PersistenceBinding} binding | 145 * @param {?Persistence.PersistenceBinding} binding |
146 * @this {Persistence.Automapping} | 146 * @this {Persistence.Automapping} |
147 */ | 147 */ |
148 function onBinding(binding) { | 148 function onBinding(binding) { |
149 if (networkSourceCode[Persistence.Automapping._processingPromise] !== crea
teBindingPromise) | 149 if (networkSourceCode[Persistence.Automapping._processingPromise] !== crea
teBindingPromise) |
150 return; | 150 return; |
151 networkSourceCode[Persistence.Automapping._processingPromise] = null; | 151 networkSourceCode[Persistence.Automapping._processingPromise] = null; |
152 if (!binding) { | 152 if (!binding || this._disposed) { |
153 this._onBindingFailedForTest(); | 153 this._onBindingFailedForTest(); |
154 return; | 154 return; |
155 } | 155 } |
156 // TODO(lushnikov): remove this check once there's a single uiSourceCode p
er url. @see crbug.com/670180 | 156 // TODO(lushnikov): remove this check once there's a single uiSourceCode p
er url. @see crbug.com/670180 |
157 if (binding.network[Persistence.Automapping._binding] || binding.fileSyste
m[Persistence.Automapping._binding]) | 157 if (binding.network[Persistence.Automapping._binding] || binding.fileSyste
m[Persistence.Automapping._binding]) |
158 return; | 158 return; |
159 | 159 |
160 this._bindings.add(binding); | 160 this._bindings.add(binding); |
161 binding.network[Persistence.Automapping._binding] = binding; | 161 binding.network[Persistence.Automapping._binding] = binding; |
162 binding.fileSystem[Persistence.Automapping._binding] = binding; | 162 binding.fileSystem[Persistence.Automapping._binding] = binding; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 var fileMetadata = file[Persistence.Automapping._metadata]; | 270 var fileMetadata = file[Persistence.Automapping._metadata]; |
271 if (!fileMetadata) | 271 if (!fileMetadata) |
272 return false; | 272 return false; |
273 // Allow a second of difference due to network timestamps lack of precisio
n. | 273 // Allow a second of difference due to network timestamps lack of precisio
n. |
274 var timeMatches = !networkMetadata.modificationTime || | 274 var timeMatches = !networkMetadata.modificationTime || |
275 Math.abs(networkMetadata.modificationTime - fileMetadata.modificationT
ime) < 1000; | 275 Math.abs(networkMetadata.modificationTime - fileMetadata.modificationT
ime) < 1000; |
276 var contentMatches = !networkMetadata.contentSize || fileMetadata.contentS
ize === networkMetadata.contentSize; | 276 var contentMatches = !networkMetadata.contentSize || fileMetadata.contentS
ize === networkMetadata.contentSize; |
277 return timeMatches && contentMatches; | 277 return timeMatches && contentMatches; |
278 }); | 278 }); |
279 } | 279 } |
| 280 |
| 281 dispose() { |
| 282 if (this._disposed) |
| 283 return; |
| 284 this._disposed = true; |
| 285 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 286 for (var binding of this._bindings.valuesArray()) |
| 287 this._unbindNetwork(binding.network); |
| 288 } |
280 }; | 289 }; |
281 | 290 |
282 Persistence.Automapping._binding = Symbol('Automapping.Binding'); | 291 Persistence.Automapping._binding = Symbol('Automapping.Binding'); |
283 Persistence.Automapping._processingPromise = Symbol('Automapping.ProcessingPromi
se'); | 292 Persistence.Automapping._processingPromise = Symbol('Automapping.ProcessingPromi
se'); |
284 Persistence.Automapping._metadata = Symbol('Automapping.Metadata'); | 293 Persistence.Automapping._metadata = Symbol('Automapping.Metadata'); |
285 | 294 |
286 /** | 295 /** |
287 * @unrestricted | 296 * @unrestricted |
288 */ | 297 */ |
289 Persistence.Automapping.PathEncoder = class { | 298 Persistence.Automapping.PathEncoder = class { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 /** | 411 /** |
403 * @param {string} path | 412 * @param {string} path |
404 * @return {string} | 413 * @return {string} |
405 */ | 414 */ |
406 closestParentFolder(path) { | 415 closestParentFolder(path) { |
407 var encodedPath = this._encoder.encode(path); | 416 var encodedPath = this._encoder.encode(path); |
408 var commonPrefix = this._index.longestPrefix(encodedPath, true); | 417 var commonPrefix = this._index.longestPrefix(encodedPath, true); |
409 return this._encoder.decode(commonPrefix); | 418 return this._encoder.decode(commonPrefix); |
410 } | 419 } |
411 }; | 420 }; |
OLD | NEW |