});
});
+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);
+ }
+ }
+ });
+ });
+});
+
chrome.storage.onChanged.addListener(function(changes, namespace) {
- if (changes[Constants.AccessSurpriseMeEnabledKey]) {
- if (changes[Constants.AccessSurpriseMeEnabledKey].newValue) {
- SurpriseWallpaper.getInstance().next();
- } else {
- SurpriseWallpaper.getInstance().disable();
+ 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();
+ }
}
- }
- 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() {});
+ 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);
}
- WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
- newValue, false);
- }
- });
- }
+ });
+ }
+ });
});
chrome.alarms.onAlarm.addListener(function() {