Commit 5d75b735 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Clean up old wallpaper picker code (Part III)

Remove more dead code.

Bug: 812085
Change-Id: I1ba634e3fb41d61511736dc7c057a5bbc5903c78
Reviewed-on: https://chromium-review.googlesource.com/c/1300315
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604772}
parent 2ebd2c83
......@@ -127,20 +127,6 @@ body.v1 {
position: relative;
}
#spinner-container {
-webkit-box-align: center;
-webkit-box-pack: center;
background: url(chrome://resources/images/throbber_medium.svg) center/32px
no-repeat;
display: -webkit-box;
height: 287px;
padding-bottom: 15px;
padding-top: 5px;
position: absolute;
top: 0;
width: 100%;
}
#wallpaper-set-by-message {
height: 30px;
padding-inline-end: 5px;
......
......@@ -4,11 +4,6 @@
/** @const */ var Constants = {
/**
* Key to access wallpaper rss in chrome.storage.local.
*/
AccessLocalRssKey: 'wallpaper-picker-surprise-rss-key',
/**
* Key to access wallpaper manifest in chrome.storage.local.
*/
......@@ -59,18 +54,6 @@
*/
AccessLocalImagesInfoKey: 'images-info-key',
/**
* URL to get latest wallpaper RSS feed.
*/
WallpaperRssURL: 'https://storage.googleapis.com/' +
'chromeos-wallpaper-public/wallpaper.rss',
/**
* cros-wallpaper namespace URI.
*/
WallpaperNameSpaceURI: 'http://commondatastorage.googleapis.com/' +
'chromeos-wallpaper-public/cros-wallpaper-uri',
/**
* Wallpaper sources enum.
*/
......@@ -80,7 +63,6 @@
OEM: 'OEM',
Custom: 'CUSTOM',
ThirdParty: 'THIRDPARTY',
AddNew: 'ADDNEW',
Default: 'DEFAULT'
},
......
......@@ -30,103 +30,15 @@ SurpriseWallpaper.getInstance = function() {
return surpriseWallpaper;
};
/**
* Tries to change wallpaper to a new one in the background. May fail due to a
* network issue.
*/
SurpriseWallpaper.prototype.tryChangeWallpaper = function() {
var self = this;
var onFailure = function(status) {
if (status != 404)
self.fallbackToLocalRss_();
else
self.updateRandomWallpaper_();
};
// Try to fetch newest rss as document from server first. If the requested
// URL is not found (404 error), set a random wallpaper displayed in the
// wallpaper picker. If any other error occurs, proceed with local copy of
// rss.
WallpaperUtil.fetchURL(Constants.WallpaperRssURL, 'document', function(xhr) {
WallpaperUtil.saveToLocalStorage(
Constants.AccessLocalRssKey,
new XMLSerializer().serializeToString(xhr.responseXML));
self.updateSurpriseWallpaper(xhr.responseXML);
}, onFailure);
};
/**
* Retries changing the wallpaper 1 hour later. This is called when fetching the
* rss or wallpaper from server fails.
* wallpaper from server fails.
* @private
*/
SurpriseWallpaper.prototype.retryLater_ = function() {
chrome.alarms.create('RetryAlarm', {delayInMinutes: 60});
};
/**
* Fetches the cached rss feed from local storage in the event of being unable
* to download the online feed.
* @private
*/
SurpriseWallpaper.prototype.fallbackToLocalRss_ = function() {
var self = this;
Constants.WallpaperLocalStorage.get(
Constants.AccessLocalRssKey, function(items) {
var rssString = items[Constants.AccessLocalRssKey];
if (rssString) {
self.updateSurpriseWallpaper(
new DOMParser().parseFromString(rssString, 'text/xml'));
} else {
self.updateSurpriseWallpaper();
}
});
};
/**
* Starts to change wallpaper. Called after rss is fetched.
* @param {Document=} opt_rss The fetched rss document. If opt_rss is null, uses
* a random wallpaper.
*/
SurpriseWallpaper.prototype.updateSurpriseWallpaper = function(opt_rss) {
if (opt_rss) {
var items = opt_rss.querySelectorAll('item');
var date = new Date(new Date().toDateString()).getTime();
for (var i = 0; i < items.length; i++) {
item = items[i];
var disableDate =
new Date(item.getElementsByTagNameNS(
Constants.WallpaperNameSpaceURI, 'disableDate')[0]
.textContent)
.getTime();
var enableDate =
new Date(item.getElementsByTagNameNS(
Constants.WallpaperNameSpaceURI, 'enableDate')[0]
.textContent)
.getTime();
var regionsString = item.getElementsByTagNameNS(
Constants.WallpaperNameSpaceURI, 'regions')[0]
.textContent;
var regions = regionsString.split(', ');
if (enableDate <= date && disableDate > date &&
regions.indexOf(navigator.language) != -1) {
var self = this;
this.setWallpaperFromRssItem_(
item, function() {},
function(status) {
if (status != 404)
self.retryLater_();
else
self.updateRandomWallpaper_();
});
return;
}
}
}
// No surprise wallpaper for today at current locale or fetching rss feed
// fails. Fallback to use a random one from wallpaper server.
this.updateRandomWallpaper_();
};
/**
* Sets a new random wallpaper if one has not already been set today.
* @private
......@@ -241,41 +153,6 @@ SurpriseWallpaper.prototype.setRandomWallpaperFromServer_ = function(
WallpaperUtil.getDailyRefreshInfo(onDailyRefreshInfoReturned.bind(null));
};
/**
* Sets wallpaper to the wallpaper specified by item from rss. If downloading
* the wallpaper fails, retry one hour later.
* @param {Element} item The wallpaper rss item element.
* @param {function} onSuccess Success callback.
* @param {function} onFailure Failure callback.
* @private
*/
SurpriseWallpaper.prototype.setWallpaperFromRssItem_ = function(
item, onSuccess, onFailure) {
var url = item.querySelector('link').textContent;
var layout =
item.getElementsByTagNameNS(Constants.WallpaperNameSpaceURI, 'layout')[0]
.textContent;
var self = this;
WallpaperUtil.fetchURL(url, 'arraybuffer', function(xhr) {
if (xhr.response != null) {
chrome.wallpaperPrivate.setCustomWallpaper(
xhr.response, layout, false /*generateThumbnail=*/,
'surprise_wallpaper', false /*previewMode=*/, onSuccess);
WallpaperUtil.saveWallpaperInfo(
url, layout, Constants.WallpaperSourceEnum.Daily, '');
var dateString = new Date().toDateString();
WallpaperUtil.saveToLocalStorage(
Constants.AccessLastSurpriseWallpaperChangedDate, dateString,
function() {
WallpaperUtil.saveToSyncStorage(
Constants.AccessLastSurpriseWallpaperChangedDate, dataString);
});
} else {
self.updateRandomWallpaper_();
}
}, onFailure);
};
/**
* Disables the wallpaper surprise me feature. Clear all alarms and states.
*/
......@@ -296,7 +173,7 @@ SurpriseWallpaper.prototype.disable = function() {
SurpriseWallpaper.prototype.next = function() {
var nextUpdate = this.nextUpdateTime(new Date());
chrome.alarms.create({when: nextUpdate});
this.tryChangeWallpaper();
this.updateRandomWallpaper_();
};
/**
......
......@@ -34,7 +34,6 @@
// <include src="constants.js">
// <include src="util.js">
// <include src="progress_manager.js">
// <include src="wallpaper_directories.js">
// <include src="wallpaper_categories_list.js">
// <include src="wallpaper_images_grid.js">
// <include src="wallpaper_manager.js">
......
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Wallpaper file system quota.
*/
/** @const */ var WallpaperQuota = 1024 * 1024 * 100;
var wallpaperDirectories = null;
/**
* Manages custom wallpaper related directories in wallpaper's sandboxed
* FileSystem.
* @constructor
*/
function WallpaperDirectories() {
this.wallpaperDirs_ = {};
this.wallpaperDirs_[Constants.WallpaperDirNameEnum.ORIGINAL] = null;
this.wallpaperDirs_[Constants.WallpaperDirNameEnum.THUMBNAIL] = null;
}
/**
* Gets WallpaperDirectories instance. In case is hasn't been initialized, a new
* instance is created.
* @return {WallpaperDirectories} A WallpaperDirectories instance.
*/
WallpaperDirectories.getInstance = function() {
if (wallpaperDirectories === null)
wallpaperDirectories = new WallpaperDirectories();
return wallpaperDirectories;
};
WallpaperDirectories.prototype = {
/**
* Returns all custom wallpaper related directory entries.
*/
get wallpaperDirs() {
return this.wallpaperDirs_;
},
/**
* If dirName is not requested, gets the directory entry of dirName and cache
* the result. Calls success callback if success.
* @param {string} dirName The directory name of requested directory entry.
* @param {function(DirectoryEntry):void} success Call success with requested
* DirectoryEntry.
* @param {function(e):void} failure Call failure when failed to get the
* requested directory.
*/
requestDir: function(dirName, success, failure) {
if (dirName != Constants.WallpaperDirNameEnum.ORIGINAL &&
dirName != Constants.WallpaperDirNameEnum.THUMBNAIL) {
console.error('Error: Unknow directory name.');
var e = new Error();
e.code = FileError.NOT_FOUND_ERR;
failure(e);
return;
}
var self = this;
window.webkitRequestFileSystem(
window.PERSISTENT, WallpaperQuota, function(fs) {
fs.root.getDirectory(dirName, {create: true}, function(dirEntry) {
self.wallpaperDirs_[dirName] = dirEntry;
success(dirEntry);
}, failure);
}, failure);
},
/**
* Gets DirectoryEntry associated with dirName from cache. If not in cache try
* to request it from FileSystem.
* @param {string} dirName The directory name of requested directory entry.
* @param {function(DirectoryEntry):void} success Call success with requested
* DirectoryEntry.
* @param {function(e):void} failure Call failure when failed to get the
* requested directory.
*/
getDirectory: function(dirName, success, failure) {
if (this.wallpaperDirs[dirName])
success(this.wallpaperDirs[dirName]);
else
this.requestDir(dirName, success, failure);
}
};
......@@ -8,7 +8,6 @@ cr.define('wallpapers', function() {
/** @const */ var GridItem = cr.ui.GridItem;
/** @const */ var GridSelectionController = cr.ui.GridSelectionController;
/** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel;
/** @const */ var ShowSpinnerDelayMs = 500;
/**
* The number of images that appear in the slideshow of the daily refresh
......@@ -105,16 +104,6 @@ cr.define('wallpapers', function() {
this.appendChild(imageEl);
switch (this.dataItem.source) {
case Constants.WallpaperSourceEnum.AddNew:
this.id = 'add-new';
this.addEventListener('click', function(e) {
if (!WallpaperUtil.getSurpriseMeCheckboxValue())
$('wallpaper-selection-container').hidden = false;
});
// Delay dispatching the completion callback until all items have
// begun loading and are tracked.
window.setTimeout(this.callback_.bind(this, this.dataModelId_), 0);
break;
case Constants.WallpaperSourceEnum.Custom:
this.decorateCustomWallpaper_(imageEl, this.dataItem);
break;
......@@ -283,12 +272,6 @@ cr.define('wallpapers', function() {
return this.checkmark_;
},
/**
* ID of spinner delay timer.
* @private
*/
spinnerTimeout_: 0,
/**
* The timer of the slideshow of the daily refresh item.
* @private
......@@ -399,9 +382,6 @@ cr.define('wallpapers', function() {
dataModel.splice(
0, 0, {isDailyRefreshItem: true, availableOffline: false});
}
} else {
// Sets dataModel to null should hide spinner immediately.
$('spinner-container').hidden = true;
}
var parentSetter = cr.ui.Grid.prototype.__lookupSetter__('dataModel');
......@@ -520,9 +500,6 @@ cr.define('wallpapers', function() {
if (this.pendingItems_ == 0) {
this.style.visibility = 'visible';
window.clearTimeout(this.spinnerTimeout_);
this.spinnerTimeout_ = 0;
$('spinner-container').hidden = true;
// Start the slideshow.
if (this.dailyRefreshItem) {
window.clearTimeout(this.dailyRefreshTimer_);
......@@ -604,17 +581,6 @@ cr.define('wallpapers', function() {
this.inProgramSelection_ = false;
},
/**
* Forces re-display, size re-calculation and focuses grid.
*/
updateAndFocus: function() {
// Recalculate the measured item size.
this.measured_ = null;
this.columns = 0;
this.redraw();
this.focus();
},
/**
* Shows a checkmark on the active thumbnail and clears previous active one
* if any. Note if wallpaper was not set successfully, checkmark should not
......
......@@ -43,7 +43,6 @@ found in the LICENSE file.
<script src="js/constants.js"></script>
<script src="js/util.js"></script>
<script src="js/progress_manager.js"></script>
<script src="js/wallpaper_directories.js"></script>
<script src="js/wallpaper_categories_list.js"></script>
<script src="js/wallpaper_images_grid.js"></script>
<script src="js/wallpaper_manager.js"></script>
......@@ -56,11 +55,6 @@ found in the LICENSE file.
shortcut="Delete"></command>
</commands>
<cr-menu id="wallpaper-context-menu" class="chrome-menu"
visibleif="custom surprise-me-disabled">
<cr-menu-item command="#delete"></cr-menu-item>
</cr-menu>
<div id="error-container" class="overlay-container" hidden>
<div class="page">
<div id="close-error" class="close"></div>
......@@ -134,7 +128,6 @@ found in the LICENSE file.
</div>
</div>
<grid id="wallpaper-grid" class="image-picker" tabIndex="-1"></grid>
<div id="spinner-container" hidden></div>
<div class="progress-bar" hidden>
<div class="progress-track"></div>
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment