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

Unified Diff: Source/devtools/front_end/sdk/StylesSourceMapping.js

Issue 319143002: DevTools: introduce WebInspector.Throttler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: jsdoc for Throttler.FinishCallback Created 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/sdk/StylesSourceMapping.js
diff --git a/Source/devtools/front_end/sdk/StylesSourceMapping.js b/Source/devtools/front_end/sdk/StylesSourceMapping.js
index 8acb4d57434b28a20f5502b0cd2d7ebc13565a33..25ec07f577c4c5082da3c15bd2bc78c213d6bc30 100644
--- a/Source/devtools/front_end/sdk/StylesSourceMapping.js
+++ b/Source/devtools/front_end/sdk/StylesSourceMapping.js
@@ -323,6 +323,7 @@ WebInspector.StyleFile = function(uiSourceCode, mapping)
this._mapping = mapping;
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
+ this._commitThrottler = new WebInspector.Throttler(WebInspector.StyleFile.updateTimeout);
vsevik 2014/06/09 12:32:58 We have (at least used to have) a test that overri
lushnikov 2014/06/09 13:07:26 All tests successfully pass.
}
WebInspector.StyleFile.updateTimeout = 200;
@@ -345,7 +346,7 @@ WebInspector.StyleFile.prototype = {
return;
this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Major;
vsevik 2014/06/09 12:32:58 I believe it should be enough to set this._isMajor
lushnikov 2014/06/09 13:07:26 Indeed. Fixed this.
- this._maybeProcessChange();
+ this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), true);
},
/**
@@ -355,60 +356,32 @@ WebInspector.StyleFile.prototype = {
{
if (this._isAddingRevision)
return;
-
if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType.Major)
return;
- this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Minor;
- this._maybeProcessChange();
- },
-
- _maybeProcessChange: function()
- {
- if (this._isSettingContent)
- return;
- if (!this._pendingChangeType)
- return;
- if (this._pendingChangeType === WebInspector.StyleFile.PendingChangeType.Major) {
- this._clearIncrementalUpdateTimer();
- delete this._pendingChangeType;
- this._commitIncrementalEdit(true);
- return;
- }
-
- if (this._incrementalUpdateTimer)
- return;
- this._incrementalUpdateTimer = setTimeout(this._commitIncrementalEdit.bind(this, false), WebInspector.StyleFile.updateTimeout);
+ this._pendingChangeType = WebInspector.StyleFile.PendingChangeType.Minor;
+ this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), false);
},
/**
- * @param {boolean} majorChange
+ * @param {!WebInspector.Throttler.FinishCallback} finishCallback
*/
- _commitIncrementalEdit: function(majorChange)
+ _commitIncrementalEdit: function(finishCallback)
{
- this._clearIncrementalUpdateTimer();
+ var majorChange = this._pendingChangeType === WebInspector.StyleFile.PendingChangeType.Major;
dgozman 2014/06/09 07:01:51 I still think, that binding such values as paramet
vsevik 2014/06/09 12:32:58 We can not bind pending change type.
lushnikov 2014/06/09 13:07:26 It's tempting, but we can't.
+ this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), majorChange, this._styleContentSet.bind(this, finishCallback));
delete this._pendingChangeType;
- this._isSettingContent = true;
- this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), majorChange, this._styleContentSet.bind(this));
},
/**
+ * @param {!WebInspector.Throttler.FinishCallback} finishCallback
* @param {?string} error
*/
- _styleContentSet: function(error)
+ _styleContentSet: function(finishCallback, error)
{
if (error)
this._mapping._cssModel.target().consoleModel.showErrorMessage(error);
- delete this._isSettingContent;
- this._maybeProcessChange();
- },
-
- _clearIncrementalUpdateTimer: function()
- {
- if (!this._incrementalUpdateTimer)
- return;
- clearTimeout(this._incrementalUpdateTimer);
- delete this._incrementalUpdateTimer;
+ finishCallback();
},
/**

Powered by Google App Engine
This is Rietveld 408576698