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

Unified Diff: third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js

Issue 2588503002: DevTools: Cache the original content on UISourceCode (Closed)
Patch Set: Move logic to the project level Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js b/third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js
index 0dc66a264cc229478caee2209668dd844227d723..29f937f8b10fcaae9f5c139c831c4cee574dad73 100644
--- a/third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js
@@ -554,6 +554,8 @@ Snippets.SnippetsProject = class extends Bindings.ContentProviderBasedProject {
constructor(workspace, model) {
super(workspace, 'snippets:', Workspace.projectTypes.Snippets, '', false /* isServiceProject */);
this._model = model;
+ /** @type {!WeakMap<!Workspace.UISourceCode, !Promise<?string>>} */
+ this._originalContent = new WeakMap();
}
/**
@@ -572,16 +574,30 @@ Snippets.SnippetsProject = class extends Bindings.ContentProviderBasedProject {
canSetFileContent() {
return true;
}
+ /**
+ * @override
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ * @return {!Promise<?string>}
+ */
+ requestOriginalFileContent(uiSourceCode) {
+ if (this._originalContent.has(uiSourceCode))
+ return this._originalContent.get(uiSourceCode);
+ var promise = super.requestOriginalFileContent(uiSourceCode);
+ this._originalContent.set(uiSourceCode, promise);
+ return promise;
+ }
/**
* @override
* @param {!Workspace.UISourceCode} uiSourceCode
* @param {string} newContent
- * @param {function(?string)} callback
+ * @param {function()} callback
*/
setFileContent(uiSourceCode, newContent, callback) {
- this._model._setScriptSnippetContent(uiSourceCode.url(), newContent);
- callback('');
+ this.requestOriginalFileContent(uiSourceCode).then(() => {
+ this._model._setScriptSnippetContent(uiSourceCode.url(), newContent);
+ callback();
+ });
}
/**

Powered by Google App Engine
This is Rietveld 408576698