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

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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 }, function(w) { 261 }, function(w) {
262 wallpaperPickerWindow = w; 262 wallpaperPickerWindow = w;
263 chrome.wallpaperPrivate.minimizeInactiveWindows(); 263 chrome.wallpaperPrivate.minimizeInactiveWindows();
264 w.onClosed.addListener(function() { 264 w.onClosed.addListener(function() {
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) {
tbarzic 2016/02/04 21:31:24 More suitable for another cl: sync file system is
xdai1 2016/02/05 01:09:52 Sync file system is updated both for thumbnails an
tbarzic 2016/02/05 22:27:37 Oh, yeah, I see what you mean after second reading
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') {
276 if (detail.direction == 'remote_to_local') { 276 if (detail.direction == 'remote_to_local') {
277 if (detail.action == 'added') { 277 if (detail.action == 'added') {
278 Constants.WallpaperLocalStorage.get( 278 Constants.WallpaperLocalStorage.get(
279 Constants.AccessLocalWallpaperInfoKey, 279 Constants.AccessLocalWallpaperInfoKey,
280 function(items) { 280 function(items) {
281 var localData = items[Constants.AccessLocalWallpaperInfoKey]; 281 var localData = items[Constants.AccessLocalWallpaperInfoKey];
282 if (localData && localData.url == detail.fileEntry.name && 282 if (!localData) {
283 // localData might be null on a powerwashed device.
284 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(
285 detail.fileEntry);
286 } else if (localData.url == detail.fileEntry.name &&
283 localData.source == Constants.WallpaperSourceEnum.Custom) { 287 localData.source == Constants.WallpaperSourceEnum.Custom) {
284 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url, 288 if (localData.hasOwnProperty('appName')) {
285 localData.layout); 289 WallpaperUtil.setCustomWallpaperFromSyncFS(
286 } else if (!localData || localData.url != 290 localData.url, localData.layout, localData.appName);
tbarzic 2016/02/04 21:31:24 I'd just use localData.appName || '' (instead of i
287 detail.fileEntry.name.replace( 291 } else {
288 Constants.CustomWallpaperThumbnailSuffix, '')) { 292 WallpaperUtil.setCustomWallpaperFromSyncFS(
289 // localData might be null on a powerwashed device. 293 localData.url, localData.layout, '');
294 }
295 } else if (localData.url != detail.fileEntry.name.replace(
296 Constants.CustomWallpaperThumbnailSuffix, '') &&
297 detail.fileEntry.name.indexOf(
298 Constants.ThirdPartyWallpaperPrefix) == -1) {
290 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS( 299 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(
291 detail.fileEntry); 300 detail.fileEntry);
292 } 301 }
293 }); 302 });
294 } else if (detail.action == 'deleted') { 303 } else if (detail.action == 'deleted') {
295 var fileName = detail.fileEntry.name.replace( 304 var fileName = detail.fileEntry.name.replace(
296 Constants.CustomWallpaperThumbnailSuffix, ''); 305 Constants.CustomWallpaperThumbnailSuffix, '');
297 WallpaperUtil.deleteWallpaperFromLocalFS(fileName); 306 WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
298 } 307 }
299 } 308 }
(...skipping 12 matching lines...) Expand all
312 SurpriseWallpaper.getInstance().next(); 321 SurpriseWallpaper.getInstance().next();
313 } else { 322 } else {
314 SurpriseWallpaper.getInstance().disable(); 323 SurpriseWallpaper.getInstance().disable();
315 } 324 }
316 } 325 }
317 326
318 if (changes[Constants.AccessLocalWallpaperInfoKey]) { 327 if (changes[Constants.AccessLocalWallpaperInfoKey]) {
319 // If the old wallpaper is a third party wallpaper we should remove it 328 // If the old wallpaper is a third party wallpaper we should remove it
320 // from the local & sync file system to free space. 329 // from the local & sync file system to free space.
321 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; 330 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue;
322 if (oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { 331 if (oldInfo &&
332 oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) {
323 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); 333 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url);
324 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); 334 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url);
325 } 335 }
326 } 336 }
327 337
328 if (changes[Constants.AccessSyncWallpaperInfoKey]) { 338 if (changes[Constants.AccessSyncWallpaperInfoKey]) {
329 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; 339 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
330 340
331 Constants.WallpaperSyncStorage.get( 341 Constants.WallpaperSyncStorage.get(
332 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { 342 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) {
(...skipping 14 matching lines...) Expand all
347 (syncSurpriseMeEnabled && 357 (syncSurpriseMeEnabled &&
348 syncLastSurpriseMeChangedDate == today)) { 358 syncLastSurpriseMeChangedDate == today)) {
349 Constants.WallpaperLocalStorage.get( 359 Constants.WallpaperLocalStorage.get(
350 Constants.AccessLocalWallpaperInfoKey, function(infoItems) { 360 Constants.AccessLocalWallpaperInfoKey, function(infoItems) {
351 var localInfo = 361 var localInfo =
352 infoItems[Constants.AccessLocalWallpaperInfoKey]; 362 infoItems[Constants.AccessLocalWallpaperInfoKey];
353 // Normally, the wallpaper info saved in local storage and sync 363 // Normally, the wallpaper info saved in local storage and sync
354 // storage are the same. If the synced value changed by sync 364 // storage are the same. If the synced value changed by sync
355 // service, they may different. In that case, change wallpaper 365 // service, they may different. In that case, change wallpaper
356 // to the one saved in sync storage and update the local value. 366 // to the one saved in sync storage and update the local value.
357 if (localInfo == undefined || 367 if (!localInfo ||
358 localInfo.url != syncInfo.url || 368 localInfo.url != syncInfo.url ||
359 localInfo.layout != syncInfo.layout || 369 localInfo.layout != syncInfo.layout ||
360 localInfo.source != syncInfo.source) { 370 localInfo.source != syncInfo.source) {
361 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) { 371 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) {
362 // TODO(bshe): Consider schedule an alarm to set online 372 // TODO(bshe): Consider schedule an alarm to set online
363 // wallpaper later when failed. Note that we need to cancel 373 // wallpaper later when failed. Note that we need to cancel
364 // the retry if user set another wallpaper before retry 374 // the retry if user set another wallpaper before retry
365 // alarm invoked. 375 // alarm invoked.
366 WallpaperUtil.setOnlineWallpaper(syncInfo.url, 376 WallpaperUtil.setOnlineWallpaper(syncInfo.url,
367 syncInfo.layout, function() {}, function() {}); 377 syncInfo.layout, function() {}, function() {});
368 } else if (syncInfo.source == 378 } else if (syncInfo.source ==
369 Constants.WallpaperSourceEnum.Custom) { 379 Constants.WallpaperSourceEnum.Custom) {
370 WallpaperUtil.setCustomWallpaperFromSyncFS(syncInfo.url, 380 if (syncInfo.hasOwnProperty('appName')) {
371 syncInfo.layout); 381 WallpaperUtil.setCustomWallpaperFromSyncFS(
382 syncInfo.url, syncInfo.layout, syncInfo.appName);
tbarzic 2016/02/04 21:31:24 How about: WallpaperUtil.setCustomWallpaperFromSyn
xdai1 2016/02/05 01:09:52 As explained in WallpaperUtil.setCustomWallpaperFr
383 } else {
384 WallpaperUtil.setCustomWallpaperFromSyncFS(
385 syncInfo.url, syncInfo.layout, '');
386 }
372 } else if (syncInfo.source == 387 } else if (syncInfo.source ==
373 Constants.WallpaperSourceEnum.Default) { 388 Constants.WallpaperSourceEnum.Default) {
374 chrome.wallpaperPrivate.resetWallpaper(); 389 chrome.wallpaperPrivate.resetWallpaper();
375 } 390 }
376 391
377 // If the old wallpaper is a third party wallpaper we should 392 // If the old wallpaper is a third party wallpaper we should
378 // remove it from the local & sync file system to free space. 393 // remove it from the local & sync file system to free space.
379 if (localInfo && localInfo.url.indexOf( 394 if (localInfo && localInfo.url.indexOf(
380 Constants.ThirdPartyWallpaperPrefix) != -1) { 395 Constants.ThirdPartyWallpaperPrefix) != -1) {
381 WallpaperUtil.deleteWallpaperFromLocalFS(localInfo.url); 396 WallpaperUtil.deleteWallpaperFromLocalFS(localInfo.url);
(...skipping 20 matching lines...) Expand all
402 } 417 }
403 } 418 }
404 }); 419 });
405 }); 420 });
406 421
407 chrome.alarms.onAlarm.addListener(function() { 422 chrome.alarms.onAlarm.addListener(function() {
408 SurpriseWallpaper.getInstance().next(); 423 SurpriseWallpaper.getInstance().next();
409 }); 424 });
410 425
411 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( 426 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function(
412 wallpaper, thumbnail, layout) { 427 wallpaper, thumbnail, layout, appName) {
413 WallpaperUtil.saveToLocalStorage( 428 WallpaperUtil.saveToLocalStorage(
414 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { 429 Constants.AccessLocalSurpriseMeEnabledKey, false, function() {
415 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, 430 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey,
416 false); 431 false);
417 }); 432 });
418 SurpriseWallpaper.getInstance().disable(); 433 SurpriseWallpaper.getInstance().disable();
419 434
420 // Make third party wallpaper syncable through different devices. 435 // 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(); 436 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime();
423 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; 437 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix;
424 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); 438 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper);
425 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); 439 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail);
426 WallpaperUtil.saveWallpaperInfo(filename, layout, 440 WallpaperUtil.saveWallpaperInfo(
tbarzic 2016/02/04 21:31:24 Not introduced here, but might make for a good fol
xdai1 2016/02/05 01:09:52 Might not true. It's the onChanged() event which i
tbarzic 2016/02/05 22:27:37 Oh, yeah, syncFileSystem,onFileStatusChange only h
427 Constants.WallpaperSourceEnum.Custom); 441 filename, layout, Constants.WallpaperSourceEnum.Custom, appName);
428 }); 442 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698