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

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

Issue 2585393003: DevTools: [Persistence] implement Persistence.subscribeForBindingEvents (Closed)
Patch Set: address comments Created 3 years, 12 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * @param {!Workspace.FileSystemMapping} fileSystemMapping 11 * @param {!Workspace.FileSystemMapping} fileSystemMapping
12 */ 12 */
13 constructor(workspace, breakpointManager, fileSystemMapping) { 13 constructor(workspace, breakpointManager, fileSystemMapping) {
14 super(); 14 super();
15 this._workspace = workspace; 15 this._workspace = workspace;
16 this._breakpointManager = breakpointManager; 16 this._breakpointManager = breakpointManager;
17 /** @type {!Map<string, number>} */ 17 /** @type {!Map<string, number>} */
18 this._filePathPrefixesToBindingCount = new Map(); 18 this._filePathPrefixesToBindingCount = new Map();
19 19
20 /** @type {!Multimap<!Workspace.UISourceCode, function()>} */
21 this._subscribedBindingEventListeners = new Multimap();
22
20 if (Runtime.experiments.isEnabled('persistence2')) { 23 if (Runtime.experiments.isEnabled('persistence2')) {
21 var linkDecorator = new Persistence.PersistenceUtils.LinkDecorator(this); 24 var linkDecorator = new Persistence.PersistenceUtils.LinkDecorator(this);
22 Components.Linkifier.setLinkDecorator(linkDecorator); 25 Components.Linkifier.setLinkDecorator(linkDecorator);
23 this._mapping = 26 this._mapping =
24 new Persistence.Automapping(workspace, this._validateBinding.bind(this ), this._onBindingRemoved.bind(this)); 27 new Persistence.Automapping(workspace, this._validateBinding.bind(this ), this._onBindingRemoved.bind(this));
25 } else { 28 } else {
26 this._mapping = new Persistence.DefaultMapping( 29 this._mapping = new Persistence.DefaultMapping(
27 workspace, fileSystemMapping, this._validateBinding.bind(this), this._ onBindingRemoved.bind(this)); 30 workspace, fileSystemMapping, this._validateBinding.bind(this), this._ onBindingRemoved.bind(this));
28 } 31 }
29 } 32 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 binding.fileSystem.addEventListener( 90 binding.fileSystem.addEventListener(
88 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); 91 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this);
89 binding.network.addEventListener( 92 binding.network.addEventListener(
90 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); 93 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this);
91 binding.fileSystem.addEventListener( 94 binding.fileSystem.addEventListener(
92 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); 95 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this);
93 96
94 this._addFilePathBindingPrefixes(binding.fileSystem.url()); 97 this._addFilePathBindingPrefixes(binding.fileSystem.url());
95 98
96 this._moveBreakpoints(binding.fileSystem, binding.network); 99 this._moveBreakpoints(binding.fileSystem, binding.network);
100
101 this._notifyBindingEvent(binding.network);
102 this._notifyBindingEvent(binding.fileSystem);
97 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding); 103 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding);
98 } 104 }
99 105
100 /** 106 /**
101 * @param {!Persistence.PersistenceBinding} binding 107 * @param {!Persistence.PersistenceBinding} binding
102 */ 108 */
103 _onBindingRemoved(binding) { 109 _onBindingRemoved(binding) {
104 binding._removed = true; 110 binding._removed = true;
105 if (binding.network[Persistence.Persistence._binding] !== binding) 111 if (binding.network[Persistence.Persistence._binding] !== binding)
106 return; 112 return;
107 console.assert( 113 console.assert(
108 binding.network[Persistence.Persistence._binding] === binding.fileSystem [Persistence.Persistence._binding], 114 binding.network[Persistence.Persistence._binding] === binding.fileSystem [Persistence.Persistence._binding],
109 'ERROR: inconsistent binding for networkURL ' + binding.network.url()); 115 'ERROR: inconsistent binding for networkURL ' + binding.network.url());
110 116
111 binding.network[Persistence.Persistence._binding] = null; 117 binding.network[Persistence.Persistence._binding] = null;
112 binding.fileSystem[Persistence.Persistence._binding] = null; 118 binding.fileSystem[Persistence.Persistence._binding] = null;
113 119
114 binding.network.removeEventListener( 120 binding.network.removeEventListener(
115 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); 121 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this);
116 binding.fileSystem.removeEventListener( 122 binding.fileSystem.removeEventListener(
117 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this); 123 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyC ommitted, this);
118 binding.network.removeEventListener( 124 binding.network.removeEventListener(
119 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); 125 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this);
120 binding.fileSystem.removeEventListener( 126 binding.fileSystem.removeEventListener(
121 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this); 127 Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyCha nged, this);
122 128
123 this._removeFilePathBindingPrefixes(binding.fileSystem.url()); 129 this._removeFilePathBindingPrefixes(binding.fileSystem.url());
130 this._breakpointManager.copyBreakpoints(binding.network.url(), binding.fileS ystem);
124 131
125 this._breakpointManager.copyBreakpoints(binding.network.url(), binding.fileS ystem); 132 this._notifyBindingEvent(binding.network);
133 this._notifyBindingEvent(binding.fileSystem);
126 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding); 134 this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding);
127 } 135 }
128 136
129 /** 137 /**
130 * @param {!Common.Event} event 138 * @param {!Common.Event} event
131 */ 139 */
132 _onWorkingCopyChanged(event) { 140 _onWorkingCopyChanged(event) {
133 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); 141 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
134 var binding = uiSourceCode[Persistence.Persistence._binding]; 142 var binding = uiSourceCode[Persistence.Persistence._binding];
135 if (!binding || binding[Persistence.Persistence._muteWorkingCopy]) 143 if (!binding || binding[Persistence.Persistence._muteWorkingCopy])
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 /** 269 /**
262 * @param {!Workspace.UISourceCode} uiSourceCode 270 * @param {!Workspace.UISourceCode} uiSourceCode
263 * @return {?Persistence.PersistenceBinding} 271 * @return {?Persistence.PersistenceBinding}
264 */ 272 */
265 binding(uiSourceCode) { 273 binding(uiSourceCode) {
266 return uiSourceCode[Persistence.Persistence._binding] || null; 274 return uiSourceCode[Persistence.Persistence._binding] || null;
267 } 275 }
268 276
269 /** 277 /**
270 * @param {!Workspace.UISourceCode} uiSourceCode 278 * @param {!Workspace.UISourceCode} uiSourceCode
279 * @param {function()} listener
280 */
281 subscribeForBindingEvent(uiSourceCode, listener) {
282 this._subscribedBindingEventListeners.set(uiSourceCode, listener);
283 }
284
285 /**
286 * @param {!Workspace.UISourceCode} uiSourceCode
287 * @param {function()} listener
288 */
289 unsubscribeFromBindingEvent(uiSourceCode, listener) {
290 this._subscribedBindingEventListeners.remove(uiSourceCode, listener);
291 }
292
293 /**
294 * @param {!Workspace.UISourceCode} uiSourceCode
295 */
296 _notifyBindingEvent(uiSourceCode) {
297 if (!this._subscribedBindingEventListeners.has(uiSourceCode))
298 return;
299 var listeners = Array.from(this._subscribedBindingEventListeners.get(uiSourc eCode));
300 for (var listener of listeners)
301 listener.call(null);
302 }
303
304 /**
305 * @param {!Workspace.UISourceCode} uiSourceCode
271 * @return {?Workspace.UISourceCode} 306 * @return {?Workspace.UISourceCode}
272 */ 307 */
273 fileSystem(uiSourceCode) { 308 fileSystem(uiSourceCode) {
274 var binding = this.binding(uiSourceCode); 309 var binding = this.binding(uiSourceCode);
275 return binding ? binding.fileSystem : null; 310 return binding ? binding.fileSystem : null;
276 } 311 }
277 312
278 /** 313 /**
279 * @param {string} filePath 314 * @param {string} filePath
280 */ 315 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 constructor(network, fileSystem, exactMatch) { 377 constructor(network, fileSystem, exactMatch) {
343 this.network = network; 378 this.network = network;
344 this.fileSystem = fileSystem; 379 this.fileSystem = fileSystem;
345 this.exactMatch = exactMatch; 380 this.exactMatch = exactMatch;
346 this._removed = false; 381 this._removed = false;
347 } 382 }
348 }; 383 };
349 384
350 /** @type {!Persistence.Persistence} */ 385 /** @type {!Persistence.Persistence} */
351 Persistence.persistence; 386 Persistence.persistence;
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698