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

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

Issue 1212263002: DevTools: [CSS] migrate setStyleSheetText to promises (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: log error from first stylesheet Created 5 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/bindings/StylesSourceMapping.js
diff --git a/Source/devtools/front_end/bindings/StylesSourceMapping.js b/Source/devtools/front_end/bindings/StylesSourceMapping.js
index 4d24f1f002469c611b709e3ffd1fa8573cb83e0d..f9b3e5eea6e365dd17dcf2a404ae8cb2c854319b 100644
--- a/Source/devtools/front_end/bindings/StylesSourceMapping.js
+++ b/Source/devtools/front_end/bindings/StylesSourceMapping.js
@@ -247,32 +247,33 @@ WebInspector.StylesSourceMapping.prototype = {
* @param {!WebInspector.UISourceCode} uiSourceCode
* @param {string} content
* @param {boolean} majorChange
- * @param {function(?string)} userCallback
+ * @return {!Promise<?string>}
*/
- _setStyleContent: function(uiSourceCode, content, majorChange, userCallback)
+ _setStyleContent: function(uiSourceCode, content, majorChange)
{
var networkURL = this._networkMapping.networkURL(uiSourceCode);
var styleSheetIds = this._cssModel.styleSheetIdsForURL(networkURL);
- if (!styleSheetIds.length) {
- userCallback("No stylesheet found: " + networkURL);
- return;
- }
+ if (!styleSheetIds.length)
+ return Promise.resolve(/** @type {?string} */("No stylesheet found: " + networkURL));
this._isSettingContent = true;
/**
- * @param {?Protocol.Error} error
+ * @param {?string} error
* @this {WebInspector.StylesSourceMapping}
+ * @return {?string}
*/
function callback(error)
{
- userCallback(error);
delete this._isSettingContent;
+ return error || null;
}
-
+ var promises = [];
for (var i = 0; i < styleSheetIds.length; ++i)
- this._cssModel.setStyleSheetText(styleSheetIds[i], content, majorChange, i === styleSheetIds.length - 1 ? callback.bind(this) : null);
+ promises.push(this._cssModel.setStyleSheetText(styleSheetIds[i], content, majorChange));
+
+ return Promise.all(promises).spread(callback.bind(this));
},
/**
@@ -382,19 +383,20 @@ WebInspector.StyleFile.prototype = {
*/
_commitIncrementalEdit: function(finishCallback)
{
- this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), this._isMajorChangePending, this._styleContentSet.bind(this, finishCallback));
+ this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), this._isMajorChangePending)
+ .then(this._styleContentSet.bind(this))
+ .then(finishCallback)
+ .catch(/** @type {function()} */(finishCallback));
this._isMajorChangePending = false;
},
/**
- * @param {!WebInspector.Throttler.FinishCallback} finishCallback
* @param {?string} error
*/
- _styleContentSet: function(finishCallback, error)
+ _styleContentSet: function(error)
{
if (error)
WebInspector.console.error(error);
- finishCallback();
},
/**
« no previous file with comments | « LayoutTests/inspector/elements/styles-4/styles-new-API.html ('k') | Source/devtools/front_end/sdk/CSSStyleModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698