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

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js

Issue 676403002: Sync wallpaper based on sync themes setting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 wallpaperPickerWindow = w; 230 wallpaperPickerWindow = w;
231 chrome.wallpaperPrivate.minimizeInactiveWindows(); 231 chrome.wallpaperPrivate.minimizeInactiveWindows();
232 w.onClosed.addListener(function() { 232 w.onClosed.addListener(function() {
233 chrome.wallpaperPrivate.restoreMinimizedWindows(); 233 chrome.wallpaperPrivate.restoreMinimizedWindows();
234 }); 234 });
235 WallpaperUtil.testSendMessage('wallpaper-window-created'); 235 WallpaperUtil.testSendMessage('wallpaper-window-created');
236 }); 236 });
237 }); 237 });
238 238
239 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) { 239 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) {
240 WallpaperUtil.enabledExperimentalFeatureCallback(function() { 240 WallpaperUtil.enabledSyncThemesCallback(function() {
241 if (detail.status == 'synced' && 241 WallpaperUtil.enabledExperimentalFeatureCallback(function() {
242 detail.direction == 'remote_to_local') { 242 if (detail.status == 'synced' &&
243 if (detail.action == 'added') { 243 detail.direction == 'remote_to_local') {
244 Constants.WallpaperLocalStorage.get( 244 if (detail.action == 'added') {
245 Constants.AccessLocalWallpaperInfoKey, 245 Constants.WallpaperLocalStorage.get(
246 function(items) { 246 Constants.AccessLocalWallpaperInfoKey,
247 var localData = items[Constants.AccessLocalWallpaperInfoKey]; 247 function(items) {
248 if (localData && localData.url == detail.fileEntry.name && 248 var localData = items[Constants.AccessLocalWallpaperInfoKey];
249 localData.source == Constants.WallpaperSourceEnum.Custom) { 249 if (localData && localData.url == detail.fileEntry.name &&
250 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url, 250 localData.source == Constants.WallpaperSourceEnum.Custom) {
251 localData.layout); 251 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url,
252 } else if (localData.url != 252 localData.layout);
253 detail.fileEntry.name.replace( 253 } else if (localData.url !=
254 Constants.CustomWallpaperThumbnailSuffix, '')) { 254 detail.fileEntry.name.replace(
255 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS( 255 Constants.CustomWallpaperThumbnailSuffix, '')) {
256 detail.fileEntry); 256 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(
257 } 257 detail.fileEntry);
258 }); 258 }
259 } else if (detail.action == 'deleted') { 259 });
260 var fileName = detail.fileEntry.name.replace( 260 } else if (detail.action == 'deleted') {
261 Constants.CustomWallpaperThumbnailSuffix, ''); 261 var fileName = detail.fileEntry.name.replace(
262 WallpaperUtil.deleteWallpaperFromLocalFS(fileName); 262 Constants.CustomWallpaperThumbnailSuffix, '');
263 WallpaperUtil.deleteWallpaperFromLocalFS(fileName);
264 }
263 } 265 }
266 });
267 });
268 });
269
270 chrome.storage.onChanged.addListener(function(changes, namespace) {
271 WallpaperUtil.enabledSyncThemesCallback(function() {
272 WallpaperUtil.enabledExperimentalFeatureCallback(function() {
273 WallpaperUtil.requestSyncFS(function() {});
274 });
275 if (changes[Constants.AccessSurpriseMeEnabledKey]) {
276 if (changes[Constants.AccessSurpriseMeEnabledKey].newValue) {
277 SurpriseWallpaper.getInstance().next();
278 } else {
279 SurpriseWallpaper.getInstance().disable();
280 }
281 }
282
283 if (changes[Constants.AccessSyncWallpaperInfoKey]) {
284 var newValue = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
285 Constants.WallpaperLocalStorage.get(Constants.AccessLocalWallpaperInfoKey,
286 function(items) {
287 // Normally, the wallpaper info saved in local storage and sync storage
288 // are the same. If the synced value changed by sync service, they may
289 // different. In that case, change wallpaper to the one saved in sync
290 // storage and update the local value.
291 var localValue = items[Constants.AccessLocalWallpaperInfoKey];
292 if (localValue == undefined ||
293 localValue.url != newValue.url ||
294 localValue.layout != newValue.layout ||
295 localValue.source != newValue.source) {
296 if (newValue.source == Constants.WallpaperSourceEnum.Online) {
297 // TODO(bshe): Consider schedule an alarm to set online wallpaper
298 // later when failed. Note that we need to cancel the retry if user
299 // set another wallpaper before retry alarm invoked.
300 WallpaperUtil.setOnlineWallpaper(newValue.url, newValue.layout,
301 function() {}, function() {});
302 } else if (newValue.source == Constants.WallpaperSourceEnum.Custom) {
303 WallpaperUtil.enabledExperimentalFeatureCallback(function() {
304 WallpaperUtil.setCustomWallpaperFromSyncFS(newValue.url,
305 newValue.layout);
306 });
307 } else if (newValue.source == Constants.WallpaperSourceEnum.Default) {
308 chrome.wallpaperPrivate.resetWallpaper();
309 }
310 WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
311 newValue, false);
312 }
313 });
264 } 314 }
265 }); 315 });
266 }); 316 });
267 317
268 chrome.storage.onChanged.addListener(function(changes, namespace) {
269 WallpaperUtil.enabledExperimentalFeatureCallback(function() {
270 WallpaperUtil.requestSyncFS(function() {});
271 });
272 if (changes[Constants.AccessSurpriseMeEnabledKey]) {
273 if (changes[Constants.AccessSurpriseMeEnabledKey].newValue) {
274 SurpriseWallpaper.getInstance().next();
275 } else {
276 SurpriseWallpaper.getInstance().disable();
277 }
278 }
279
280 if (changes[Constants.AccessSyncWallpaperInfoKey]) {
281 var newValue = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
282 Constants.WallpaperLocalStorage.get(Constants.AccessLocalWallpaperInfoKey,
283 function(items) {
284 // Normally, the wallpaper info saved in local storage and sync storage
285 // are the same. If the synced value changed by sync service, they may
286 // different. In that case, change wallpaper to the one saved in sync
287 // storage and update the local value.
288 var localValue = items[Constants.AccessLocalWallpaperInfoKey];
289 if (localValue == undefined ||
290 localValue.url != newValue.url ||
291 localValue.layout != newValue.layout ||
292 localValue.source != newValue.source) {
293 if (newValue.source == Constants.WallpaperSourceEnum.Online) {
294 // TODO(bshe): Consider schedule an alarm to set online wallpaper
295 // later when failed. Note that we need to cancel the retry if user
296 // set another wallpaper before retry alarm invoked.
297 WallpaperUtil.setOnlineWallpaper(newValue.url, newValue.layout,
298 function() {}, function() {});
299 } else if (newValue.source == Constants.WallpaperSourceEnum.Custom) {
300 WallpaperUtil.enabledExperimentalFeatureCallback(function() {
301 WallpaperUtil.setCustomWallpaperFromSyncFS(newValue.url,
302 newValue.layout);
303 });
304 } else if (newValue.source == Constants.WallpaperSourceEnum.Default) {
305 chrome.wallpaperPrivate.resetWallpaper();
306 }
307 WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
308 newValue, false);
309 }
310 });
311 }
312 });
313
314 chrome.alarms.onAlarm.addListener(function() { 318 chrome.alarms.onAlarm.addListener(function() {
315 SurpriseWallpaper.getInstance().next(); 319 SurpriseWallpaper.getInstance().next();
316 }); 320 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698