Bug 784558. [Page Thumbnails] Re-add removeFile function to allow single thumbnail removal, used when removing entries from the history. r=felipe

This commit is contained in:
Tim Taubert 2012-08-24 18:11:06 -07:00
parent 52c4b843a1
commit b43b2b7eb8
3 changed files with 58 additions and 27 deletions

View File

@ -19,6 +19,9 @@ let PageThumbsWorker = {
let data = {result: null, data: null};
switch (msg.type) {
case "removeFile":
data.result = this.removeFile(msg);
break;
case "removeFiles":
data.result = this.removeFiles(msg);
break;
@ -48,6 +51,15 @@ let PageThumbsWorker = {
return entries;
},
removeFile: function Worker_removeFile(msg) {
try {
OS.File.remove(msg.path);
return true;
} catch (e) {
return false;
}
},
removeFiles: function Worker_removeFiles(msg) {
for (let file of msg.paths) {
try {

View File

@ -19,21 +19,9 @@ XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () {
*/
function runTests() {
yield clearHistory();
yield createThumbnail();
// create a thumbnail
yield addTab(URL);
yield whenFileExists();
gBrowser.removeTab(gBrowser.selectedTab);
// clear all browser history
yield clearHistory();
// create a thumbnail
yield addTab(URL);
yield whenFileExists();
gBrowser.removeTab(gBrowser.selectedTab);
// make sure copy() updates an existing file
// Make sure Storage.copy() updates an existing file.
PageThumbsStorage.copy(URL, URL_COPY);
let copy = PageThumbsStorage.getFileForURL(URL_COPY);
let mtime = copy.lastModifiedTime -= 60;
@ -42,9 +30,31 @@ function runTests() {
isnot(PageThumbsStorage.getFileForURL(URL_COPY).lastModifiedTime, mtime,
"thumbnail file was updated");
// clear last 10 mins of history
let file = PageThumbsStorage.getFileForURL(URL);
let fileCopy = PageThumbsStorage.getFileForURL(URL_COPY);
// Clear the browser history. Retry until the files are gone because Windows
// locks them sometimes.
while (file.exists() || fileCopy.exists()) {
yield clearHistory();
}
yield createThumbnail();
// Clear the last 10 minutes of browsing history.
yield clearHistory(true);
ok(!copy.exists(), "copy of thumbnail has been removed");
// Retry until the file is gone because Windows locks it sometimes.
while (file.exists()) {
// Re-add our URL to the history so that history observer's onDeleteURI()
// is called again.
let time = Date.now() * 1000;
let trans = Ci.nsINavHistoryService.TRANSITION_LINK;
PlacesUtils.history.addVisit(makeURI(URL), time, null, trans, false, 0);
// Try again...
yield clearHistory(true);
}
}
function clearHistory(aUseRange) {
@ -65,25 +75,33 @@ function clearHistory(aUseRange) {
if (aUseRange) {
let usec = Date.now() * 1000;
s.range = [usec - 10 * 60 * 1000 * 1000, usec];
s.ignoreTimespan = false;
}
s.sanitize();
s.range = null;
s.ignoreTimespan = true;
executeSoon(function () {
if (PageThumbsStorage.getFileForURL(URL).exists())
clearHistory(aUseRange);
else
executeSoon(next);
}
function createThumbnail() {
addTab(URL, function () {
whenFileExists(function () {
gBrowser.removeTab(gBrowser.selectedTab);
next();
});
});
}
function whenFileExists() {
let callback = whenFileExists;
function whenFileExists(aCallback) {
let callback;
let file = PageThumbsStorage.getFileForURL(URL);
if (file.exists() && file.fileSize)
callback = next;
if (file.exists() && file.fileSize) {
callback = aCallback;
} else {
callback = function () whenFileExists(aCallback);
}
executeSoon(callback);
}

View File

@ -57,10 +57,11 @@ function next() {
/**
* Creates a new tab with the given URI.
* @param aURI The URI that's loaded in the tab.
* @param aCallback The function to call when the tab has loaded.
*/
function addTab(aURI) {
function addTab(aURI, aCallback) {
let tab = gBrowser.selectedTab = gBrowser.addTab(aURI);
whenLoaded(tab.linkedBrowser);
whenLoaded(tab.linkedBrowser, aCallback);
}
/**