Bug 758463 - Windows XP does not clear prefetch on updates. r=jimm
authorBrian R. Bondy <netzen@gmail.com>
Fri, 15 Jun 2012 10:37:55 -0400
changeset 96813 5ebf62ac2dc4b875f4c8252b0a9cbd59206d4256
parent 96812 7abd9543e31e88591d42998de38e3f9da9c8b00a
child 96814 dd3791f6709c75a9b93a1e28f8fc04b3f562ab60
push id10724
push userbbondy@mozilla.com
push dateFri, 15 Jun 2012 14:39:33 +0000
treeherdermozilla-inbound@5ebf62ac2dc4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs758463
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 758463 - Windows XP does not clear prefetch on updates. r=jimm
browser/components/shell/src/Makefile.in
browser/components/shell/src/nsWindowsShellService.cpp
toolkit/components/maintenanceservice/maintenanceservice.cpp
--- a/browser/components/shell/src/Makefile.in
+++ b/browser/components/shell/src/Makefile.in
@@ -30,14 +30,15 @@ endif
 ifdef CPPSRCS
 LIBRARY_NAME = shellservice_s
 endif
 
 EXTRA_COMPONENTS = nsSetDefaultBrowser.js nsSetDefaultBrowser.manifest
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\"
+DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\" \
+  -DMOZ_APP_VERSION=\"$(MOZ_APP_VERSION)\"
 
 CXXFLAGS += $(TK_CFLAGS)
 
 clobber::
 	rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
--- a/browser/components/shell/src/nsWindowsShellService.cpp
+++ b/browser/components/shell/src/nsWindowsShellService.cpp
@@ -196,17 +196,18 @@ static SETTING gDDESettings[] = {
 };
 
 #if defined(MOZ_MAINTENANCE_SERVICE)
 
 #define ONLY_SERVICE_LAUNCHING
 #include "updatehelper.h"
 #include "updatehelper.cpp"
 
-static const char kPrefetchClearedPref[] = "app.update.service.prefetchCleared";
+static const char *kPrefetchClearedPref =
+  "app.update.service.lastVersionPrefetchCleared";
 static nsCOMPtr<nsIThread> sThread;
 #endif
 
 nsresult
 GetHelperPath(nsAutoString& aPath)
 {
   nsresult rv;
   nsCOMPtr<nsIProperties> directoryService = 
@@ -1011,27 +1012,30 @@ nsWindowsShellService::nsWindowsShellSer
                              nsIWindowsRegKey::WOW64_64)) ||
       NS_FAILED(regKey->ReadIntValue(NS_LITERAL_STRING("Installed"), 
                 &installed)) ||
       !installed) {
     return;
   }
 
   // check to see if we have attempted to do the one time operation of clearing
-  // the prefetch.
-  bool prefetchCleared;
+  // the prefetch.  We do it once per version upgrade.
+  nsCString lastClearedVer;
   nsCOMPtr<nsIPrefBranch> prefBranch;
   nsCOMPtr<nsIPrefService> prefs =
     do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (!prefs || 
       NS_FAILED(prefs->GetBranch(nsnull, getter_AddRefs(prefBranch))) ||
-      (NS_SUCCEEDED(prefBranch->GetBoolPref(kPrefetchClearedPref, 
-                                            &prefetchCleared)) &&
-       prefetchCleared)) {
-    return;
+      (NS_SUCCEEDED(prefBranch->GetCharPref(kPrefetchClearedPref, 
+                                            getter_Copies(lastClearedVer))))) {
+    // If the versions are the same, then bail out early.  We only want to clear
+    // once per version.
+    if (!strcmp(MOZ_APP_VERSION, lastClearedVer.get())) {
+      return;
+    }
   }
 
   // In a minute after startup is definitely complete, launch the
   // service command.
   mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
   if (mTimer) {
     mTimer->InitWithFuncCallback(
       nsWindowsShellService::LaunchPrefetchClearCommand, 
@@ -1092,17 +1096,17 @@ nsWindowsShellService::LaunchPrefetchCle
 {
   // Make sure we don't call this again from the application, it will be
   // called on each application update instead.
   nsCOMPtr<nsIPrefBranch> prefBranch;
   nsCOMPtr<nsIPrefService> prefs =
     do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (prefs) {
     if (NS_SUCCEEDED(prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)))) {
-      prefBranch->SetBoolPref(kPrefetchClearedPref, true);
+      prefBranch->SetCharPref(kPrefetchClearedPref, MOZ_APP_VERSION);
     }
   }
 
   // Starting the sevice can take a bit of time and we don't want to block the 
   // main thread, so start an event on another thread to handle the operation
   NS_NewThread(getter_AddRefs(sThread));
   if (sThread) {
     nsCOMPtr<nsIRunnable> prefetchEvent = new ClearPrefetchEvent();
--- a/toolkit/components/maintenanceservice/maintenanceservice.cpp
+++ b/toolkit/components/maintenanceservice/maintenanceservice.cpp
@@ -22,28 +22,16 @@ HANDLE gWorkDoneEvent = NULL;
 HANDLE gThread = NULL;
 bool gServiceControlStopping = false;
 
 // logs are pretty small, about 20 lines, so 10 seems reasonable.
 #define LOGS_TO_KEEP 10
 
 BOOL GetLogDirectoryPath(WCHAR *path);
 
-/**
- * Wraps all commands that should be executed by the service on each install
- * and upgrade.
-*/
-void
-RunCommandsForEachUpgrade()
-{
-  LOG(("Running install/upgrade commands...\n"));
-  ClearKnownPrefetch();
-  LOG(("Finished install/upgrade commands\n"));
-}
-
 int 
 wmain(int argc, WCHAR **argv)
 {
   // If command-line parameter is "install", install the service
   // or upgrade if already installed
   // If command line parameter is "forceinstall", install the service
   // even if it is older than what is already installed.
   // If command-line parameter is "upgrade", upgrade the service
@@ -79,19 +67,18 @@ wmain(int argc, WCHAR **argv)
 
   if (!lstrcmpi(argv[1], L"upgrade")) {
     WCHAR updatePath[MAX_PATH + 1];
     if (GetLogDirectoryPath(updatePath)) {
       LogInit(updatePath, L"maintenanceservice-install.log");
     }
     LOG(("Upgrading service if installed...\n"));
 
-    bool ret = SvcInstall(UpgradeSvc);
-    RunCommandsForEachUpgrade();
-    if (!ret) {
+    
+    if (!SvcInstall(UpgradeSvc)) {
       LOG(("Could not upgrade service (%d)\n", GetLastError()));
       LogFinish();
       return 1;
     }
 
     LOG(("The service was upgraded successfully\n"));
     LogFinish();
     return 0;