mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
608f3e7539
In this change we: - stop treating the nsPluginDirServiceProvider as a directory provider, as its GetFile implementation was a no-op anyway - registering it didn't make any difference. - stop treating it as a class entirely, because the PLID getters were already static, so instantiating it also didn't do anything. - move IO from the plugin directory list provider and the Windows-only PLID getters into nsPluginHost. This enables us to move it off of the main thread later - the directory getting has to happen on the main thread, but we can postpone further checks on the nsIFile instances. - in the process, stop doing exists() calls on files because we can fail more lazily. This allows us to remove more allowlist entries from browser_startup_mainthreadio, though the `isDirectory` calls will actually still cause IO - they don't seem to create IO markers in the profiler. We will move this IO away from the main thread in subsequent commits. Depends on D48328 Differential Revision: https://phabricator.services.mozilla.com/D48329 --HG-- extra : moz-landing-system : lando
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "nsPluginDirServiceProvider.h"
|
|
|
|
#include "nsCRT.h"
|
|
#include "nsIFile.h"
|
|
|
|
#include <windows.h>
|
|
#include "nsIWindowsRegKey.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
/* static */ nsresult GetPLIDDirectories(nsTArray<nsCOMPtr<nsIFile>>& aDirs) {
|
|
GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, aDirs);
|
|
GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
|
|
aDirs);
|
|
return NS_OK;
|
|
}
|
|
|
|
/* static */ nsresult GetPLIDDirectoriesWithRootKey(
|
|
uint32_t aKey, nsTArray<nsCOMPtr<nsIFile>>& aDirs) {
|
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
|
NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE);
|
|
|
|
nsresult rv =
|
|
regKey->Open(aKey, NS_LITERAL_STRING("Software\\MozillaPlugins"),
|
|
nsIWindowsRegKey::ACCESS_READ);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
uint32_t childCount = 0;
|
|
regKey->GetChildCount(&childCount);
|
|
|
|
for (uint32_t index = 0; index < childCount; ++index) {
|
|
nsAutoString childName;
|
|
rv = regKey->GetChildName(index, childName);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
nsCOMPtr<nsIWindowsRegKey> childKey;
|
|
rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
|
|
getter_AddRefs(childKey));
|
|
if (NS_SUCCEEDED(rv) && childKey) {
|
|
nsAutoString path;
|
|
rv = childKey->ReadStringValue(NS_LITERAL_STRING("Path"), path);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
// We deliberately do not do any further checks here on whether
|
|
// these are actually directories, whether they even exist, or
|
|
// whether they are duplicates. The pluginhost code will do them.
|
|
// This allows the whole process to avoid mainthread IO.
|
|
nsCOMPtr<nsIFile> localFile;
|
|
rv = NS_NewLocalFile(path, true, getter_AddRefs(localFile));
|
|
if (NS_SUCCEEDED(rv) && localFile) {
|
|
aDirs.AppendElement(localFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|