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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js

Issue 1609973002: DevTools: promisify ContentProvider.requestContent and all its clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 11 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 | « third_party/WebKit/Source/devtools/front_end/sources/SourcesSearchScope.js ('k') | 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 30 matching lines...) Expand all
41 { 41 {
42 this._project = project; 42 this._project = project;
43 this._url = url; 43 this._url = url;
44 44
45 var pathComponents = WebInspector.ParsedURL.splitURLIntoPathComponents(url); 45 var pathComponents = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
46 this._origin = pathComponents[0]; 46 this._origin = pathComponents[0];
47 this._parentURL = pathComponents.slice(0, -1).join("/"); 47 this._parentURL = pathComponents.slice(0, -1).join("/");
48 this._name = pathComponents[pathComponents.length - 1]; 48 this._name = pathComponents[pathComponents.length - 1];
49 49
50 this._contentType = contentType; 50 this._contentType = contentType;
51 /** @type {!Array.<function(?string)>} */ 51 /** @type {?function(?string)} */
52 this._requestContentCallbacks = []; 52 this._requestContentCallback = null;
53 /** @type {?Promise<?string>} */
54 this._requestContentPromise = null;
53 55
54 /** @type {!Array.<!WebInspector.Revision>} */ 56 /** @type {!Array.<!WebInspector.Revision>} */
55 this.history = []; 57 this.history = [];
56 this._hasUnsavedCommittedChanges = false; 58 this._hasUnsavedCommittedChanges = false;
57 59
58 /** @type {!Array<!WebInspector.UISourceCode.Message>} */ 60 /** @type {!Array<!WebInspector.UISourceCode.Message>} */
59 this._messages = []; 61 this._messages = [];
60 } 62 }
61 63
62 /** 64 /**
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 /** 217 /**
216 * @return {!WebInspector.Project} 218 * @return {!WebInspector.Project}
217 */ 219 */
218 project: function() 220 project: function()
219 { 221 {
220 return this._project; 222 return this._project;
221 }, 223 },
222 224
223 /** 225 /**
224 * @override 226 * @override
225 * @param {function(?string)} callback 227 * @return {!Promise<?string>}
226 */ 228 */
227 requestContent: function(callback) 229 requestContent: function()
228 { 230 {
229 if (this._content || this._contentLoaded) { 231 if (this._content || this._contentLoaded)
230 callback(this._content); 232 return Promise.resolve(this._content);
231 return; 233 var promise = this._requestContentPromise;
234 if (!promise) {
235 promise = new Promise(fulfill => this._requestContentCallback = fulf ill);
236 this._requestContentPromise = promise;
237 this._project.requestFileContent(this, this._fireContentAvailable.bi nd(this));
232 } 238 }
233 this._requestContentCallbacks.push(callback); 239 return promise;
234 if (this._requestContentCallbacks.length === 1)
235 this._project.requestFileContent(this, this._fireContentAvailable.bi nd(this));
236 }, 240 },
237 241
238 /** 242 /**
239 * @return {!Promise.<?string>}
240 */
241 requestContentPromise: function()
242 {
243 return new Promise(succ => this.requestContent(succ));
244 },
245
246 /**
247 * @param {function()} callback 243 * @param {function()} callback
248 */ 244 */
249 _pushCheckContentUpdatedCallback: function(callback) 245 _pushCheckContentUpdatedCallback: function(callback)
250 { 246 {
251 if (!this._checkContentUpdatedCallbacks) 247 if (!this._checkContentUpdatedCallbacks)
252 this._checkContentUpdatedCallbacks = []; 248 this._checkContentUpdatedCallbacks = [];
253 this._checkContentUpdatedCallbacks.push(callback); 249 this._checkContentUpdatedCallbacks.push(callback);
254 }, 250 },
255 251
256 _terminateContentCheck: function() 252 _terminateContentCheck: function()
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 this._terminateContentCheck(); 321 this._terminateContentCheck();
326 } 322 }
327 }, 323 },
328 324
329 forceLoadOnCheckContent: function() 325 forceLoadOnCheckContent: function()
330 { 326 {
331 this._forceLoadOnCheckContent = true; 327 this._forceLoadOnCheckContent = true;
332 }, 328 },
333 329
334 /** 330 /**
335 * @param {function(?string)} callback 331 * @return {!Promise<?string>}
336 */ 332 */
337 requestOriginalContent: function(callback) 333 requestOriginalContent: function()
338 { 334 {
335 var callback;
336 var promise = new Promise(fulfill => callback = fulfill);
339 this._project.requestFileContent(this, callback); 337 this._project.requestFileContent(this, callback);
338 return promise;
340 }, 339 },
341 340
342 /** 341 /**
343 * @param {string} content 342 * @param {string} content
344 */ 343 */
345 _commitContent: function(content) 344 _commitContent: function(content)
346 { 345 {
347 var wasPersisted = false; 346 var wasPersisted = false;
348 if (this._project.canSetFileContent()) { 347 if (this._project.canSetFileContent()) {
349 this._project.setFileContent(this, content, function() { }); 348 this._project.setFileContent(this, content, function() { });
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 }, 407 },
409 408
410 /** 409 /**
411 * @param {string} content 410 * @param {string} content
412 */ 411 */
413 addRevision: function(content) 412 addRevision: function(content)
414 { 413 {
415 this._commitContent(content); 414 this._commitContent(content);
416 }, 415 },
417 416
417 /**
418 * @return {!Promise}
419 */
418 revertToOriginal: function() 420 revertToOriginal: function()
419 { 421 {
420 /** 422 /**
421 * @this {WebInspector.UISourceCode} 423 * @this {WebInspector.UISourceCode}
422 * @param {?string} content 424 * @param {?string} content
423 */ 425 */
424 function callback(content) 426 function callback(content)
425 { 427 {
426 if (typeof content !== "string") 428 if (typeof content !== "string")
427 return; 429 return;
428 430
429 this.addRevision(content); 431 this.addRevision(content);
430 } 432 }
431 433
432 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied); 434 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied);
433 this.requestOriginalContent(callback.bind(this)); 435 return this.requestOriginalContent().then(callback.bind(this));
434 }, 436 },
435 437
436 /** 438 /**
437 * @param {function(!WebInspector.UISourceCode)} callback 439 * @param {function(!WebInspector.UISourceCode)} callback
438 */ 440 */
439 revertAndClearHistory: function(callback) 441 revertAndClearHistory: function(callback)
440 { 442 {
441 /** 443 /**
442 * @this {WebInspector.UISourceCode} 444 * @this {WebInspector.UISourceCode}
443 * @param {?string} content 445 * @param {?string} content
444 */ 446 */
445 function revert(content) 447 function revert(content)
446 { 448 {
447 if (typeof content !== "string") 449 if (typeof content !== "string")
448 return; 450 return;
449 451
450 this.addRevision(content); 452 this.addRevision(content);
451 this.history = []; 453 this.history = [];
452 callback(this); 454 callback(this);
453 } 455 }
454 456
455 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied); 457 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied);
456 this.requestOriginalContent(revert.bind(this)); 458 this.requestOriginalContent().then(revert.bind(this));
457 }, 459 },
458 460
459 /** 461 /**
460 * @return {string} 462 * @return {string}
461 */ 463 */
462 workingCopy: function() 464 workingCopy: function()
463 { 465 {
464 if (this._workingCopyGetter) { 466 if (this._workingCopyGetter) {
465 this._workingCopy = this._workingCopyGetter(); 467 this._workingCopy = this._workingCopyGetter();
466 delete this._workingCopyGetter; 468 delete this._workingCopyGetter;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 }, 559 },
558 560
559 /** 561 /**
560 * @param {?string} content 562 * @param {?string} content
561 */ 563 */
562 _fireContentAvailable: function(content) 564 _fireContentAvailable: function(content)
563 { 565 {
564 this._contentLoaded = true; 566 this._contentLoaded = true;
565 this._content = content; 567 this._content = content;
566 568
567 var callbacks = this._requestContentCallbacks.slice(); 569 var callback = this._requestContentCallback;
568 this._requestContentCallbacks = []; 570 this._requestContentCallback = null;
569 for (var i = 0; i < callbacks.length; ++i) 571 this._requestContentPromise = null;
570 callbacks[i](content); 572
573 callback.call(null, content);
571 }, 574 },
572 575
573 /** 576 /**
574 * @return {boolean} 577 * @return {boolean}
575 */ 578 */
576 contentLoaded: function() 579 contentLoaded: function()
577 { 580 {
578 return this._contentLoaded; 581 return this._contentLoaded;
579 }, 582 },
580 583
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 }, 721 },
719 722
720 /** 723 /**
721 * @return {?string} 724 * @return {?string}
722 */ 725 */
723 get content() 726 get content()
724 { 727 {
725 return this._content || null; 728 return this._content || null;
726 }, 729 },
727 730
731 /**
732 * @return {!Promise}
733 */
728 revertToThis: function() 734 revertToThis: function()
729 { 735 {
730 /** 736 /**
731 * @param {string} content 737 * @param {?string} content
732 * @this {WebInspector.Revision} 738 * @this {WebInspector.Revision}
733 */ 739 */
734 function revert(content) 740 function revert(content)
735 { 741 {
736 if (this._uiSourceCode._content !== content) 742 if (content && this._uiSourceCode._content !== content)
737 this._uiSourceCode.addRevision(content); 743 this._uiSourceCode.addRevision(content);
738 } 744 }
739 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied); 745 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Rev isionApplied);
740 this.requestContent(revert.bind(this)); 746 return this.requestContent().then(revert.bind(this));
741 }, 747 },
742 748
743 /** 749 /**
744 * @override 750 * @override
745 * @return {string} 751 * @return {string}
746 */ 752 */
747 contentURL: function() 753 contentURL: function()
748 { 754 {
749 return this._uiSourceCode.url(); 755 return this._uiSourceCode.url();
750 }, 756 },
751 757
752 /** 758 /**
753 * @override 759 * @override
754 * @return {!WebInspector.ResourceType} 760 * @return {!WebInspector.ResourceType}
755 */ 761 */
756 contentType: function() 762 contentType: function()
757 { 763 {
758 return this._uiSourceCode.contentType(); 764 return this._uiSourceCode.contentType();
759 }, 765 },
760 766
761 /** 767 /**
762 * @override 768 * @override
763 * @param {function(string)} callback 769 * @return {!Promise<?string>}
764 */ 770 */
765 requestContent: function(callback) 771 requestContent: function()
766 { 772 {
767 callback(this._content || ""); 773 return Promise.resolve(/** @type {?string} */(this._content || ""));
768 }, 774 },
769 775
770 /** 776 /**
771 * @override 777 * @override
772 * @param {string} query 778 * @param {string} query
773 * @param {boolean} caseSensitive 779 * @param {boolean} caseSensitive
774 * @param {boolean} isRegex 780 * @param {boolean} isRegex
775 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback 781 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback
776 */ 782 */
777 searchInContent: function(query, caseSensitive, isRegex, callback) 783 searchInContent: function(query, caseSensitive, isRegex, callback)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 isEqual: function(another) 864 isEqual: function(another)
859 { 865 {
860 return this._uiSourceCode === another._uiSourceCode && this.text() === a nother.text() && this.level() === another.level() && this.range().equal(another. range()); 866 return this._uiSourceCode === another._uiSourceCode && this.text() === a nother.text() && this.level() === another.level() && this.range().equal(another. range());
861 }, 867 },
862 868
863 remove: function() 869 remove: function()
864 { 870 {
865 this._uiSourceCode.removeMessage(this); 871 this._uiSourceCode.removeMessage(this);
866 } 872 }
867 } 873 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sources/SourcesSearchScope.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698