зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1705726 - Create an interface to determine if the maintenance service registry entry exists r=nalexander
Creates nsIUpdateProcessor.serviceRegKeyExists(), which checks for existence the registry key written by the installer that indicates that the current installation can use the Maintenance Service. The nsIUpdateProcessor interface was chosen because that is the one Update-related xpcom component that is implemented in C++. By implementing this in C++, we can use the existing implementation of CalculateRegistryPathFromFilePath() to do most of the work for us. Unfortunately, we can't really test this feature without being able to write to HKEY_LOCAL_MACHINE, which we have no good way of doing during testing. Differential Revision: https://phabricator.services.mozilla.com/D114803
This commit is contained in:
Родитель
27722db2f1
Коммит
b7b545db73
|
@ -483,6 +483,21 @@ interface nsIUpdateProcessor : nsISupports
|
|||
* the permissions.
|
||||
*/
|
||||
void fixUpdateDirectoryPerms(in boolean useServiceOnFailure);
|
||||
|
||||
/**
|
||||
* The installer writes an installation-specific registry key if the
|
||||
* Maintenance Service can be used for this installation. This function checks
|
||||
* for that key's existence (it does not read or verify the key's contents).
|
||||
*
|
||||
* This function should only be called on Windows.
|
||||
*
|
||||
* @returns true if the registry key exists, false if it does not.
|
||||
* @throws NS_ERROR_NOT_AVAILABLE
|
||||
* If registry access fails.
|
||||
* @throws NS_ERROR_NOT_IMPLEMENTED
|
||||
* If this is called on a non-Windows platform.
|
||||
*/
|
||||
bool getServiceRegKeyExists();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -133,6 +133,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android":
|
|||
|
||||
UNIFIED_SOURCES += [
|
||||
"/toolkit/mozapps/update/common/commonupdatedir.cpp",
|
||||
"/toolkit/mozapps/update/common/pathhash.cpp",
|
||||
"AutoSQLiteLifetime.cpp",
|
||||
"Bootstrap.cpp",
|
||||
"CmdLineAndEnvUtils.cpp",
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
# include <strsafe.h>
|
||||
# include "commonupdatedir.h"
|
||||
# include "nsWindowsHelpers.h"
|
||||
# include "pathhash.h"
|
||||
# define getcwd(path, size) _getcwd(path, size)
|
||||
# define getpid() GetCurrentProcessId()
|
||||
#elif defined(XP_UNIX)
|
||||
|
@ -1077,3 +1078,47 @@ void nsUpdateProcessor::UpdateDone() {
|
|||
|
||||
ShutdownWatcherThread();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUpdateProcessor::GetServiceRegKeyExists(bool* aResult) {
|
||||
#ifndef XP_WIN
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#else // #ifdef XP_WIN
|
||||
nsCOMPtr<nsIProperties> dirSvc(
|
||||
do_GetService("@mozilla.org/file/directory_service;1"));
|
||||
NS_ENSURE_TRUE(dirSvc, NS_ERROR_SERVICE_NOT_AVAILABLE);
|
||||
|
||||
nsCOMPtr<nsIFile> installBin;
|
||||
nsresult rv = dirSvc->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
|
||||
getter_AddRefs(installBin));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> installDir;
|
||||
rv = installBin->GetParent(getter_AddRefs(installDir));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString installPath;
|
||||
rv = installDir->GetPath(installPath);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
wchar_t maintenanceServiceKey[MAX_PATH + 1];
|
||||
BOOL success = CalculateRegistryPathFromFilePath(
|
||||
PromiseFlatString(installPath).get(), maintenanceServiceKey);
|
||||
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
||||
|
||||
HKEY regHandle;
|
||||
LSTATUS ls = RegOpenKeyExW(HKEY_LOCAL_MACHINE, maintenanceServiceKey, 0,
|
||||
KEY_QUERY_VALUE | KEY_WOW64_64KEY, ®Handle);
|
||||
if (ls == ERROR_SUCCESS) {
|
||||
RegCloseKey(regHandle);
|
||||
*aResult = true;
|
||||
return NS_OK;
|
||||
}
|
||||
if (ls == ERROR_FILE_NOT_FOUND) {
|
||||
*aResult = false;
|
||||
return NS_OK;
|
||||
}
|
||||
// We got an error we weren't expecting reading the registry.
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
#endif // #ifdef XP_WIN
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче