Bug 727864 - Enable DLL preloading when MozillaMaintenance service disabled prefetch. r=jimm

This commit is contained in:
Brian R. Bondy 2012-05-27 22:40:48 -04:00
Родитель 4ae600a9d9
Коммит 9e83f5bc8b
2 изменённых файлов: 71 добавлений и 1 удалений

Просмотреть файл

@ -157,6 +157,38 @@ static int do_main(int argc, char* argv[])
return XRE_main(argc, argv, &sAppData, 0);
}
#ifdef XP_WIN
/**
* Determines if the registry is disabled via the service or not.
*
* @return true if prefetch is disabled
* false if prefetch is not disabled or an error occurred.
*/
bool IsPrefetchDisabledViaService()
{
// We don't need to return false when we don't have MOZ_MAINTENANCE_SERVICE
// defined. The reason is because another product installed that has it
// defined may have cleared our prefetch for us. There is no known way
// to figure out which prefetch files are associated with which apps
// because of the prefetch hash. So we disable all of them that start
// with FIREFOX.
HKEY baseKey;
LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Mozilla\\MaintenanceService", 0,
KEY_READ | KEY_WOW64_64KEY, &baseKey);
if (retCode != ERROR_SUCCESS) {
return false;
}
DWORD disabledValue = 0;
DWORD disabledValueSize = sizeof(DWORD);
RegQueryValueExW(baseKey, L"FFPrefetchDisabled", 0, NULL,
reinterpret_cast<LPBYTE>(&disabledValue),
&disabledValueSize);
RegCloseKey(baseKey);
return disabledValue == 1;
}
#endif
int main(int argc, char* argv[])
{
char exePath[MAXPATHLEN];
@ -187,9 +219,13 @@ int main(int argc, char* argv[])
// in the program. Luckily 1 coincides with when prefetch is
// enabled. If Windows prefetch didn't happen we can do our own
// faster dll preloading.
// The MozillaMaintenance service issues a command to disable the
// prefetch by replacing all found .pf files with 0 byte read only
// files.
IO_COUNTERS ioCounters;
gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters);
if (gotCounters && !ioCounters.ReadOperationCount)
if ((gotCounters && !ioCounters.ReadOperationCount) ||
IsPrefetchDisabledViaService())
#endif
{
XPCOMGlueEnablePreload();

Просмотреть файл

@ -41,6 +41,35 @@
#include "nsWindowsHelpers.h"
#define MAX_KEY_LENGTH 255
/**
* Writes a registry DWORD with a value of 1 at BASE_SERVICE_REG_KEY
* if the prefetch was cleared successfully.
*
* @return TRUE if successful.
*/
BOOL
WritePrefetchClearedReg()
{
HKEY baseKeyRaw;
LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
BASE_SERVICE_REG_KEY, 0,
KEY_WRITE | KEY_WOW64_64KEY, &baseKeyRaw);
if (retCode != ERROR_SUCCESS) {
LOG(("Could not open key for prefetch. (%d)\n", retCode));
return FALSE;
}
nsAutoRegKey baseKey(baseKeyRaw);
DWORD disabledValue = 1;
if (RegSetValueExW(baseKey, L"FFPrefetchDisabled", 0, REG_DWORD,
reinterpret_cast<LPBYTE>(&disabledValue),
sizeof(disabledValue)) != ERROR_SUCCESS) {
LOG(("Could not write prefetch cleared value to registry. (%d)\n",
GetLastError()));
return FALSE;
}
return TRUE;
}
/**
* We found that prefetch actually causes large applications like Firefox
* to startup slower. This will get rid of the Windows prefetch files for
@ -179,6 +208,11 @@ ClearPrefetch(LPCWSTR prefetchProcessName)
// Cleanup after ourselves.
FindClose(findHandle);
if (deletedAllFFPrefetch) {
WritePrefetchClearedReg();
}
return deletedAllFFPrefetch;
}