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

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

Issue 676403002: Sync wallpaper based on sync themes setting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
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 strings: null, // Object that contains all the flags 6 strings: null, // Object that contains all the flags
7 syncFs: null, // syncFileSystem handler 7 syncFs: null, // syncFileSystem handler
8 webkitFs: null // webkitFileSystem handler 8 webkitFs: null // webkitFileSystem handler
9 }; 9 };
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 /** 47 /**
48 * Loads a wallpaper from sync file system and saves it and its thumbnail to 48 * Loads a wallpaper from sync file system and saves it and its thumbnail to
49 * local file system. 49 * local file system.
50 * @param {string} wallpaperFileEntry File name of wallpaper image. 50 * @param {string} wallpaperFileEntry File name of wallpaper image.
51 */ 51 */
52 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS = function(wallpaperFileEntry) { 52 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS = function(wallpaperFileEntry) {
53 var filenName = wallpaperFileEntry.name; 53 var filenName = wallpaperFileEntry.name;
54 var storeDir = Constants.WallpaperDirNameEnum.ORIGINAL; 54 var storeDir = Constants.WallpaperDirNameEnum.ORIGINAL;
55 if (filenName.indexOf(Constants.CustomWallpaperThumbnailSuffix) != -1) 55 if (filenName.indexOf(Constants.CustomWallpaperThumbnailSuffix) != -1)
56 storeDir = Constants.WallpaperDirNameEnum.THUMBNAIL; 56 storeDir = Constants.WallpaperDirNameEnum.THUMBNAIL;
57 filenName = filenName.replace(Constants.CustomWallpaperThumbnailSuffix, '');
58 wallpaperFileEntry.file(function(file) { 57 wallpaperFileEntry.file(function(file) {
59 var reader = new FileReader(); 58 var reader = new FileReader();
60 reader.onloadend = function() { 59 reader.onloadend = function() {
61 WallpaperUtil.storeWallpaperToLocalFS(filenName, reader.result, storeDir); 60 WallpaperUtil.storeWallpaperToLocalFS(filenName, reader.result, storeDir);
62 }; 61 };
63 reader.readAsArrayBuffer(file); 62 reader.readAsArrayBuffer(file);
64 }, WallpaperUtil.onFileSystemError); 63 }, WallpaperUtil.onFileSystemError);
65 }; 64 };
66 65
67 /** 66 /**
(...skipping 14 matching lines...) Expand all
82 {create: false}, 81 {create: false},
83 function(fe) { 82 function(fe) {
84 fe.remove(function() {}, null); 83 fe.remove(function() {}, null);
85 }, 84 },
86 WallpaperUtil.onFileSystemError); 85 WallpaperUtil.onFileSystemError);
87 }; 86 };
88 WallpaperUtil.requestSyncFS(success); 87 WallpaperUtil.requestSyncFS(success);
89 }; 88 };
90 89
91 /** 90 /**
92 * Run experimental features. 91 * Executes callback if experimental flag is set to true.
93 * @param {function} callback The callback will be executed if 'isExperimental' 92 * @param {function} callback The callback will be executed if 'isExperimental'
94 * flag is set to true. 93 * flag is set to true.
95 */ 94 */
96 WallpaperUtil.enabledExperimentalFeatureCallback = function(callback) { 95 WallpaperUtil.enabledExperimentalFeatureCallback = function(callback) {
97 if (WallpaperUtil.strings) { 96 if (WallpaperUtil.strings) {
98 if (WallpaperUtil.strings.isExperimental) 97 if (WallpaperUtil.strings.isExperimental)
99 callback(); 98 callback();
100 } else { 99 } else {
101 chrome.wallpaperPrivate.getStrings(function(strings) { 100 chrome.wallpaperPrivate.getStrings(function(strings) {
102 WallpaperUtil.strings = strings; 101 WallpaperUtil.strings = strings;
103 if (WallpaperUtil.strings.isExperimental) 102 if (WallpaperUtil.strings.isExperimental)
104 callback(); 103 callback();
105 }); 104 });
106 } 105 }
107 }; 106 };
108 107
109 /** 108 /**
109 * Executes callback if sync theme is enabled.
110 * @param {function} callback The callback will be executed if sync themes is
111 * enabled.
112 */
113 WallpaperUtil.enabledSyncThemesCallback = function(callback) {
114 chrome.wallpaperPrivate.getSyncSetting(function(setting) {
115 if (setting.syncThemes)
116 callback();
117 });
118 };
119
120 /**
110 * Request a syncFileSystem handle and run callback on it. 121 * Request a syncFileSystem handle and run callback on it.
111 * @param {function} callback The callback to execute after syncFileSystem 122 * @param {function} callback The callback to execute after syncFileSystem
112 * handler is available. 123 * handler is available.
113 */ 124 */
114 WallpaperUtil.requestSyncFS = function(callback) { 125 WallpaperUtil.requestSyncFS = function(callback) {
115 if (WallpaperUtil.syncFs) { 126 WallpaperUtil.enabledSyncThemesCallback(function() {
116 callback(WallpaperUtil.syncFs); 127 if (WallpaperUtil.syncFs) {
117 } else {
118 chrome.syncFileSystem.requestFileSystem(function(fs) {
119 WallpaperUtil.syncFs = fs;
120 callback(WallpaperUtil.syncFs); 128 callback(WallpaperUtil.syncFs);
121 }); 129 } else {
122 } 130 chrome.syncFileSystem.requestFileSystem(function(fs) {
131 WallpaperUtil.syncFs = fs;
132 callback(WallpaperUtil.syncFs);
133 });
134 }
135 });
123 }; 136 };
124 137
125 /** 138 /**
126 * Request a Local Fs handle and run callback on it. 139 * Request a Local Fs handle and run callback on it.
127 * @param {function} callback The callback to execute after Local handler is 140 * @param {function} callback The callback to execute after Local handler is
128 * available. 141 * available.
129 */ 142 */
130 WallpaperUtil.requestLocalFS = function(callback) { 143 WallpaperUtil.requestLocalFS = function(callback) {
131 if (WallpaperUtil.webkitFs) { 144 if (WallpaperUtil.webkitFs) {
132 callback(WallpaperUtil.webkitFs); 145 callback(WallpaperUtil.webkitFs);
(...skipping 16 matching lines...) Expand all
149 }; 162 };
150 163
151 /** 164 /**
152 * Write jpeg/png file data into file entry. 165 * Write jpeg/png file data into file entry.
153 * @param {FileEntry} fileEntry The file entry that going to be writen. 166 * @param {FileEntry} fileEntry The file entry that going to be writen.
154 * @param {ArrayBuffer} wallpaperData Data for image file. 167 * @param {ArrayBuffer} wallpaperData Data for image file.
155 * @param {function=} writeCallback The callback that will be executed after 168 * @param {function=} writeCallback The callback that will be executed after
156 * writing data. 169 * writing data.
157 */ 170 */
158 WallpaperUtil.writeFile = function(fileEntry, wallpaperData, writeCallback) { 171 WallpaperUtil.writeFile = function(fileEntry, wallpaperData, writeCallback) {
159 var uint8arr = new Uint8Array(wallpaperData);
160 fileEntry.createWriter(function(fileWriter) { 172 fileEntry.createWriter(function(fileWriter) {
161 var blob = new Blob([new Int8Array(wallpaperData)]); 173 var blob = new Blob([new Int8Array(wallpaperData)]);
162 fileWriter.write(blob); 174 fileWriter.write(blob);
163 if (writeCallback) 175 if (writeCallback)
164 writeCallback(); 176 writeCallback();
165 }, WallpaperUtil.onFileSystemError); 177 }, WallpaperUtil.onFileSystemError);
166 }; 178 };
167 179
168 /** 180 /**
169 * Write jpeg/png file data into syncFileSystem. 181 * Write jpeg/png file data into syncFileSystem.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 * Saves value to local storage that associates with key. 281 * Saves value to local storage that associates with key.
270 * @param {string} key The key that associates with value. 282 * @param {string} key The key that associates with value.
271 * @param {string} value The value to save to local storage. 283 * @param {string} value The value to save to local storage.
272 * @param {boolen} sync True if the value is saved to sync storage. 284 * @param {boolen} sync True if the value is saved to sync storage.
273 * @param {function=} opt_callback The callback on success, or on failure. 285 * @param {function=} opt_callback The callback on success, or on failure.
274 */ 286 */
275 WallpaperUtil.saveToStorage = function(key, value, sync, opt_callback) { 287 WallpaperUtil.saveToStorage = function(key, value, sync, opt_callback) {
276 var items = {}; 288 var items = {};
277 items[key] = value; 289 items[key] = value;
278 if (sync) 290 if (sync)
279 Constants.WallpaperSyncStorage.set(items, opt_callback); 291 WallpaperUtil.enabledSyncThemesCallback(function() {
292 Constants.WallpaperSyncStorage.set(items, opt_callback);
293 });
280 else 294 else
281 Constants.WallpaperLocalStorage.set(items, opt_callback); 295 Constants.WallpaperLocalStorage.set(items, opt_callback);
282 }; 296 };
283 297
284 /** 298 /**
285 * Saves user's wallpaper infomation to local and sync storage. Note that local 299 * Saves user's wallpaper infomation to local and sync storage. Note that local
286 * value should be saved first. 300 * value should be saved first.
287 * @param {string} url The url address of wallpaper. For custom wallpaper, it is 301 * @param {string} url The url address of wallpaper. For custom wallpaper, it is
288 * the file name. 302 * the file name.
289 * @param {string} layout The wallpaper layout. 303 * @param {string} layout The wallpaper layout.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 * Runs chrome.test.sendMessage in test environment. Does nothing if running 384 * Runs chrome.test.sendMessage in test environment. Does nothing if running
371 * in production environment. 385 * in production environment.
372 * 386 *
373 * @param {string} message Test message to send. 387 * @param {string} message Test message to send.
374 */ 388 */
375 WallpaperUtil.testSendMessage = function(message) { 389 WallpaperUtil.testSendMessage = function(message) {
376 var test = chrome.test || window.top.chrome.test; 390 var test = chrome.test || window.top.chrome.test;
377 if (test) 391 if (test)
378 test.sendMessage(message); 392 test.sendMessage(message);
379 }; 393 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698