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

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

Issue 14416017: Sync online wallpaper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 var WallpaperUtil = {}; 5 var WallpaperUtil = {};
6 6
7 /** 7 /**
8 * Saves value to local storage that associates with key. 8 * Saves value to local storage that associates with key.
9 * @param {string} key The key that associates with value. 9 * @param {string} key The key that associates with value.
10 * @param {string} value The value to save to local storage. 10 * @param {string} value The value to save to local storage.
11 * @param {boolen} sync True if the value is saved to sync storage.
11 * @param {function=} opt_callback The callback on success, or on failure. 12 * @param {function=} opt_callback The callback on success, or on failure.
12 */ 13 */
13 WallpaperUtil.saveToLocalStorage = function(key, value, opt_callback) { 14 WallpaperUtil.saveToStorage = function(key, value, sync, opt_callback) {
14 var items = {}; 15 var items = {};
15 items[key] = value; 16 items[key] = value;
16 Constants.WallpaperLocalStorage.set(items, opt_callback); 17 if (sync)
18 Constants.WallpaperSyncStorage.set(items, opt_callback);
19 else
20 Constants.WallpaperLocalStorage.set(items, opt_callback);
17 }; 21 };
18 22
19 /** 23 /**
24 * Saves user's wallpaper infomation to local and sync storage. Note that local
25 * value should be saved first.
26 * @param {string} url The url address of wallpaper. For custom wallpaper, it is
27 * the file name.
28 * @param {string} layout The wallpaper layout.
29 * @param {string} source The wallpaper source.
30 */
31 WallpaperUtil.saveWallpaperInfo = function(url, layout, source) {
32 var wallpaperInfo = {
33 url: url,
34 layout: layout,
35 source: source
36 };
37 WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
38 wallpaperInfo, false, function() {
39 WallpaperUtil.saveToStorage(Constants.AccessSyncWallpaperInfoKey,
40 wallpaperInfo, true);
41 });
42 };
43
44 /**
20 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly. 45 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly.
21 * @param {string} url The url address where we should fetch resources. 46 * @param {string} url The url address where we should fetch resources.
22 * @param {string} type The response type of XMLHttprequest. 47 * @param {string} type The response type of XMLHttprequest.
23 * @param {function} onSuccess The success callback. It must be called with 48 * @param {function} onSuccess The success callback. It must be called with
24 * current XMLHttprequest object. 49 * current XMLHttprequest object.
25 * @param {function} onFailure The failure callback. 50 * @param {function} onFailure The failure callback.
26 * @param {XMLHttpRequest=} opt_xhr The XMLHttpRequest object. 51 * @param {XMLHttpRequest=} opt_xhr The XMLHttpRequest object.
27 */ 52 */
28 WallpaperUtil.fetchURL = function(url, type, onSuccess, onFailure, opt_xhr) { 53 WallpaperUtil.fetchURL = function(url, type, onSuccess, onFailure, opt_xhr) {
29 var xhr; 54 var xhr;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Constants.WallpaperSourceEnum.Online, function(exists) { 86 Constants.WallpaperSourceEnum.Online, function(exists) {
62 if (exists) { 87 if (exists) {
63 onSuccess(); 88 onSuccess();
64 return; 89 return;
65 } 90 }
66 91
67 self.fetchURL(url, 'arraybuffer', function(xhr) { 92 self.fetchURL(url, 'arraybuffer', function(xhr) {
68 if (xhr.response != null) { 93 if (xhr.response != null) {
69 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 94 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
70 onSuccess); 95 onSuccess);
96 self.saveWallpaperInfo(url, layout,
97 Constants.WallpaperSourceEnum.Online);
71 } else { 98 } else {
72 onFailure(); 99 onFailure();
73 } 100 }
74 }, onFailure); 101 }, onFailure);
75 }); 102 });
76 }; 103 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698