Bug 784558 - [Page Thumbnails] single thumbnail removal doesn't work anymore when the corresponding site is removed from history; r=felipe
☠☠ backed out by fd6973289931 ☠ ☠
authorTim Taubert <ttaubert@mozilla.com>
Wed, 22 Aug 2012 10:02:28 -0700
changeset 105045 5fb14f57f34ac0ded126cb7e53454cf4c01654d3
parent 105044 e1cdfebb423df4287eac249fc9b36d355505cb56
child 105046 fd69732899315d872e2d4a2a733110bbf498bd03
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersfelipe
bugs784558
milestone17.0a1
Bug 784558 - [Page Thumbnails] single thumbnail removal doesn't work anymore when the corresponding site is removed from history; r=felipe
browser/components/thumbnails/PageThumbsWorker.js
browser/components/thumbnails/test/browser_thumbnails_storage.js
--- a/browser/components/thumbnails/PageThumbsWorker.js
+++ b/browser/components/thumbnails/PageThumbsWorker.js
@@ -14,16 +14,19 @@
 importScripts("resource://gre/modules/osfile.jsm");
 
 let PageThumbsWorker = {
   handleMessage: function Worker_handleMessage(aEvent) {
     let msg = aEvent.data;
     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;
       case "getFilesInDirectory":
         data.result = this.getFilesInDirectory(msg);
         break;
       default:
         data.result = false;
@@ -43,16 +46,25 @@ let PageThumbsWorker = {
         entries.push(entry.name);
       }
     }
 
     iter.close();
     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 {
         OS.File.remove(file);
       } catch (e) {
         // We couldn't remove the file for some reason.
         // Let's just continue with the next one.
       }
--- a/browser/components/thumbnails/test/browser_thumbnails_storage.js
+++ b/browser/components/thumbnails/test/browser_thumbnails_storage.js
@@ -39,17 +39,17 @@ function runTests() {
   let mtime = copy.lastModifiedTime -= 60;
 
   PageThumbsStorage.copy(URL, URL_COPY);
   isnot(PageThumbsStorage.getFileForURL(URL_COPY).lastModifiedTime, mtime,
         "thumbnail file was updated");
 
   // clear last 10 mins of history
   yield clearHistory(true);
-  ok(!copy.exists(), "copy of thumbnail has been removed");
+  yield whenFileRemoved();
 }
 
 function clearHistory(aUseRange) {
   let s = new Sanitizer();
   s.prefDomain = "privacy.cpd.";
 
   let prefs = gPrefService.getBranch(s.prefDomain);
   prefs.setBoolPref("history", true);
@@ -60,20 +60,22 @@ function clearHistory(aUseRange) {
   prefs.setBoolPref("offlineApps", false);
   prefs.setBoolPref("passwords", false);
   prefs.setBoolPref("sessions", false);
   prefs.setBoolPref("siteSettings", false);
 
   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
       next();
   });
 }
@@ -82,8 +84,18 @@ function whenFileExists() {
   let callback = whenFileExists;
 
   let file = PageThumbsStorage.getFileForURL(URL);
   if (file.exists() && file.fileSize)
     callback = next;
 
   executeSoon(callback);
 }
+
+function whenFileRemoved() {
+  let callback = whenFileRemoved;
+
+  let file = PageThumbsStorage.getFileForURL(URL);
+  if (!file.exists())
+    callback = next;
+
+  executeSoon(callback);
+}