| OLD | NEW |
| 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 Loading... |
| 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 }; |
| OLD | NEW |