Skip to content

Commit

Permalink
Bug 1744425 - Replace nsContentUtils::GenerateUUID() to nsID::Generat…
Browse files Browse the repository at this point in the history
…eUUID(). r=nika

Bug 1723674 added a new nsID::GenerateUUID() static factory function to generate UUIDs without the overhead of querying and instantiating an nsIUUIDGenerator object. nsContentUtils::GenerateUUID() is a utility function that amortizes that overhead by holding an nsIUUIDGenerator singleton. That's no longer necessary because code that calls nsContentUtils::GenerateUUID() can now just call nsID::GenerateUUID(). No nsIUUDGenerator is needed.

Differential Revision: https://phabricator.services.mozilla.com/D132866
  • Loading branch information
cpeterso committed Feb 3, 2022
1 parent fcd5026 commit 81801ff
Show file tree
Hide file tree
Showing 23 changed files with 31 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
nsILoadInfo::OPENER_POLICY_SAME_ORIGIN_ALLOW_POPUPS);
}

nsContentUtils::GenerateUUIDInPlace(fields.mHistoryID);
fields.mHistoryID = nsID::GenerateUUID();
fields.mExplicitActive = [&] {
if (parentBC) {
// Non-root browsing-contexts inherit their status from its parent.
Expand Down
3 changes: 1 addition & 2 deletions docshell/shistory/ChildSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ nsID ChildSHistory::AddPendingHistoryChange() {

nsID ChildSHistory::AddPendingHistoryChange(int32_t aIndexDelta,
int32_t aLengthDelta) {
nsID changeID = {};
nsContentUtils::GenerateUUIDInPlace(changeID);
nsID changeID = nsID::GenerateUUID();
PendingSHistoryChange change = {changeID, aIndexDelta, aLengthDelta};
mPendingSHistoryChanges.AppendElement(change);
return changeID;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/DocGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ DocGroup::DocGroup(BrowsingContextGroup* aBrowsingContextGroup,
const nsACString& aKey)
: mKey(aKey),
mBrowsingContextGroup(aBrowsingContextGroup),
mAgentClusterId(nsContentUtils::GenerateUUID()) {
mAgentClusterId(nsID::GenerateUUID()) {
// This method does not add itself to
// mBrowsingContextGroup->mDocGroups as the caller does it for us.
MOZ_ASSERT(NS_IsMainThread());
Expand Down
33 changes: 1 addition & 32 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@
#include "nsIContentSecurityPolicy.h"
#include "nsIContentSink.h"
#include "nsIContentViewer.h"
#include "nsID.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
Expand Down Expand Up @@ -326,7 +325,6 @@
#if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
# include "nsIURIWithSpecialOrigin.h"
#endif
#include "nsIUUIDGenerator.h"
#include "nsIUserIdleService.h"
#include "nsIWeakReferenceUtils.h"
#include "nsIWebNavigation.h"
Expand Down Expand Up @@ -415,7 +413,6 @@ nsIScriptSecurityManager* nsContentUtils::sSecurityManager;
nsIPrincipal* nsContentUtils::sSystemPrincipal;
nsIPrincipal* nsContentUtils::sNullSubjectPrincipal;
nsIIOService* nsContentUtils::sIOService;
nsIUUIDGenerator* nsContentUtils::sUUIDGenerator;
nsIConsoleService* nsContentUtils::sConsoleService;
nsTHashMap<nsRefPtrHashKey<nsAtom>, EventNameMapping>*
nsContentUtils::sAtomEventTable = nullptr;
Expand Down Expand Up @@ -795,13 +792,6 @@ nsresult nsContentUtils::Init() {

Unused << nsRFPService::GetOrCreate();

nsCOMPtr<nsIUUIDGenerator> uuidGenerator =
do_GetService("@mozilla.org/uuid-generator;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
uuidGenerator.forget(&sUUIDGenerator);

if (XRE_IsParentProcess()) {
AsyncPrecreateStringBundles();
}
Expand Down Expand Up @@ -1868,7 +1858,7 @@ void nsContentUtils::Shutdown() {
NS_IF_RELEASE(sSystemPrincipal);
NS_IF_RELEASE(sNullSubjectPrincipal);
NS_IF_RELEASE(sIOService);
NS_IF_RELEASE(sUUIDGenerator);

sBidiKeyboard = nullptr;

delete sAtomEventTable;
Expand Down Expand Up @@ -7349,27 +7339,6 @@ bool nsContentUtils::IsJavascriptMIMEType(const nsAString& aMIMEType) {
return false;
}

nsresult nsContentUtils::GenerateUUIDInPlace(nsID& aUUID) {
MOZ_ASSERT(sUUIDGenerator);

nsresult rv = sUUIDGenerator->GenerateUUIDInPlace(&aUUID);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

return NS_OK;
}

nsID nsContentUtils::GenerateUUID() {
MOZ_DIAGNOSTIC_ASSERT(sUUIDGenerator);

nsID uuid;
nsresult rv = sUUIDGenerator->GenerateUUIDInPlace(&uuid);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));

return uuid;
}

bool nsContentUtils::PrefetchPreloadEnabled(nsIDocShell* aDocShell) {
//
// SECURITY CHECK: disable prefetching and preloading from mailnews!
Expand Down
13 changes: 0 additions & 13 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "nsCOMPtr.h"
#include "nsHashtablesFwd.h"
#include "nsIContentPolicy.h"
#include "nsID.h"
#include "nsINode.h"
#include "nsIScriptError.h"
#include "nsIThread.h"
Expand Down Expand Up @@ -110,7 +109,6 @@ class nsIStringBundleService;
class nsISupports;
class nsITransferable;
class nsIURI;
class nsIUUIDGenerator;
class nsIWidget;
class nsIXPConnect;
class nsNodeInfoManager;
Expand Down Expand Up @@ -1270,16 +1268,6 @@ class nsContentUtils {
*/
static void SandboxFlagsToString(uint32_t aFlags, nsAString& aString);

/**
* Helper function that generates a UUID.
*/
static nsresult GenerateUUIDInPlace(nsID& aUUID);

/**
* Infallable (with an assertion) helper function that generates a UUID.
*/
static nsID GenerateUUID();

static bool PrefetchPreloadEnabled(nsIDocShell* aDocShell);

static void ExtractErrorValues(JSContext* aCx, JS::Handle<JS::Value> aValue,
Expand Down Expand Up @@ -3380,7 +3368,6 @@ class nsContentUtils {
static nsIPrincipal* sNullSubjectPrincipal;

static nsIIOService* sIOService;
static nsIUUIDGenerator* sUUIDGenerator;

static nsIConsoleService* sConsoleService;

Expand Down
3 changes: 1 addition & 2 deletions dom/broadcastchannel/BroadcastChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/StorageAccess.h"
#include "nsContentUtils.h"

#include "nsICookieJarSettings.h"
#include "mozilla/dom/Document.h"
Expand Down Expand Up @@ -149,7 +148,7 @@ already_AddRefed<BroadcastChannel> BroadcastChannel::Constructor(
}

nsID portUUID = {};
aRv = nsContentUtils::GenerateUUIDInPlace(portUUID);
aRv = nsID::GenerateUUIDInPlace(portUUID);
if (aRv.Failed()) {
return nullptr;
}
Expand Down
5 changes: 2 additions & 3 deletions dom/clients/manager/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/ClearOnShutdown.h" // PastShutdownPhase
#include "mozilla/StaticPrefs_dom.h"
#include "nsContentUtils.h"
#include "prthread.h"

namespace mozilla::dom {
Expand Down Expand Up @@ -106,7 +105,7 @@ UniquePtr<ClientSource> ClientManager::CreateSourceInternal(
NS_ASSERT_OWNINGTHREAD(ClientManager);

nsID id;
nsresult rv = nsContentUtils::GenerateUUIDInPlace(id);
nsresult rv = nsID::GenerateUUIDInPlace(id);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
if (NS_WARN_IF(NS_FAILED(rv))) {
// If we can't even get a UUID, at least make sure not to use a garbage
Expand Down Expand Up @@ -339,7 +338,7 @@ Maybe<ClientInfo> ClientManager::CreateInfo(ClientType aType,
}

nsID id;
rv = nsContentUtils::GenerateUUIDInPlace(id);
rv = nsID::GenerateUUIDInPlace(id);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
if (NS_WARN_IF(NS_FAILED(rv))) {
return Nothing();
Expand Down
2 changes: 1 addition & 1 deletion dom/fetch/FetchStreamUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ParentToParentStream ToParentToParentStream(
MOZ_ASSERT(XRE_IsParentProcess());

ParentToParentStream stream;
MOZ_ALWAYS_SUCCEEDS(nsContentUtils::GenerateUUIDInPlace(stream.uuid()));
stream.uuid() = nsID::GenerateUUID();
GetRemoteLazyInputStreamStorage()->AddStream(aStream.get(), stream.uuid(),
aStreamSize, 0);
return stream;
Expand Down
3 changes: 1 addition & 2 deletions dom/file/ipc/RemoteLazyInputStreamParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "RemoteLazyInputStreamParent.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "mozilla/InputStreamLengthHelper.h"
#include "nsContentUtils.h"
#include "RemoteLazyInputStreamStorage.h"

namespace mozilla {
Expand All @@ -22,7 +21,7 @@ RemoteLazyInputStreamParent::CreateCommon(nsIInputStream* aInputStream,
MOZ_ASSERT(aRv);

nsID id;
*aRv = nsContentUtils::GenerateUUIDInPlace(id);
*aRv = nsID::GenerateUUIDInPlace(id);
if (NS_WARN_IF(NS_FAILED(*aRv))) {
return nullptr;
}
Expand Down
3 changes: 1 addition & 2 deletions dom/filesystem/GetFilesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/ipc/IPCStreamUtils.h"
#include "FileSystemUtils.h"
#include "nsContentUtils.h"
#include "nsNetCID.h"
#include "nsProxyRelease.h"

Expand Down Expand Up @@ -448,7 +447,7 @@ void GetFilesHelperChild::Work(ErrorResult& aRv) {
return;
}

aRv = nsContentUtils::GenerateUUIDInPlace(mUUID);
aRv = nsID::GenerateUUIDInPlace(mUUID);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions dom/filesystem/compat/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "FileSystem.h"
#include "FileSystemRootDirectoryEntry.h"
#include "mozilla/dom/FileSystemBinding.h"
#include "nsContentUtils.h"
#include "nsIDUtils.h"

namespace mozilla::dom {
Expand All @@ -29,7 +28,7 @@ already_AddRefed<FileSystem> FileSystem::Create(nsIGlobalObject* aGlobalObject)
MOZ_ASSERT(aGlobalObject);

nsID id;
nsresult rv = nsContentUtils::GenerateUUIDInPlace(id);
nsresult rv = nsID::GenerateUUIDInPlace(id);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
Expand Down
3 changes: 1 addition & 2 deletions dom/ipc/RefMessageBodyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "mozilla/RefPtr.h"
#include "mozilla/dom/ipc/StructuredCloneData.h"
#include "nsBaseHashtable.h"
#include "nsContentUtils.h"
#include "nsDebug.h"

namespace mozilla::dom {
Expand Down Expand Up @@ -58,7 +57,7 @@ const nsID RefMessageBodyService::Register(
MOZ_ASSERT(body);

nsID uuid = {};
aRv = nsContentUtils::GenerateUUIDInPlace(uuid);
aRv = nsID::GenerateUUIDInPlace(uuid);
if (NS_WARN_IF(aRv.Failed())) {
return nsID();
}
Expand Down
3 changes: 1 addition & 2 deletions dom/media/webrtc/MediaEngineWebRTCAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "MediaTrackConstraints.h"
#include "mozilla/Assertions.h"
#include "mozilla/ErrorNames.h"
#include "nsContentUtils.h"
#include "nsIDUtils.h"
#include "transport/runnable_utils.h"
#include "Tracing.h"
Expand Down Expand Up @@ -1383,7 +1382,7 @@ nsString MediaEngineWebRTCAudioCaptureSource::GetUUID() {
nsCString asciiString;
ErrorResult rv;

rv = nsContentUtils::GenerateUUIDInPlace(uuid);
rv = nsID::GenerateUUIDInPlace(uuid);
if (rv.Failed()) {
return u""_ns;
}
Expand Down
5 changes: 2 additions & 3 deletions dom/messagechannel/MessageChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/Navigator.h"
#include "mozilla/dom/WorkerRunnable.h"
#include "nsContentUtils.h"
#include "mozilla/dom/Document.h"
#include "nsIGlobalObject.h"
#include "nsServiceManagerUtils.h"
Expand Down Expand Up @@ -50,13 +49,13 @@ already_AddRefed<MessageChannel> MessageChannel::Constructor(
MOZ_ASSERT(aGlobal);

nsID portUUID1;
aRv = nsContentUtils::GenerateUUIDInPlace(portUUID1);
aRv = nsID::GenerateUUIDInPlace(portUUID1);
if (aRv.Failed()) {
return nullptr;
}

nsID portUUID2;
aRv = nsContentUtils::GenerateUUIDInPlace(portUUID2);
aRv = nsID::GenerateUUIDInPlace(portUUID2);
if (aRv.Failed()) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/payments/PaymentRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ already_AddRefed<PaymentRequest> PaymentRequest::CreatePaymentRequest(
nsPIDOMWindowInner* aWindow, ErrorResult& aRv) {
// Generate a unique id for identification
nsID uuid;
if (NS_WARN_IF(NS_FAILED(nsContentUtils::GenerateUUIDInPlace(uuid)))) {
if (NS_WARN_IF(NS_FAILED(nsID::GenerateUUIDInPlace(uuid)))) {
aRv.ThrowAbortError(
"Failed to create an internal UUID for the PaymentRequest");
return nullptr;
Expand Down
3 changes: 1 addition & 2 deletions dom/serviceworkers/FetchEventOpProxyParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "mozilla/dom/FetchTypes.h"
#include "mozilla/dom/ServiceWorkerOpArgs.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsIInputStream.h"

#include "mozilla/Assertions.h"
Expand Down Expand Up @@ -50,7 +49,7 @@ nsresult MaybeDeserializeAndWrapForMainThread(
aSink = Some(ParentToParentStream());
auto& uuid = aSink->uuid();

MOZ_TRY(nsContentUtils::GenerateUUIDInPlace(uuid));
MOZ_TRY(nsID::GenerateUUIDInPlace(uuid));

auto storageOrErr = RemoteLazyInputStreamStorage::Get();

Expand Down
4 changes: 2 additions & 2 deletions dom/serviceworkers/ServiceWorkerPrivateImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ nsresult MaybeStoreStreamForBackgroundThread(nsIInterceptedChannel* aChannel,
Maybe<BodyStreamVariant>& body = aIPCRequest.body();
body.emplace(ParentToParentStream());

MOZ_TRY(nsContentUtils::GenerateUUIDInPlace(
body->get_ParentToParentStream().uuid()));
MOZ_TRY(
nsID::GenerateUUIDInPlace(body->get_ParentToParentStream().uuid()));

auto storageOrErr = RemoteLazyInputStreamStorage::Get();
if (NS_WARN_IF(storageOrErr.isErr())) {
Expand Down
3 changes: 1 addition & 2 deletions dom/serviceworkers/ServiceWorkerRegistrationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mozilla/dom/ServiceWorkerInfo.h"
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
#include "nsContentUtils.h"
#include "nsProxyRelease.h"
#include "nsTObserverArray.h"

Expand All @@ -39,7 +38,7 @@ class ServiceWorkerRegistrationInfo final
};
nsTArray<UniquePtr<VersionEntry>> mVersionList;

const nsID mAgentClusterId = nsContentUtils::GenerateUUID();
const nsID mAgentClusterId = nsID::GenerateUUID();

uint32_t mControlledClientsCounter;
uint32_t mDelayMultiplier;
Expand Down
6 changes: 3 additions & 3 deletions dom/workers/WorkerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ class CancelingRunnable final : public Runnable {
} /* anonymous namespace */

nsString ComputeWorkerPrivateId() {
nsID uuid = nsContentUtils::GenerateUUID();
nsID uuid = nsID::GenerateUUID();
return NSID_TrimBracketsUTF16(uuid);
}

Expand Down Expand Up @@ -2426,7 +2426,7 @@ WorkerPrivate::ComputeAgentClusterIdAndCoop(WorkerPrivate* aParent,
RefPtr<DocGroup> docGroup = doc->GetDocGroup();

nsID agentClusterId =
docGroup ? docGroup->AgentClusterId() : nsContentUtils::GenerateUUID();
docGroup ? docGroup->AgentClusterId() : nsID::GenerateUUID();

BrowsingContext* bc = aLoadInfo->mWindow->GetBrowsingContext();
MOZ_DIAGNOSTIC_ASSERT(bc);
Expand All @@ -2435,7 +2435,7 @@ WorkerPrivate::ComputeAgentClusterIdAndCoop(WorkerPrivate* aParent,

// If the window object was failed to be set into the WorkerLoadInfo, we
// make the worker into another agent cluster group instead of failures.
return {nsContentUtils::GenerateUUID(), agentClusterCoop};
return {nsID::GenerateUUID(), agentClusterCoop};
}

// static
Expand Down
Loading

0 comments on commit 81801ff

Please sign in to comment.