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

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: Address tbarzic@'s comments. 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 if (!wallpaperFilename) { 241 if (!wallpaperFilename) {
242 console.error('wallpaperFilename is not provided.'); 242 console.error('wallpaperFilename is not provided.');
243 return; 243 return;
244 } 244 }
245 if (!wallpaperLayout) 245 if (!wallpaperLayout)
246 wallpaperLayout = 'CENTER_CROPPED'; 246 wallpaperLayout = 'CENTER_CROPPED';
247 fs.root.getFile(wallpaperFilename, {create: false}, function(fileEntry) { 247 fs.root.getFile(wallpaperFilename, {create: false}, function(fileEntry) {
248 fileEntry.file(function(file) { 248 fileEntry.file(function(file) {
249 var reader = new FileReader(); 249 var reader = new FileReader();
250 reader.onloadend = function() { 250 reader.onloadend = function() {
251 chrome.wallpaperPrivate.setCustomWallpaper( 251 Constants.WallpaperSyncStorage.get(
tbarzic 2016/02/02 20:59:38 pass the app name as a function param (as filename
xdai1 2016/02/04 01:46:33 Done.
252 reader.result, 252 Constants.AccessSyncThirdPartyAppName, function(items) {
253 wallpaperLayout, 253 var thirdPartyAppName = '';
254 true, 254 if (items.hasOwnProperty(Constants.AccessSyncThirdPartyAppName))
255 wallpaperFilename, 255 thirdPartyAppName = items[Constants.AccessSyncThirdPartyAppName];
256 function(thumbnailData) { 256 chrome.wallpaperPrivate.setCustomWallpaper(
257 // TODO(ranj): Ignore 'canceledWallpaper' error. 257 reader.result,
258 if (chrome.runtime.lastError) { 258 wallpaperLayout,
259 console.error(chrome.runtime.lastError.message); 259 true,
260 return; 260 wallpaperFilename,
261 } 261 thirdPartyAppName,
262 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 262 function(thumbnailData) {
263 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL); 263 // TODO(ranj): Ignore 'canceledWallpaper' error.
264 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 264 if (chrome.runtime.lastError) {
265 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL); 265 console.error(chrome.runtime.lastError.message);
266 if (onSuccess) 266 return;
267 onSuccess(); 267 }
268 }); 268
269 // If it's a custom wallpaper (i.e., not set by a third party
270 // app), it should be stored into the local filesystem.
271 if (!thirdPartyAppName) {
272 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
273 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL);
274 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
275 thumbnailData,
276 Constants.WallpaperDirNameEnum.THUMBNAIL);
277 WallpaperUtil.clearThirdPartyAppName();
tbarzic 2016/02/02 20:59:38 the correct value should already be set at this po
278 }
279 if (onSuccess)
280 onSuccess();
281 });
282 });
269 }; 283 };
270 reader.readAsArrayBuffer(file); 284 reader.readAsArrayBuffer(file);
271 }, WallpaperUtil.onFileSystemError); 285 }, WallpaperUtil.onFileSystemError);
272 }, function(e) {} // fail to read file, expected due to download delay 286 }, function(e) {} // fail to read file, expected due to download delay
273 ); 287 );
274 }; 288 };
275 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback); 289 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback);
276 }; 290 };
277 291
278 /** 292 /**
293 * Save the third party wallpaper app name to local & sync filesystem.
294 * @param {string} appname The third party wallpaper extension or app's name.
295 */
296 WallpaperUtil.saveThirdPartyAppName = function(appname) {
297 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalThirdPartyAppName,
298 appname, function() {
299 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncThirdPartyAppName,
300 appname);
301 });
302 };
303
304 /**
305 * Clear the third party wallpaper app name from local & sync filesystem.
306 */
307 WallpaperUtil.clearThirdPartyAppName = function() {
308 WallpaperUtil.saveThirdPartyAppName('');
309 };
310
311 /**
279 * Saves value to local storage that associates with key. 312 * Saves value to local storage that associates with key.
280 * @param {string} key The key that associates with value. 313 * @param {string} key The key that associates with value.
281 * @param {string} value The value to save to local storage. 314 * @param {string} value The value to save to local storage.
282 * @param {function=} opt_callback The callback on success. 315 * @param {function=} opt_callback The callback on success.
283 */ 316 */
284 WallpaperUtil.saveToLocalStorage = function(key, value, opt_callback) { 317 WallpaperUtil.saveToLocalStorage = function(key, value, opt_callback) {
285 var items = {}; 318 var items = {};
286 items[key] = value; 319 items[key] = value;
287 Constants.WallpaperLocalStorage.set(items, opt_callback); 320 Constants.WallpaperLocalStorage.set(items, opt_callback);
288 }; 321 };
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 onSuccess(); 407 onSuccess();
375 return; 408 return;
376 } 409 }
377 410
378 self.fetchURL(url, 'arraybuffer', function(xhr) { 411 self.fetchURL(url, 'arraybuffer', function(xhr) {
379 if (xhr.response != null) { 412 if (xhr.response != null) {
380 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 413 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
381 onSuccess); 414 onSuccess);
382 self.saveWallpaperInfo(url, layout, 415 self.saveWallpaperInfo(url, layout,
383 Constants.WallpaperSourceEnum.Online); 416 Constants.WallpaperSourceEnum.Online);
417 WallpaperUtil.clearThirdPartyAppName();
384 } else { 418 } else {
385 onFailure(); 419 onFailure();
386 } 420 }
387 }, onFailure); 421 }, onFailure);
388 }); 422 });
389 }; 423 };
390 424
391 /** 425 /**
392 * Runs chrome.test.sendMessage in test environment. Does nothing if running 426 * Runs chrome.test.sendMessage in test environment. Does nothing if running
393 * in production environment. 427 * in production environment.
394 * 428 *
395 * @param {string} message Test message to send. 429 * @param {string} message Test message to send.
396 */ 430 */
397 WallpaperUtil.testSendMessage = function(message) { 431 WallpaperUtil.testSendMessage = function(message) {
398 var test = chrome.test || window.top.chrome.test; 432 var test = chrome.test || window.top.chrome.test;
399 if (test) 433 if (test)
400 test.sendMessage(message); 434 test.sendMessage(message);
401 }; 435 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698