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

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: sync wallpaper Created 7 years, 8 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 /**
20 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly. 24 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly.
21 * @param {string} url The url address where we should fetch resources. 25 * @param {string} url The url address where we should fetch resources.
22 * @param {string} type The response type of XMLHttprequest. 26 * @param {string} type The response type of XMLHttprequest.
23 * @param {function} onSuccess The success callback. It must be called with 27 * @param {function} onSuccess The success callback. It must be called with
24 * current XMLHttprequest object. 28 * current XMLHttprequest object.
25 * @param {function} onFailure The failure callback. 29 * @param {function} onFailure The failure callback.
26 * @param {XMLHttpRequest=} opt_xhr The XMLHttpRequest object. 30 * @param {XMLHttpRequest=} opt_xhr The XMLHttpRequest object.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Constants.WallpaperSourceEnum.Online, function(exists) { 65 Constants.WallpaperSourceEnum.Online, function(exists) {
62 if (exists) { 66 if (exists) {
63 onSuccess(); 67 onSuccess();
64 return; 68 return;
65 } 69 }
66 70
67 self.fetchURL(url, 'arraybuffer', function(xhr) { 71 self.fetchURL(url, 'arraybuffer', function(xhr) {
68 if (xhr.response != null) { 72 if (xhr.response != null) {
69 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 73 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
70 onSuccess); 74 onSuccess);
75 var wallpaperInfo = {
76 url: url,
77 layout: layout,
78 source: Constants.WallpaperSourceEnum.Online
79 };
80 WallpaperUtil.saveToStorage(Constants.AccessWallpaperInfoKey,
81 wallpaperInfo, true);
71 } else { 82 } else {
72 onFailure(); 83 onFailure();
73 } 84 }
74 }, onFailure); 85 }, onFailure);
75 }); 86 });
76 }; 87 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698