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

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.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 WALLPAPER_PICKER_WIDTH = 574; 5 var WALLPAPER_PICKER_WIDTH = 574;
6 var WALLPAPER_PICKER_HEIGHT = 420; 6 var WALLPAPER_PICKER_HEIGHT = 420;
7 7
8 var wallpaperPickerWindow; 8 var wallpaperPickerWindow;
9 9
10 var surpriseWallpaper = null; 10 var surpriseWallpaper = null;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 chrome.wallpaperPrivate.restoreMinimizedWindows(); 265 chrome.wallpaperPrivate.restoreMinimizedWindows();
266 }); 266 });
267 WallpaperUtil.testSendMessage('wallpaper-window-created'); 267 WallpaperUtil.testSendMessage('wallpaper-window-created');
268 }); 268 });
269 }); 269 });
270 270
271 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) { 271 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) {
272 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { 272 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) {
273 if (!syncEnabled) 273 if (!syncEnabled)
274 return; 274 return;
275 if (detail.status == 'synced') { 275 if (detail.status == 'synced' && detail.direction == 'remote_to_local') {
tbarzic 2016/02/05 22:27:37 nit: I think this would be easier to read: if (de
xdai1 2016/02/06 01:42:30 Done.
276 if (detail.direction == 'remote_to_local') { 276 if (detail.action == 'added') {
277 if (detail.action == 'added') { 277 // TODO(xdai): Get rid of this setCustomWallpaperFromSyncFS logic.
278 Constants.WallpaperLocalStorage.get( 278 // WallpaperInfo is saved in the sync filesystem before the corresonding
tbarzic 2016/02/05 22:27:37 I'm not sure if this is necessary true. I don't th
xdai1 2016/02/06 01:42:30 As discussed offline, modified the comment to bett
279 Constants.AccessLocalWallpaperInfoKey, 279 // custom wallpaper and thumbnail are saved, thus the onChanged() might
280 function(items) { 280 // not set the custom wallpaper correctly.
281 var localData = items[Constants.AccessLocalWallpaperInfoKey]; 281 Constants.WallpaperLocalStorage.get(
282 if (localData && localData.url == detail.fileEntry.name && 282 Constants.AccessLocalWallpaperInfoKey, function(items) {
283 localData.source == Constants.WallpaperSourceEnum.Custom) { 283 var localData = items[Constants.AccessLocalWallpaperInfoKey];
284 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url, 284 if (localData &&
285 localData.layout); 285 localData.url == detail.fileEntry.name &&
286 } else if (!localData || localData.url != 286 localData.source == Constants.WallpaperSourceEnum.Custom) {
287 detail.fileEntry.name.replace( 287 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url,
288 Constants.CustomWallpaperThumbnailSuffix, '')) { 288 localData.layout);
289 // localData might be null on a powerwashed device. 289 }
290 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS( 290 });
291 detail.fileEntry); 291 // We only need to store the custom wallpaper if it was set by the
292 } 292 // built-in wallpaper picker.
293 }); 293 if (detail.fileEntry.name.indexOf(
294 } else if (detail.action == 'deleted') { 294 Constants.ThirdPartyWallpaperPrefix) == -1) {
295 var fileName = detail.fileEntry.name.replace( 295 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(detail.fileEntry);
tbarzic 2016/02/05 22:27:37 Previously, local FS was not updated if call to wa
xdai1 2016/02/06 01:42:30 I prefer the current behavior. Even if the synced
tbarzic 2016/02/06 01:50:14 OK.
296 Constants.CustomWallpaperThumbnailSuffix, '');
297 WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
298 } 296 }
297 } else if (detail.action == 'deleted') {
298 var fileName = detail.fileEntry.name.replace(
299 Constants.CustomWallpaperThumbnailSuffix, '');
300 WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
299 } 301 }
300 } 302 }
301 }); 303 });
302 }); 304 });
303 305
304 chrome.storage.onChanged.addListener(function(changes, namespace) { 306 chrome.storage.onChanged.addListener(function(changes, namespace) {
305 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { 307 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) {
306 if (syncEnabled) { 308 if (syncEnabled) {
307 // If sync theme is enabled, use values from chrome.storage.sync to sync 309 // If sync theme is enabled, use values from chrome.storage.sync to sync
308 // wallpaper changes. 310 // wallpaper changes.
309 WallpaperUtil.requestSyncFS(function() {}); 311 WallpaperUtil.requestSyncFS(function() {});
310 if (changes[Constants.AccessSyncSurpriseMeEnabledKey]) { 312 if (changes[Constants.AccessSyncSurpriseMeEnabledKey]) {
311 if (changes[Constants.AccessSyncSurpriseMeEnabledKey].newValue) { 313 if (changes[Constants.AccessSyncSurpriseMeEnabledKey].newValue) {
312 SurpriseWallpaper.getInstance().next(); 314 SurpriseWallpaper.getInstance().next();
313 } else { 315 } else {
314 SurpriseWallpaper.getInstance().disable(); 316 SurpriseWallpaper.getInstance().disable();
315 } 317 }
316 } 318 }
317 319
318 if (changes[Constants.AccessLocalWallpaperInfoKey]) { 320 if (changes[Constants.AccessLocalWallpaperInfoKey]) {
319 // If the old wallpaper is a third party wallpaper we should remove it 321 // If the old wallpaper is a third party wallpaper we should remove it
320 // from the local & sync file system to free space. 322 // from the local & sync file system to free space.
321 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; 323 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue;
322 if (oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { 324 if (oldInfo &&
325 oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) {
323 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); 326 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url);
324 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); 327 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url);
325 } 328 }
326 } 329 }
327 330
328 if (changes[Constants.AccessSyncWallpaperInfoKey]) { 331 if (changes[Constants.AccessSyncWallpaperInfoKey]) {
329 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; 332 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
330 333
331 Constants.WallpaperSyncStorage.get( 334 Constants.WallpaperSyncStorage.get(
332 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { 335 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) {
(...skipping 14 matching lines...) Expand all
347 (syncSurpriseMeEnabled && 350 (syncSurpriseMeEnabled &&
348 syncLastSurpriseMeChangedDate == today)) { 351 syncLastSurpriseMeChangedDate == today)) {
349 Constants.WallpaperLocalStorage.get( 352 Constants.WallpaperLocalStorage.get(
350 Constants.AccessLocalWallpaperInfoKey, function(infoItems) { 353 Constants.AccessLocalWallpaperInfoKey, function(infoItems) {
351 var localInfo = 354 var localInfo =
352 infoItems[Constants.AccessLocalWallpaperInfoKey]; 355 infoItems[Constants.AccessLocalWallpaperInfoKey];
353 // Normally, the wallpaper info saved in local storage and sync 356 // Normally, the wallpaper info saved in local storage and sync
354 // storage are the same. If the synced value changed by sync 357 // storage are the same. If the synced value changed by sync
355 // service, they may different. In that case, change wallpaper 358 // service, they may different. In that case, change wallpaper
356 // to the one saved in sync storage and update the local value. 359 // to the one saved in sync storage and update the local value.
357 if (localInfo == undefined || 360 if (!localInfo ||
358 localInfo.url != syncInfo.url || 361 localInfo.url != syncInfo.url ||
359 localInfo.layout != syncInfo.layout || 362 localInfo.layout != syncInfo.layout ||
360 localInfo.source != syncInfo.source) { 363 localInfo.source != syncInfo.source) {
361 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) { 364 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) {
362 // TODO(bshe): Consider schedule an alarm to set online 365 // TODO(bshe): Consider schedule an alarm to set online
363 // wallpaper later when failed. Note that we need to cancel 366 // wallpaper later when failed. Note that we need to cancel
364 // the retry if user set another wallpaper before retry 367 // the retry if user set another wallpaper before retry
365 // alarm invoked. 368 // alarm invoked.
366 WallpaperUtil.setOnlineWallpaper(syncInfo.url, 369 WallpaperUtil.setOnlineWallpaper(syncInfo.url,
367 syncInfo.layout, function() {}, function() {}); 370 syncInfo.layout, function() {}, function() {});
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 405 }
403 } 406 }
404 }); 407 });
405 }); 408 });
406 409
407 chrome.alarms.onAlarm.addListener(function() { 410 chrome.alarms.onAlarm.addListener(function() {
408 SurpriseWallpaper.getInstance().next(); 411 SurpriseWallpaper.getInstance().next();
409 }); 412 });
410 413
411 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( 414 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function(
412 wallpaper, thumbnail, layout) { 415 wallpaper, thumbnail, layout, appName) {
413 WallpaperUtil.saveToLocalStorage( 416 WallpaperUtil.saveToLocalStorage(
414 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { 417 Constants.AccessLocalSurpriseMeEnabledKey, false, function() {
415 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, 418 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey,
416 false); 419 false);
417 }); 420 });
418 SurpriseWallpaper.getInstance().disable(); 421 SurpriseWallpaper.getInstance().disable();
419 422
420 // Make third party wallpaper syncable through different devices. 423 // Make third party wallpaper syncable through different devices.
421 // TODO(xdai): also sync the third party app name.
422 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime(); 424 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime();
423 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; 425 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix;
424 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); 426 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper);
425 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); 427 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail);
426 WallpaperUtil.saveWallpaperInfo(filename, layout, 428 WallpaperUtil.saveWallpaperInfo(
427 Constants.WallpaperSourceEnum.Custom); 429 filename, layout, Constants.WallpaperSourceEnum.Custom, appName);
428 }); 430 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698