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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace_diff/WorkspaceDiff.js

Issue 2925023003: DevTools: Avoid a race in WorkspaceDiff when UISourceCodes are removed (Closed)
Patch Set: Created 3 years, 6 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 5
6 WorkspaceDiff.WorkspaceDiff = class extends Common.Object { 6 WorkspaceDiff.WorkspaceDiff = class extends Common.Object {
7 /** 7 /**
8 * @param {!Workspace.Workspace} workspace 8 * @param {!Workspace.Workspace} workspace
9 */ 9 */
10 constructor(workspace) { 10 constructor(workspace) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 _uiSourceCodeAdded(event) { 82 _uiSourceCodeAdded(event) {
83 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); 83 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
84 this._updateModifiedState(uiSourceCode); 84 this._updateModifiedState(uiSourceCode);
85 } 85 }
86 86
87 /** 87 /**
88 * @param {!Common.Event} event 88 * @param {!Common.Event} event
89 */ 89 */
90 _uiSourceCodeRemoved(event) { 90 _uiSourceCodeRemoved(event) {
91 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); 91 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
92 this._loadingUISourceCodes.delete(uiSourceCode); 92 this._removeUISourceCode(uiSourceCode);
93 this._markAsUnmodified(uiSourceCode);
94 } 93 }
95 94
96 /** 95 /**
97 * @param {!Common.Event} event 96 * @param {!Common.Event} event
98 */ 97 */
99 _projectRemoved(event) { 98 _projectRemoved(event) {
100 var project = /** @type {!Workspace.Project} */ (event.data); 99 var project = /** @type {!Workspace.Project} */ (event.data);
101 for (var uiSourceCode of project.uiSourceCodes()) { 100 for (var uiSourceCode of project.uiSourceCodes())
102 this._loadingUISourceCodes.delete(uiSourceCode); 101 this._removeUISourceCode(uiSourceCode);
103 this._markAsUnmodified(uiSourceCode); 102 }
104 } 103
104 _removeUISourceCode(uiSourceCode) {
lushnikov 2017/06/08 00:06:51 let's jsdoc this
einbinder 2017/06/08 01:27:55 Done.
105 this._loadingUISourceCodes.delete(uiSourceCode);
106 var uiSourceCodeDiff = this._uiSourceCodeDiffs.get(uiSourceCode);
107 if (uiSourceCodeDiff)
108 uiSourceCodeDiff._invalidated = true;
109 this._markAsUnmodified(uiSourceCode);
105 } 110 }
106 111
107 /** 112 /**
108 * @param {!Workspace.UISourceCode} uiSourceCode 113 * @param {!Workspace.UISourceCode} uiSourceCode
109 */ 114 */
110 _markAsUnmodified(uiSourceCode) { 115 _markAsUnmodified(uiSourceCode) {
111 this._uiSourceCodeProcessedForTest(); 116 this._uiSourceCodeProcessedForTest();
112 if (this._modifiedUISourceCodes.delete(uiSourceCode)) 117 if (this._modifiedUISourceCodes.delete(uiSourceCode))
113 this.dispatchEventToListeners(WorkspaceDiff.Events.ModifiedStatusChanged, {uiSourceCode, isModified: false}); 118 this.dispatchEventToListeners(WorkspaceDiff.Events.ModifiedStatusChanged, {uiSourceCode, isModified: false});
114 } 119 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 /** 169 /**
165 * @param {!Workspace.UISourceCode} uiSourceCode 170 * @param {!Workspace.UISourceCode} uiSourceCode
166 */ 171 */
167 constructor(uiSourceCode) { 172 constructor(uiSourceCode) {
168 super(); 173 super();
169 this._uiSourceCode = uiSourceCode; 174 this._uiSourceCode = uiSourceCode;
170 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyChang ed, this._uiSourceCodeChanged, this); 175 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyChang ed, this._uiSourceCodeChanged, this);
171 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCommi tted, this._uiSourceCodeChanged, this); 176 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCommi tted, this._uiSourceCodeChanged, this);
172 this._requestDiffPromise = null; 177 this._requestDiffPromise = null;
173 this._pendingChanges = null; 178 this._pendingChanges = null;
179 this._invalidated = false;
lushnikov 2017/06/08 00:06:51 how about this._disposed? Feels like a better name
einbinder 2017/06/08 01:27:55 Done.
174 } 180 }
175 181
176 _uiSourceCodeChanged() { 182 _uiSourceCodeChanged() {
177 if (this._pendingChanges) { 183 if (this._pendingChanges) {
178 clearTimeout(this._pendingChanges); 184 clearTimeout(this._pendingChanges);
179 this._pendingChanges = null; 185 this._pendingChanges = null;
180 } 186 }
181 this._requestDiffPromise = null; 187 this._requestDiffPromise = null;
182 188
183 var content = this._uiSourceCode.content(); 189 var content = this._uiSourceCode.content();
184 var delay = (!content || content.length < 65536) ? 0 : WorkspaceDiff.Workspa ceDiff.UpdateTimeout; 190 var delay = (!content || content.length < 65536) ? 0 : WorkspaceDiff.Workspa ceDiff.UpdateTimeout;
185 this._pendingChanges = setTimeout(emitDiffChanged.bind(this), delay); 191 this._pendingChanges = setTimeout(emitDiffChanged.bind(this), delay);
186 192
187 /** 193 /**
188 * @this {WorkspaceDiff.WorkspaceDiff.UISourceCodeDiff} 194 * @this {WorkspaceDiff.WorkspaceDiff.UISourceCodeDiff}
189 */ 195 */
190 function emitDiffChanged() { 196 function emitDiffChanged() {
197 if (this._invalidated)
198 return;
191 this.dispatchEventToListeners(WorkspaceDiff.Events.DiffChanged); 199 this.dispatchEventToListeners(WorkspaceDiff.Events.DiffChanged);
192 this._pendingChanges = null; 200 this._pendingChanges = null;
193 } 201 }
194 } 202 }
195 203
196 /** 204 /**
197 * @return {!Promise<?Diff.Diff.DiffArray>} 205 * @return {!Promise<?Diff.Diff.DiffArray>}
198 */ 206 */
199 requestDiff() { 207 requestDiff() {
200 if (!this._requestDiffPromise) 208 if (!this._requestDiffPromise)
201 this._requestDiffPromise = this._innerRequestDiff(); 209 this._requestDiffPromise = this._innerRequestDiff();
202 return this._requestDiffPromise; 210 return this._requestDiffPromise;
203 } 211 }
204 212
205 /** 213 /**
206 * @return {!Promise<?Diff.Diff.DiffArray>} 214 * @return {!Promise<?Diff.Diff.DiffArray>}
207 */ 215 */
208 async _innerRequestDiff() { 216 async _innerRequestDiff() {
217 if (this._invalidated)
218 return null;
219
209 var current = this._uiSourceCode.workingCopy(); 220 var current = this._uiSourceCode.workingCopy();
210 if (!current && !this._uiSourceCode.contentLoaded()) 221 if (!current && !this._uiSourceCode.contentLoaded())
211 current = await this._uiSourceCode.requestContent(); 222 current = await this._uiSourceCode.requestContent();
lushnikov 2017/06/08 00:06:51 while we are here: let's add a huge // ------ ASYN
einbinder 2017/06/08 01:27:55 Done.
223 if (this._invalidated)
224 return null;
225
212 var baseline = await this._uiSourceCode.requestOriginalContent(); 226 var baseline = await this._uiSourceCode.requestOriginalContent();
lushnikov 2017/06/08 00:06:51 and let's add the "ASYNC" comment here as well
einbinder 2017/06/08 01:27:55 Done.
227 if (this._invalidated)
228 return null;
229
213 if (current === null || baseline === null) 230 if (current === null || baseline === null)
214 return null; 231 return null;
215 return Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n')); 232 return Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n'));
216 } 233 }
217 }; 234 };
218 235
219 /** 236 /**
220 * @enum {symbol} 237 * @enum {symbol}
221 */ 238 */
222 WorkspaceDiff.Events = { 239 WorkspaceDiff.Events = {
223 DiffChanged: Symbol('DiffChanged'), 240 DiffChanged: Symbol('DiffChanged'),
224 ModifiedStatusChanged: Symbol('ModifiedStatusChanged') 241 ModifiedStatusChanged: Symbol('ModifiedStatusChanged')
225 }; 242 };
226 243
227 /** 244 /**
228 * @return {!WorkspaceDiff.WorkspaceDiff} 245 * @return {!WorkspaceDiff.WorkspaceDiff}
229 */ 246 */
230 WorkspaceDiff.workspaceDiff = function() { 247 WorkspaceDiff.workspaceDiff = function() {
231 if (!WorkspaceDiff.WorkspaceDiff._instance) 248 if (!WorkspaceDiff.WorkspaceDiff._instance)
232 WorkspaceDiff.WorkspaceDiff._instance = new WorkspaceDiff.WorkspaceDiff(Work space.workspace); 249 WorkspaceDiff.WorkspaceDiff._instance = new WorkspaceDiff.WorkspaceDiff(Work space.workspace);
233 return WorkspaceDiff.WorkspaceDiff._instance; 250 return WorkspaceDiff.WorkspaceDiff._instance;
234 }; 251 };
235 252
236 WorkspaceDiff.WorkspaceDiff.UpdateTimeout = 200; 253 WorkspaceDiff.WorkspaceDiff.UpdateTimeout = 200;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698