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

Unified Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 11028121: Convert wallpaper picker to v2 app (Closed) Base URL: http://git.chromium.org/chromium/src.git@AppsV2
Patch Set: add the list of previous minimized window to new window state manager Created 8 years, 1 month 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: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
diff --git a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
index c8696a65fae22dd457c0f7d1137627805defb1e0..2f83969b1cccc244fb259dea04ec0c5c3aa5b4c2 100644
--- a/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
+++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js
@@ -20,8 +20,8 @@ function WallpaperManager(dialogDom) {
this.butterBar_ = new ButterBar(this.dialogDom_);
this.customWallpaperData_ = null;
this.currentWallpaper_ = null;
+ this.wallpaperRequest_ = null;
this.fetchManifest_();
- this.initDom_();
}
// Anonymous 'namespace'.
@@ -81,31 +81,56 @@ function WallpaperManager(dialogDom) {
* Requests wallpaper manifest file from server.
*/
WallpaperManager.prototype.fetchManifest_ = function() {
- var xhr = new XMLHttpRequest();
var locale = navigator.language;
var urls = [
ManifestBaseURL + locale + '.json',
// Fallback url. Use 'en' locale by default.
ManifestBaseURL + 'en.json'];
+ var self = this;
+
+ var asyncFetchManifestFromUrls = function(urls, func, callback) {
flackr 2012/11/13 16:18:30 To make this a bit easier to read, perhaps you cou
bshe 2012/11/13 19:33:22 Done.
+ var index = 0;
+ var loop = {
+ next: function() {
+ if (index < urls.length) {
+ func(loop, urls[index]);
+ index++;
+ } else {
+ callback();
+ }
+ },
- for (var i = 0; i < urls.length; i++) {
- xhr.open('GET', urls[i], false);
+ done: function() {
+ callback();
flackr 2012/11/13 16:18:30 It looks like if there are no manifests we will no
bshe 2012/11/13 19:33:22 No. That was a mistake. Fixed it in new patch. On
+ }
+ };
+ loop.next();
+ }
flackr 2012/11/13 16:18:30 Need semicolon at end of line.
bshe 2012/11/13 19:33:22 Done.
+
+ var fetchManifestAsync = function(loop, url) {
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url, true);
try {
xhr.send(null);
- // TODO(bshe): We should save the downloaded manifest to local disk.
- // Other components may want to use it (i.e. screen saver).
- if (xhr.status === 200) {
- this.parseManifest_(xhr.responseText);
- return;
- }
+ xhr.addEventListener('load', function(e) {
+ // TODO(bshe): We should save the downloaded manifest to local disk.
+ // Other components may want to use it (e.g. screen saver).
+ if (xhr.status === 200) {
+ self.parseManifest_(xhr.responseText);
+ self.initDom_();
+ loop.done();
flackr 2012/11/13 16:18:30 As the code is currently, you'll call initDom twic
bshe 2012/11/13 19:33:22 Should be fixed in the new patch. On 2012/11/13 1
+ } else {
+ loop.next();
+ }
+ });
} catch (e) {
- this.manifest_ = {};
- this.butterBar_.showError_(str('connectionFailed'));
- return;
+ self.manifest_ = {};
+ self.butterBar_.showError_(str('connectionFailed'));
+ loop.done();
}
}
flackr 2012/11/13 16:18:30 Semicolon at end of line.
bshe 2012/11/13 19:33:22 Done.
- this.manifest_ = {};
- this.butterBar_.showError_(str('connectionFailed'));
+
+ asyncFetchManifestFromUrls(urls, fetchManifestAsync, this.initDom_);
// TODO(bshe): Fall back to saved manifest if there is a problem fetching
// manifest from server.

Powered by Google App Engine
This is Rietveld 408576698