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

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 11348215: Make wallpaper picker manifest and thumbnails available when offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment nits Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * WallpaperManager constructor. 6 * WallpaperManager constructor.
7 * 7 *
8 * WallpaperManager objects encapsulate the functionality of the wallpaper 8 * WallpaperManager objects encapsulate the functionality of the wallpaper
9 * manager extension. 9 * manager extension.
10 * 10 *
11 * @constructor 11 * @constructor
12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical 12 * @param {HTMLElement} dialogDom The DOM node containing the prototypical
13 * extension UI. 13 * extension UI.
14 */ 14 */
15 15
16 function WallpaperManager(dialogDom) { 16 function WallpaperManager(dialogDom) {
17 this.dialogDom_ = dialogDom; 17 this.dialogDom_ = dialogDom;
18 this.storage_ = chrome.storage.local;
18 this.document_ = dialogDom.ownerDocument; 19 this.document_ = dialogDom.ownerDocument;
19 this.selectedCategory = null; 20 this.selectedCategory = null;
20 this.butterBar_ = new ButterBar(this.dialogDom_); 21 this.butterBar_ = new ButterBar(this.dialogDom_);
21 this.customWallpaperData_ = null; 22 this.customWallpaperData_ = null;
22 this.currentWallpaper_ = null; 23 this.currentWallpaper_ = null;
23 this.wallpaperRequest_ = null; 24 this.wallpaperRequest_ = null;
24 this.fetchManifest_(); 25 this.fetchManifest_();
25 } 26 }
26 27
27 // Anonymous 'namespace'. 28 // Anonymous 'namespace'.
28 // TODO(bshe): Get rid of anonymous namespace. 29 // TODO(bshe): Get rid of anonymous namespace.
29 (function() { 30 (function() {
30 31
31 /** 32 /**
32 * Base URL of the manifest file. 33 * Base URL of the manifest file.
33 */ 34 */
34 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' + 35 /** @const */ var ManifestBaseURL = 'https://commondatastorage.googleapis.' +
35 'com/chromeos-wallpaper-public/manifest_'; 36 'com/chromeos-wallpaper-public/manifest_';
36 37
37 /** 38 /**
38 * Suffix to append to baseURL if requesting high resoultion wallpaper. 39 * Suffix to append to baseURL if requesting high resoultion wallpaper.
39 */ 40 */
40 /** @const */ var HighResolutionSuffix = '_high_resolution.jpg'; 41 /** @const */ var HighResolutionSuffix = '_high_resolution.jpg';
41 42
42 /** 43 /**
44 * Key to access wallpaper manifest in chrome.local.storage.
45 */
46 /** @const */ var AccessManifestKey = 'wallpaper-picker-manifest-key';
47
48 /**
43 * Returns a translated string. 49 * Returns a translated string.
44 * 50 *
45 * Wrapper function to make dealing with translated strings more concise. 51 * Wrapper function to make dealing with translated strings more concise.
46 * Equivilant to localStrings.getString(id). 52 * Equivilant to localStrings.getString(id).
47 * 53 *
48 * @param {string} id The id of the string to return. 54 * @param {string} id The id of the string to return.
49 * @return {string} The translated string. 55 * @return {string} The translated string.
50 */ 56 */
51 function str(id) { 57 function str(id) {
52 return loadTimeData.getString(id); 58 return loadTimeData.getString(id);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 }); 120 });
115 xhr.open('GET', url, true); 121 xhr.open('GET', url, true);
116 xhr.send(null); 122 xhr.send(null);
117 } catch (e) { 123 } catch (e) {
118 loop.failure(); 124 loop.failure();
119 } 125 }
120 }; 126 };
121 127
122 asyncFetchManifestFromUrls(urls, fetchManifestAsync, 128 asyncFetchManifestFromUrls(urls, fetchManifestAsync,
123 this.onLoadManifestSuccess_.bind(this), 129 this.onLoadManifestSuccess_.bind(this),
124 this.onLoadManifestFailed_.bind(this)); 130 this.onLoadManifestFailed_.bind(this));
flackr 2012/11/27 22:04:36 If we're offline won't it take a while to fail to
bshe 2012/11/28 18:54:26 Good point. I added navigator.onLine to detect the
flackr 2012/12/03 20:03:46 I think in the long run loading the offline manife
bshe 2012/12/03 22:18:01 Make sense. Added a TODO. On 2012/12/03 20:03:46,
125 }; 131 };
126 132
127 /** 133 /**
128 * Sets manifest loaded from server. Called after manifest is successfully 134 * Sets manifest loaded from server. Called after manifest is successfully
129 * loaded. 135 * loaded.
130 * @param {object} manifest The parsed manifest file. 136 * @param {object} manifest The parsed manifest file.
131 */ 137 */
132 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) { 138 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) {
133 this.manifest_ = manifest; 139 this.manifest_ = manifest;
140 var items = {};
141 items[AccessManifestKey] = manifest;
142 this.storage_.set(items, function() {});
134 this.initDom_(); 143 this.initDom_();
135 }; 144 };
136 145
137 // Sets manifest to an empty object and shows connection error. Called after 146 // Sets manifest to previously saved object if any and shows connection error.
138 // manifest failed to load. 147 // Called after manifest failed to load.
139 WallpaperManager.prototype.onLoadManifestFailed_ = function() { 148 WallpaperManager.prototype.onLoadManifestFailed_ = function() {
140 // TODO(bshe): Fall back to saved manifest if there is a problem fetching 149 var self = this;
141 // manifest from server. 150 this.storage_.get(AccessManifestKey, function(items) {
142 this.manifest_ = {}; 151 self.manifest_ = items[AccessManifestKey] ? items[AccessManifestKey] : {};
143 this.butterBar_.showError_(str('connectionFailed')); 152 self.butterBar_.showError_(str('connectionFailed'));
144 this.initDom_(); 153 self.initDom_();
154 });
145 }; 155 };
146 156
147 /** 157 /**
148 * One-time initialization of various DOM nodes. 158 * One-time initialization of various DOM nodes.
149 */ 159 */
150 WallpaperManager.prototype.initDom_ = function() { 160 WallpaperManager.prototype.initDom_ = function() {
151 i18nTemplate.process(this.document_, loadTimeData); 161 i18nTemplate.process(this.document_, loadTimeData);
152 this.initCategoriesList_(); 162 this.initCategoriesList_();
153 this.initThumbnailsGrid_(); 163 this.initThumbnailsGrid_();
154 164
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 selectedItem = wallpaperInfo; 445 selectedItem = wallpaperInfo;
436 } 446 }
437 } 447 }
438 } 448 }
439 this.wallpaperGrid_.dataModel = wallpapersDataModel; 449 this.wallpaperGrid_.dataModel = wallpapersDataModel;
440 this.wallpaperGrid_.selectedItem = selectedItem; 450 this.wallpaperGrid_.selectedItem = selectedItem;
441 } 451 }
442 }; 452 };
443 453
444 })(); 454 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698