| Index: chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
|
| diff --git a/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js b/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
|
| index 2a6b9a9581a57ba02b93673e5c4b7682039541d2..f986347a79419de1bb325ff9808e68403a3e3f45 100644
|
| --- a/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
|
| +++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
|
| @@ -237,82 +237,78 @@ chrome.app.runtime.onLaunched.addListener(function() {
|
| });
|
|
|
| chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) {
|
| - WallpaperUtil.enabledSyncThemesCallback(function() {
|
| - WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| - if (detail.status == 'synced' &&
|
| - detail.direction == 'remote_to_local') {
|
| - if (detail.action == 'added') {
|
| - Constants.WallpaperLocalStorage.get(
|
| - Constants.AccessLocalWallpaperInfoKey,
|
| - function(items) {
|
| - var localData = items[Constants.AccessLocalWallpaperInfoKey];
|
| - if (localData && localData.url == detail.fileEntry.name &&
|
| - localData.source == Constants.WallpaperSourceEnum.Custom) {
|
| - WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url,
|
| - localData.layout);
|
| - } else if (localData.url !=
|
| - detail.fileEntry.name.replace(
|
| - Constants.CustomWallpaperThumbnailSuffix, '')) {
|
| - WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(
|
| - detail.fileEntry);
|
| - }
|
| - });
|
| - } else if (detail.action == 'deleted') {
|
| - var fileName = detail.fileEntry.name.replace(
|
| - Constants.CustomWallpaperThumbnailSuffix, '');
|
| - WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
|
| - }
|
| + WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| + if (detail.status == 'synced' &&
|
| + detail.direction == 'remote_to_local') {
|
| + if (detail.action == 'added') {
|
| + Constants.WallpaperLocalStorage.get(
|
| + Constants.AccessLocalWallpaperInfoKey,
|
| + function(items) {
|
| + var localData = items[Constants.AccessLocalWallpaperInfoKey];
|
| + if (localData && localData.url == detail.fileEntry.name &&
|
| + localData.source == Constants.WallpaperSourceEnum.Custom) {
|
| + WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url,
|
| + localData.layout);
|
| + } else if (localData.url !=
|
| + detail.fileEntry.name.replace(
|
| + Constants.CustomWallpaperThumbnailSuffix, '')) {
|
| + WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(
|
| + detail.fileEntry);
|
| + }
|
| + });
|
| + } else if (detail.action == 'deleted') {
|
| + var fileName = detail.fileEntry.name.replace(
|
| + Constants.CustomWallpaperThumbnailSuffix, '');
|
| + WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
|
| }
|
| - });
|
| + }
|
| });
|
| });
|
|
|
| chrome.storage.onChanged.addListener(function(changes, namespace) {
|
| - WallpaperUtil.enabledSyncThemesCallback(function() {
|
| - WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| - WallpaperUtil.requestSyncFS(function() {});
|
| - });
|
| - if (changes[Constants.AccessSurpriseMeEnabledKey]) {
|
| - if (changes[Constants.AccessSurpriseMeEnabledKey].newValue) {
|
| - SurpriseWallpaper.getInstance().next();
|
| - } else {
|
| - SurpriseWallpaper.getInstance().disable();
|
| - }
|
| + WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| + WallpaperUtil.requestSyncFS(function() {});
|
| + });
|
| + if (changes[Constants.AccessSurpriseMeEnabledKey]) {
|
| + if (changes[Constants.AccessSurpriseMeEnabledKey].newValue) {
|
| + SurpriseWallpaper.getInstance().next();
|
| + } else {
|
| + SurpriseWallpaper.getInstance().disable();
|
| }
|
| + }
|
|
|
| - if (changes[Constants.AccessSyncWallpaperInfoKey]) {
|
| - var newValue = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
|
| - Constants.WallpaperLocalStorage.get(Constants.AccessLocalWallpaperInfoKey,
|
| - function(items) {
|
| - // Normally, the wallpaper info saved in local storage and sync storage
|
| - // are the same. If the synced value changed by sync service, they may
|
| - // different. In that case, change wallpaper to the one saved in sync
|
| - // storage and update the local value.
|
| - var localValue = items[Constants.AccessLocalWallpaperInfoKey];
|
| - if (localValue == undefined ||
|
| - localValue.url != newValue.url ||
|
| - localValue.layout != newValue.layout ||
|
| - localValue.source != newValue.source) {
|
| - if (newValue.source == Constants.WallpaperSourceEnum.Online) {
|
| - // TODO(bshe): Consider schedule an alarm to set online wallpaper
|
| - // later when failed. Note that we need to cancel the retry if user
|
| - // set another wallpaper before retry alarm invoked.
|
| - WallpaperUtil.setOnlineWallpaper(newValue.url, newValue.layout,
|
| - function() {}, function() {});
|
| - } else if (newValue.source == Constants.WallpaperSourceEnum.Custom) {
|
| - WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| - WallpaperUtil.setCustomWallpaperFromSyncFS(newValue.url,
|
| - newValue.layout);
|
| - });
|
| - } else if (newValue.source == Constants.WallpaperSourceEnum.Default) {
|
| - chrome.wallpaperPrivate.resetWallpaper();
|
| - }
|
| - WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
|
| - newValue, false);
|
| + if (changes[Constants.AccessSyncWallpaperInfoKey]) {
|
| + var newValue = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
|
| + Constants.WallpaperLocalStorage.get(Constants.AccessLocalWallpaperInfoKey,
|
| + function(items) {
|
| + // Normally, the wallpaper info saved in local storage and sync storage
|
| + // are the same. If the synced value changed by sync service, they may
|
| + // different. In that case, change wallpaper to the one saved in sync
|
| + // storage and update the local value.
|
| + var localValue = items[Constants.AccessLocalWallpaperInfoKey];
|
| + if (localValue == undefined ||
|
| + localValue.url != newValue.url ||
|
| + localValue.layout != newValue.layout ||
|
| + localValue.source != newValue.source) {
|
| + if (newValue.source == Constants.WallpaperSourceEnum.Online) {
|
| + // TODO(bshe): Consider schedule an alarm to set online wallpaper
|
| + // later when failed. Note that we need to cancel the retry if user
|
| + // set another wallpaper before retry alarm invoked.
|
| + WallpaperUtil.setOnlineWallpaper(newValue.url, newValue.layout,
|
| + function() {}, function() {});
|
| + } else if (newValue.source == Constants.WallpaperSourceEnum.Custom) {
|
| + WallpaperUtil.enabledExperimentalFeatureCallback(function() {
|
| + WallpaperUtil.setCustomWallpaperFromSyncFS(newValue.url,
|
| + newValue.layout);
|
| + });
|
| + } else if (newValue.source == Constants.WallpaperSourceEnum.Default) {
|
| + chrome.wallpaperPrivate.resetWallpaper();
|
| }
|
| - });
|
| - }
|
| - });
|
| + WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
|
| + newValue, false);
|
| + }
|
| + });
|
| + }
|
| });
|
|
|
| chrome.alarms.onAlarm.addListener(function() {
|
|
|