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

Unified Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js

Issue 956403003: Fix the issue that wallpaper changes twice when both "onChanged" and "onAlarm" are fired. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9e693e4c5843be3f6589941d6df2b8dcbe520418..a6f44c5bc3ef2e963f6dd3af688bd788e8cbaecb 100644
--- a/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
+++ b/chrome/browser/resources/chromeos/wallpaper_manager/js/event_page.js
@@ -115,11 +115,8 @@ SurpriseWallpaper.prototype.updateRandomWallpaper_ = function() {
var self = this;
Constants.WallpaperSyncStorage.get(
Constants.AccessLastSurpriseWallpaperChangedDate, function(items) {
- var dateString = new Date().toDateString();
- // At most one random wallpaper per day.
- if (items[Constants.AccessLastSurpriseWallpaperChangedDate] != dateString) {
- self.setRandomWallpaper_(dateString);
- }
+ var today = new Date().toDateString();
+ self.setRandomWallpaper_(today);
});
};
@@ -150,6 +147,8 @@ SurpriseWallpaper.prototype.setRandomWallpaper_ = function(dateString) {
Constants.AccessLastSurpriseWallpaperChangedDate,
dateString,
true);
+ WallpaperUtil.saveWallpaperInfo(wallpaperURL, wallpaper.default_layout,
+ Constants.WallpaperSourceEnum.Online);
bshe 2015/03/04 19:45:39 nit: 4 spaces indention for new line.
xdai1 2015/03/04 21:32:39 Done.
};
WallpaperUtil.setOnlineWallpaper(wallpaperURL, wallpaper.default_layout,
onSuccess, self.retryLater_.bind(self));
@@ -194,13 +193,22 @@ SurpriseWallpaper.prototype.disable = function() {
};
/**
- * Changes current wallpaper and sets up an alarm to schedule next change around
- * midnight.
+ * Changes current wallpaper once a day and sets up an alarm to schedule next
+ * change around midnight. If the surprise wallpaper was already set toady,
+ * then don't change it any more.
*/
SurpriseWallpaper.prototype.next = function() {
var nextUpdate = this.nextUpdateTime(new Date());
chrome.alarms.create({when: nextUpdate});
- this.tryChangeWallpaper();
+
+ var self = this;
+ Constants.WallpaperSyncStorage.get(
bshe 2015/03/04 19:45:39 why do you want to move the check to here? Looks l
xdai1 2015/03/04 21:32:39 Since when surprise me is enabled, we only change
bshe 2015/03/05 14:53:19 Rss wallpaper is not saved to sync storage and we
+ Constants.AccessLastSurpriseWallpaperChangedDate, function(items) {
+ var today = new Date().toDateString();
+ if (items[Constants.AccessLastSurpriseWallpaperChangedDate] != today) {
+ self.tryChangeWallpaper();
+ }
+ });
};
/**
@@ -277,33 +285,57 @@ chrome.storage.onChanged.addListener(function(changes, namespace) {
}
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.setCustomWallpaperFromSyncFS(newValue.url,
- newValue.layout);
- } else if (newValue.source == Constants.WallpaperSourceEnum.Default) {
- chrome.wallpaperPrivate.resetWallpaper();
+ var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue;
+
+ Constants.WallpaperSyncStorage.get(Constants.AccessSurpriseMeEnabledKey,
+ function(enabledItems) {
+ var syncSurpriseMeEnabled =
+ enabledItems[Constants.AccessSurpriseMeEnabledKey];
bshe 2015/03/04 19:45:39 nit: 4 spaces indention
xdai1 2015/03/04 21:32:39 Done.
+
+ Constants.WallpaperSyncStorage.get(
+ Constants.AccessLastSurpriseWallpaperChangedDate, function(items) {
bshe 2015/03/04 19:45:39 ditto
xdai1 2015/03/04 21:32:39 Done.
+ var syncLastSurpriseMeChangedDate =
bshe 2015/03/04 19:45:39 nit: function implementation should have 2 space i
xdai1 2015/03/04 21:32:39 I think it already has 2 space indention?
+ items[Constants.AccessLastSurpriseWallpaperChangedDate];
+
+ var today = new Date().toDateString();
+ // If SurpriseMe is enabled and surprise wallpaper hasn't been changed
+ // today, we should not sync the change, instead onAlarm() will be
+ // triggered to update a surprise me wallpaper.
+ if (!syncSurpriseMeEnabled || (syncSurpriseMeEnabled &&
+ syncLastSurpriseMeChangedDate == today)) {
bshe 2015/03/04 19:45:39 nit: indention is off. Consider this: if (!syncSur
xdai1 2015/03/04 21:32:39 Done.
+ Constants.WallpaperLocalStorage.get(
+ Constants.AccessLocalWallpaperInfoKey, function(infoItems) {
+ var localInfo =
+ infoItems[Constants.AccessLocalWallpaperInfoKey];
bshe 2015/03/04 19:45:39 nit: 4 space indention
xdai1 2015/03/04 21:32:39 Done.
+ // 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.
+ if (localInfo == undefined ||
+ localInfo.url != syncInfo.url ||
+ localInfo.layout != syncInfo.layout ||
+ localInfo.source != syncInfo.source) {
+ if (syncInfo.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(syncInfo.url,
+ syncInfo.layout, function() {}, function() {});
+ } else if (syncInfo.source ==
+ Constants.WallpaperSourceEnum.Custom) {
+ WallpaperUtil.setCustomWallpaperFromSyncFS(syncInfo.url,
+ syncInfo.layout);
+ } else if (syncInfo.source ==
+ Constants.WallpaperSourceEnum.Default) {
+ chrome.wallpaperPrivate.resetWallpaper();
+ }
+ WallpaperUtil.saveToStorage(
+ Constants.AccessLocalWallpaperInfoKey, syncInfo, false);
+ }
+ });
}
- WallpaperUtil.saveToStorage(Constants.AccessLocalWallpaperInfoKey,
- newValue, false);
- }
+ });
});
}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698