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

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

Issue 2537233003: DevTools: [Persistence] sync working copies of UISourceCodes (Closed)
Patch Set: address comments 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/Persistence.js
diff --git a/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js b/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js
index 0a0bd178b62cd8b9dd369500c53d07d7b7e8d650..a67fd69013a738f2c74b04e11dd477ea68d948c7 100644
--- a/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js
+++ b/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js
@@ -49,6 +49,10 @@ Persistence.Persistence = class extends Common.Object {
Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
binding.fileSystem.addEventListener(
Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
+ binding.network.addEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
+ binding.fileSystem.addEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
this._addFilePathBindingPrefixes(binding.fileSystem.url());
@@ -60,9 +64,6 @@ Persistence.Persistence = class extends Common.Object {
* @param {!Persistence.PersistenceBinding} binding
*/
_onBindingRemoved(binding) {
- if (binding.network.isDirty())
- binding.fileSystem.setWorkingCopy(binding.network.workingCopy());
-
binding.network[Persistence.Persistence._binding] = null;
binding.fileSystem[Persistence.Persistence._binding] = null;
@@ -70,6 +71,10 @@ Persistence.Persistence = class extends Common.Object {
Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
binding.fileSystem.removeEventListener(
Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
+ binding.network.removeEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
+ binding.fileSystem.removeEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
this._removeFilePathBindingPrefixes(binding.fileSystem.url());
@@ -80,6 +85,39 @@ Persistence.Persistence = class extends Common.Object {
/**
* @param {!Common.Event} event
*/
+ _onWorkingCopyChanged(event) {
+ var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target);
+ var binding = uiSourceCode[Persistence.Persistence._binding];
+ if (!binding || binding[Persistence.Persistence._muteWorkingCopy])
+ return;
+ var other = binding.network === uiSourceCode ? binding.fileSystem : binding.network;
+ var target = Bindings.NetworkProject.targetForUISourceCode(binding.network);
+ if (target.isNodeJS()) {
+ var newContent = uiSourceCode.workingCopy();
+ other.requestContent().then(() => {
+ var nodeJSContent = this._rewrapNodeJSContent(binding, other, other.workingCopy(), newContent);
+ setWorkingCopy.call(this, () => nodeJSContent);
+ });
+ return;
+ }
+
+ setWorkingCopy.call(this, () => uiSourceCode.workingCopy());
+
+ /**
+ * @param {function():string} workingCopyGetter
+ * @this {Persistence.Persistence}
+ */
+ function setWorkingCopy(workingCopyGetter) {
+ binding[Persistence.Persistence._muteWorkingCopy] = true;
+ other.setWorkingCopyGetter(workingCopyGetter);
+ binding[Persistence.Persistence._muteWorkingCopy] = false;
+ this._contentSyncedForTest();
+ }
+ }
+
+ /**
+ * @param {!Common.Event} event
+ */
_onWorkingCopyCommitted(event) {
var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target);
var binding = uiSourceCode[Persistence.Persistence._binding];
@@ -89,14 +127,24 @@ Persistence.Persistence = class extends Common.Object {
var other = binding.network === uiSourceCode ? binding.fileSystem : binding.network;
var target = Bindings.NetworkProject.targetForUISourceCode(binding.network);
if (target.isNodeJS()) {
- other.requestContent().then(
- currentContent => this._syncNodeJSContent(binding, other, currentContent, newContent));
+ other.requestContent().then(currentContent => {
+ var nodeJSContent = this._rewrapNodeJSContent(binding, other, currentContent, newContent);
+ setContent.call(this, nodeJSContent);
+ });
return;
}
- binding[Persistence.Persistence._muteCommit] = true;
- other.addRevision(newContent);
- binding[Persistence.Persistence._muteCommit] = false;
- this._contentSyncedForTest();
+ setContent.call(this, newContent);
+
+ /**
+ * @param {string} newContent
+ * @this {Persistence.Persistence}
+ */
+ function setContent(newContent) {
+ binding[Persistence.Persistence._muteCommit] = true;
+ other.addRevision(newContent);
+ binding[Persistence.Persistence._muteCommit] = false;
+ this._contentSyncedForTest();
+ }
}
/**
@@ -104,8 +152,9 @@ Persistence.Persistence = class extends Common.Object {
* @param {!Workspace.UISourceCode} uiSourceCode
* @param {string} currentContent
* @param {string} newContent
+ * @return {string}
*/
- _syncNodeJSContent(binding, uiSourceCode, currentContent, newContent) {
+ _rewrapNodeJSContent(binding, uiSourceCode, currentContent, newContent) {
if (uiSourceCode === binding.fileSystem) {
if (newContent.startsWith(Persistence.Persistence._NodePrefix) &&
newContent.endsWith(Persistence.Persistence._NodeSuffix)) {
@@ -121,10 +170,7 @@ Persistence.Persistence = class extends Common.Object {
currentContent.endsWith(Persistence.Persistence._NodeSuffix))
newContent = Persistence.Persistence._NodePrefix + newContent + Persistence.Persistence._NodeSuffix;
}
- binding[Persistence.Persistence._muteCommit] = true;
- uiSourceCode.addRevision(newContent);
- binding[Persistence.Persistence._muteCommit] = false;
- this._contentSyncedForTest();
+ return newContent;
}
_contentSyncedForTest() {
@@ -220,6 +266,7 @@ Persistence.Persistence = class extends Common.Object {
Persistence.Persistence._binding = Symbol('Persistence.Binding');
Persistence.Persistence._muteCommit = Symbol('Persistence.MuteCommit');
+Persistence.Persistence._muteWorkingCopy = Symbol('Persistence.MuteWorkingCopy');
Persistence.Persistence._NodePrefix = '(function (exports, require, module, __filename, __dirname) { ';
Persistence.Persistence._NodeSuffix = '\n});';

Powered by Google App Engine
This is Rietveld 408576698