background: refactor file loading

This commit moves the code around a bit such that the
caller gets allocated up front and then a file load is either
found or created to attach the caller to.

Functionally, the code is the same, it's just now factored in a way
that will make it easier to fix a bug with cancellation later.

https://bugzilla.gnome.org/show_bug.cgi?id=722149
This commit is contained in:
Ray Strode 2014-02-26 15:13:21 -05:00 committed by Jasper St. Pierre
parent ec6facb9e7
commit e917b7ce0f

View File

@ -132,6 +132,10 @@ const BackgroundCache = new Lang.Class({
this._removeContent(this._images, content); this._removeContent(this._images, content);
}, },
_attachCallerToFileLoad: function(caller, fileLoad) {
fileLoad.callers.push(caller);
},
_loadImageContent: function(params) { _loadImageContent: function(params) {
params = Params.parse(params, { monitorIndex: 0, params = Params.parse(params, { monitorIndex: 0,
style: null, style: null,
@ -140,21 +144,24 @@ const BackgroundCache = new Lang.Class({
cancellable: null, cancellable: null,
onFinished: null }); onFinished: null });
for (let i = 0; i < this._pendingFileLoads.length; i++) { let caller = { monitorIndex: params.monitorIndex,
if (this._pendingFileLoads[i].filename == params.filename &&
this._pendingFileLoads[i].style == params.style) {
this._pendingFileLoads[i].callers.push({ monitorIndex: params.monitorIndex,
effects: params.effects, effects: params.effects,
onFinished: params.onFinished }); onFinished: params.onFinished };
for (let i = 0; i < this._pendingFileLoads.length; i++) {
let fileLoad = this._pendingFileLoads[i];
if (fileLoad.filename == params.filename &&
fileLoad.style == params.style) {
this._attachCallerToFileLoad(caller, fileLoad);
return; return;
} }
} }
this._pendingFileLoads.push({ filename: params.filename, let fileLoad = { filename: params.filename,
style: params.style, style: params.style,
callers: [{ monitorIndex: params.monitorIndex, callers: [] };
effects: params.effects, this._attachCallerToFileLoad(caller, fileLoad);
onFinished: params.onFinished }] });
let content = new Meta.Background({ meta_screen: global.screen }); let content = new Meta.Background({ meta_screen: global.screen });