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

Unified Diff: third_party/WebKit/Source/devtools/front_end/persistence/FileSystemWorkspaceBinding.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/persistence/FileSystemWorkspaceBinding.js
diff --git a/third_party/WebKit/Source/devtools/front_end/persistence/FileSystemWorkspaceBinding.js b/third_party/WebKit/Source/devtools/front_end/persistence/FileSystemWorkspaceBinding.js
index 8091642bebe380935fc48ef7a856273015a9bb6b..607200b689b33c966bbf3b9fb283ccd1d06c3e2e 100644
--- a/third_party/WebKit/Source/devtools/front_end/persistence/FileSystemWorkspaceBinding.js
+++ b/third_party/WebKit/Source/devtools/front_end/persistence/FileSystemWorkspaceBinding.js
@@ -196,6 +196,9 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
super(workspace, id, Workspace.projectTypes.FileSystem, displayName);
+ /** @type {!WeakMap<!Workspace.UISourceCode, !Promise<?string>>} */
+ this._originalContent = new WeakMap();
+
this._fileSystem = isolatedFileSystem;
this._fileSystemBaseURL = this._fileSystem.path() + '/';
this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
@@ -286,6 +289,21 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
/**
* @override
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ * @return {!Promise<?string>}
+ */
+ requestOriginalFileContent(uiSourceCode) {
+ if (this._originalContent.has(uiSourceCode))
+ return this._originalContent.get(uiSourceCode);
+ var fulfill;
+ var promise = new Promise(x => fulfill = x);
+ this.requestFileContent(uiSourceCode, fulfill);
+ this._originalContent.set(uiSourceCode, promise);
+ return promise;
+ }
+
+ /**
+ * @override
* @return {boolean}
*/
canSetFileContent() {
@@ -296,11 +314,12 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
* @override
* @param {!Workspace.UISourceCode} uiSourceCode
* @param {string} newContent
- * @param {function(?string)} callback
einbinder 2016/12/20 03:10:34 The parameter in the callback was never used.
+ * @param {function()} callback
*/
setFileContent(uiSourceCode, newContent, callback) {
var filePath = this._filePathForUISourceCode(uiSourceCode);
- this._fileSystem.setFileContent(filePath, newContent, callback.bind(this, ''));
einbinder 2016/12/20 03:10:34 Bind the callback to this?! What is going on.
+ this.requestOriginalFileContent(uiSourceCode)
+ .then(() => this._fileSystem.setFileContent(filePath, newContent, callback));
}
/**

Powered by Google App Engine
This is Rietveld 408576698