Bug 809056 - Reduce thumbnailing impact by capturing and storing only top sites. r=markh

This commit is contained in:
Drew Willcoxon 2014-01-07 12:59:18 -08:00
parent febcb823bb
commit 6b99010477
6 changed files with 37 additions and 6 deletions

View File

@ -4,6 +4,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#endif
Cu.import("resource://gre/modules/NewTabUtils.jsm");
/**
* Keeps thumbnails of open web pages up-to-date.
*/
@ -120,6 +122,11 @@ let gBrowserThumbnails = {
},
_shouldCapture: function Thumbnails_shouldCapture(aBrowser) {
// Capture only if it's a top site in about:newtab.
if (!NewTabUtils.links.getLinks().some(
(link) => link.url == aBrowser.currentURI.spec))
return false;
// Capture only if it's the currently selected tab.
if (aBrowser != gBrowser.selectedBrowser)
return false;

View File

@ -10,6 +10,7 @@ function runTests() {
let path = PageThumbs.getThumbnailPath(URL);
yield testIfExists(path, false, "Thumbnail file does not exist");
yield addVisitsAndRepopulateNewTabLinks(URL, next);
yield createThumbnail(URL);
path = PageThumbs.getThumbnailPath(URL);

View File

@ -36,6 +36,14 @@ function runTests() {
{scheme: "https", cacheControl: "private", diskCacheSSL: false}
];
let urls = positive.map((combi) => {
let url = combi.scheme + URL;
if (combi.cacheControl)
url += "?" + combi.cacheControl;
return url;
});
yield addVisitsAndRepopulateNewTabLinks(urls, next);
yield checkCombinations(positive, true);
yield checkCombinations(negative, false);
}

View File

@ -19,6 +19,7 @@ XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () {
*/
function runTests() {
yield clearHistory();
yield addVisitsAndRepopulateNewTabLinks(URL, next);
yield createThumbnail();
// Make sure Storage.copy() updates an existing file.
@ -39,6 +40,7 @@ function runTests() {
yield clearHistory();
}
yield addVisitsAndRepopulateNewTabLinks(URL, next);
yield createThumbnail();
// Clear the last 10 minutes of browsing history.

View File

@ -4,10 +4,11 @@
let tmp = {};
Cu.import("resource://gre/modules/PageThumbs.jsm", tmp);
Cu.import("resource://gre/modules/BackgroundPageThumbs.jsm", tmp);
Cu.import("resource://gre/modules/NewTabUtils.jsm", tmp);
Cu.import("resource:///modules/sessionstore/SessionStore.jsm", tmp);
Cu.import("resource://gre/modules/FileUtils.jsm", tmp);
Cu.import("resource://gre/modules/osfile.jsm", tmp);
let {PageThumbs, BackgroundPageThumbs, PageThumbsStorage, SessionStore, FileUtils, OS} = tmp;
let {PageThumbs, BackgroundPageThumbs, NewTabUtils, PageThumbsStorage, SessionStore, FileUtils, OS} = tmp;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
@ -199,11 +200,12 @@ function removeThumbnail(aURL) {
* Asynchronously adds visits to a page, invoking a callback function when done.
*
* @param aPlaceInfo
* Can be an nsIURI, in such a case a single LINK visit will be added.
* Otherwise can be an object describing the visit to add, or an array
* of these objects:
* One of the following: a string spec, an nsIURI, an object describing
* the Place as described below, or an array of any such types. An
* object describing a Place must look like this:
* { uri: nsIURI of the page,
* transition: one of the TRANSITION_* from nsINavHistoryService,
* [optional] transition: one of the TRANSITION_* from
* nsINavHistoryService,
* [optional] title: title of the page,
* [optional] visitDate: visit date in microseconds from the epoch
* [optional] referrer: nsIURI of the referrer for this visit
@ -225,6 +227,9 @@ function addVisits(aPlaceInfo, aCallback) {
// Create mozIVisitInfo for each entry.
let now = Date.now();
for (let i = 0; i < places.length; i++) {
if (typeof(places[i] == "string")) {
places[i] = { uri: Services.io.newURI(places[i], "", null) };
}
if (!places[i].title) {
places[i].title = "test visit for " + places[i].uri.spec;
}
@ -251,6 +256,14 @@ function addVisits(aPlaceInfo, aCallback) {
);
}
/**
* Calls addVisits, and then forces the newtab module to repopulate its links.
* See addVisits for parameter descriptions.
*/
function addVisitsAndRepopulateNewTabLinks(aPlaceInfo, aCallback) {
addVisits(aPlaceInfo, () => NewTabUtils.links.populateCache(aCallback, true));
}
/**
* Calls a given callback when the thumbnail for a given URL has been found
* on disk. Keeps trying until the thumbnail has been created.

View File

@ -621,7 +621,7 @@ let Links = {
let pinnedLinks = Array.slice(PinnedLinks.links);
// Filter blocked and pinned links.
let links = this._links.filter(function (link) {
let links = (this._links || []).filter(function (link) {
return !BlockedLinks.isBlocked(link) && !PinnedLinks.isPinned(link);
});