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

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

Issue 1631923004: Sync 3rd party wallpaper app name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 reader.result, 252 reader.result,
253 wallpaperLayout, 253 wallpaperLayout,
254 true, 254 true,
255 wallpaperFilename, 255 wallpaperFilename,
256 function(thumbnailData) { 256 function(thumbnailData) {
257 // TODO(ranj): Ignore 'canceledWallpaper' error. 257 // TODO(ranj): Ignore 'canceledWallpaper' error.
258 if (chrome.runtime.lastError) { 258 if (chrome.runtime.lastError) {
259 console.error(chrome.runtime.lastError.message); 259 console.error(chrome.runtime.lastError.message);
260 return; 260 return;
261 } 261 }
262 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 262 // If the current synced wallpaper is a third party wallpaper,
263 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL); 263 // we also sync the third party app's name. Otherwise, we save
264 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 264 // the custom wallpaper to the local filesystem.
265 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL); 265 if (wallpaperFilename.indexOf(
tbarzic 2016/01/28 20:10:48 do you really need to branch here? Can't you just
xdai1 2016/02/02 01:19:42 Use value from sync fs instead.
266 Constants.ThirdPartyWallpaperPrefix) != -1) {
267 Constants.WallpaperSyncStorage.get(
268 Constants.AccessSyncThirdPartyAppName, function(items) {
269 if (items.hasOwnProperty(
270 Constants.AccessSyncThirdPartyAppName)) {
271 WallpaperUtil.saveToLocalStorage(
272 Constants.AccessLocalThirdPartyAppName,
273 items[Constants.AccessSyncThirdPartyAppName]);
274 }
275 });
276 } else {
277 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
tbarzic 2016/01/28 20:10:48 the wallpapers should still be stored to local fs
xdai1 2016/02/02 01:19:42 Only custom wallpapers need to be stored in the lo
278 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL);
279 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
280 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL);
281 WallpaperUtil.clearThirdPartyAppName();
282 }
266 if (onSuccess) 283 if (onSuccess)
267 onSuccess(); 284 onSuccess();
268 }); 285 });
269 }; 286 };
270 reader.readAsArrayBuffer(file); 287 reader.readAsArrayBuffer(file);
271 }, WallpaperUtil.onFileSystemError); 288 }, WallpaperUtil.onFileSystemError);
272 }, function(e) {} // fail to read file, expected due to download delay 289 }, function(e) {} // fail to read file, expected due to download delay
273 ); 290 );
274 }; 291 };
275 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback); 292 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback);
276 }; 293 };
277 294
278 /** 295 /**
296 * Save the third party wallpaper app name to local & sync filesystem.
297 * @param {string} appname The third party wallpaper extension or app's name.
298 */
299 WallpaperUtil.saveThirdPartyAppName = function(appname) {
300 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalThirdPartyAppName,
301 appname, function() {
302 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncThirdPartyAppName,
303 appname);
304 });
305 };
306
307 /**
308 * Clear the third party wallpaper app name from local & sync filesystem.
309 */
310 WallpaperUtil.clearThirdPartyAppName = function() {
311 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalThirdPartyAppName, '',
tbarzic 2016/01/28 20:10:48 WallpaperUtil.saveThirdPartyAppName('');
xdai1 2016/02/02 01:19:42 Done.
312 function() {
313 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncThirdPartyAppName, '');
314 });
315 };
316
317 /**
279 * Saves value to local storage that associates with key. 318 * Saves value to local storage that associates with key.
280 * @param {string} key The key that associates with value. 319 * @param {string} key The key that associates with value.
281 * @param {string} value The value to save to local storage. 320 * @param {string} value The value to save to local storage.
282 * @param {function=} opt_callback The callback on success. 321 * @param {function=} opt_callback The callback on success.
283 */ 322 */
284 WallpaperUtil.saveToLocalStorage = function(key, value, opt_callback) { 323 WallpaperUtil.saveToLocalStorage = function(key, value, opt_callback) {
285 var items = {}; 324 var items = {};
286 items[key] = value; 325 items[key] = value;
287 Constants.WallpaperLocalStorage.set(items, opt_callback); 326 Constants.WallpaperLocalStorage.set(items, opt_callback);
288 }; 327 };
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 onSuccess(); 413 onSuccess();
375 return; 414 return;
376 } 415 }
377 416
378 self.fetchURL(url, 'arraybuffer', function(xhr) { 417 self.fetchURL(url, 'arraybuffer', function(xhr) {
379 if (xhr.response != null) { 418 if (xhr.response != null) {
380 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 419 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
381 onSuccess); 420 onSuccess);
382 self.saveWallpaperInfo(url, layout, 421 self.saveWallpaperInfo(url, layout,
383 Constants.WallpaperSourceEnum.Online); 422 Constants.WallpaperSourceEnum.Online);
423 WallpaperUtil.clearThirdPartyAppName();
384 } else { 424 } else {
385 onFailure(); 425 onFailure();
386 } 426 }
387 }, onFailure); 427 }, onFailure);
388 }); 428 });
389 }; 429 };
390 430
391 /** 431 /**
392 * Runs chrome.test.sendMessage in test environment. Does nothing if running 432 * Runs chrome.test.sendMessage in test environment. Does nothing if running
393 * in production environment. 433 * in production environment.
394 * 434 *
395 * @param {string} message Test message to send. 435 * @param {string} message Test message to send.
396 */ 436 */
397 WallpaperUtil.testSendMessage = function(message) { 437 WallpaperUtil.testSendMessage = function(message) {
398 var test = chrome.test || window.top.chrome.test; 438 var test = chrome.test || window.top.chrome.test;
399 if (test) 439 if (test)
400 test.sendMessage(message); 440 test.sendMessage(message);
401 }; 441 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698