Skip to content

Commit

Permalink
Bug 1692880 - Make Put accept DataType instead of wrapping UserDataTy…
Browse files Browse the repository at this point in the history
…pe. r=xpcom-reviewers,necko-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D104850
  • Loading branch information
sigiesec committed Feb 16, 2021
1 parent 06738f2 commit 661e25b
Show file tree
Hide file tree
Showing 68 changed files with 299 additions and 343 deletions.
4 changes: 2 additions & 2 deletions chrome/nsChromeRegistryContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) {
if (NS_FAILED(rv)) return;
}

PackageEntry* entry = new PackageEntry;
UniquePtr<PackageEntry> entry = MakeUnique<PackageEntry>();
entry->flags = aPackage.flags;
entry->contentBaseURI = content;
entry->localeBaseURI = locale;
entry->skinBaseURI = skin;

mPackagesHash.Put(aPackage.package, entry);
mPackagesHash.Put(aPackage.package, std::move(entry));
}

void nsChromeRegistryContent::RegisterSubstitution(
Expand Down
4 changes: 2 additions & 2 deletions docshell/base/ChildProcessChannelListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void ChildProcessChannelListener::OnChannelReady(
aResolver(rv);
} else {
mChannelArgs.Put(aIdentifier,
{aLoadState, std::move(aStreamFilterEndpoints), aTiming,
std::move(aResolver)});
CallbackArgs{aLoadState, std::move(aStreamFilterEndpoints),
aTiming, std::move(aResolver)});
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ nsresult ExternalResourceMap::AddExternalResource(nsIURI* aURI,
}
}

ExternalResource* newResource = new ExternalResource();
mMap.Put(aURI, newResource);
ExternalResource* newResource =
mMap.Put(aURI, MakeUnique<ExternalResource>()).get();

newResource->mDocument = doc;
newResource->mViewer = aViewer;
Expand Down
8 changes: 4 additions & 4 deletions dom/events/PointerEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent,
// In this case we have to know information about available mouse pointers
sActivePointersIds->Put(
aEvent->pointerId,
new PointerInfo(false, aEvent->mInputSource, true, nullptr));
MakeUnique<PointerInfo>(false, aEvent->mInputSource, true, nullptr));

MaybeCacheSpoofedPointerID(aEvent->mInputSource, aEvent->pointerId);
break;
Expand All @@ -90,7 +90,7 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent,
// nullptr, not sure if this also happens on real usage.
sActivePointersIds->Put(
pointerEvent->pointerId,
new PointerInfo(
MakeUnique<PointerInfo>(
true, pointerEvent->mInputSource, pointerEvent->mIsPrimary,
aTargetContent ? aTargetContent->OwnerDoc() : nullptr));
MaybeCacheSpoofedPointerID(pointerEvent->mInputSource,
Expand All @@ -109,8 +109,8 @@ void PointerEventHandler::UpdateActivePointerState(WidgetMouseEvent* aEvent,
MouseEvent_Binding::MOZ_SOURCE_TOUCH) {
sActivePointersIds->Put(
pointerEvent->pointerId,
new PointerInfo(false, pointerEvent->mInputSource,
pointerEvent->mIsPrimary, nullptr));
MakeUnique<PointerInfo>(false, pointerEvent->mInputSource,
pointerEvent->mIsPrimary, nullptr));
} else {
sActivePointersIds->Remove(pointerEvent->pointerId);
}
Expand Down
4 changes: 2 additions & 2 deletions dom/file/ipc/RemoteLazyInputStreamStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ void RemoteLazyInputStreamStorage::AddStream(nsIInputStream* aInputStream,
uint64_t aChildID) {
MOZ_ASSERT(aInputStream);

StreamData* data = new StreamData();
UniquePtr<StreamData> data = MakeUnique<StreamData>();
data->mInputStream = aInputStream;
data->mChildID = aChildID;
data->mSize = aSize;

mozilla::StaticMutexAutoLock lock(gMutex);
mStorage.Put(aID, data);
mStorage.Put(aID, std::move(data));
}

nsCOMPtr<nsIInputStream> RemoteLazyInputStreamStorage::ForgetStream(
Expand Down
9 changes: 5 additions & 4 deletions dom/file/uri/BlobURLProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ static void AddDataEntryInternal(const nsACString& aURI, T aObject,
gDataTable = new nsClassHashtable<nsCStringHashKey, mozilla::dom::DataInfo>;
}

mozilla::dom::DataInfo* info =
new mozilla::dom::DataInfo(aObject, aPrincipal, aAgentClusterId);
BlobURLsReporter::GetJSStackForBlob(info);
mozilla::UniquePtr<mozilla::dom::DataInfo> info =
mozilla::MakeUnique<mozilla::dom::DataInfo>(aObject, aPrincipal,
aAgentClusterId);
BlobURLsReporter::GetJSStackForBlob(info.get());

gDataTable->Put(aURI, info);
gDataTable->Put(aURI, std::move(info));
}

void BlobURLProtocolHandler::Init(void) {
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ void HTMLFormElement::AddToPastNamesMap(const nsAString& aName,
// previous entry with the same name, if any.
nsCOMPtr<nsIContent> node = do_QueryInterface(aChild);
if (node) {
mPastNameLookupTable.Put(aName, node);
mPastNameLookupTable.Put(aName, ToSupports(node));
node->SetFlags(MAY_BE_IN_PAST_NAMES_MAP);
}
}
Expand Down
34 changes: 16 additions & 18 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7892,24 +7892,19 @@ uint64_t ConnectionPool::Start(
const bool databaseInfoIsNew = !dbInfo;

if (databaseInfoIsNew) {
dbInfo = new DatabaseInfo(this, aDatabaseId);

MutexAutoLock lock(mDatabasesMutex);

mDatabases.Put(aDatabaseId, dbInfo);
dbInfo =
mDatabases.Put(aDatabaseId, MakeUnique<DatabaseInfo>(this, aDatabaseId))
.get();
}

auto& transactionInfo = [&]() -> TransactionInfo& {
auto* transactionInfo = new TransactionInfo(
*dbInfo, aBackgroundChildLoggingId, aDatabaseId, transactionId,
aLoggingSerialNumber, aObjectStoreNames, aIsWriteTransaction,
aTransactionOp);

MOZ_ASSERT(!mTransactions.Get(transactionId));
mTransactions.Put(transactionId, transactionInfo);

return *transactionInfo;
}();
MOZ_ASSERT(!mTransactions.Contains(transactionId));
auto& transactionInfo = *mTransactions.Put(
transactionId, MakeUnique<TransactionInfo>(
*dbInfo, aBackgroundChildLoggingId, aDatabaseId,
transactionId, aLoggingSerialNumber, aObjectStoreNames,
aIsWriteTransaction, aTransactionOp));

if (aIsWriteTransaction) {
MOZ_ASSERT(dbInfo->mWriteTransactionCount < UINT32_MAX);
Expand Down Expand Up @@ -16781,10 +16776,13 @@ void OpenDatabaseOp::EnsureDatabaseActor() {
info->mLiveDatabases.AppendElement(
WrapNotNullUnchecked(mDatabase.unsafeGetRawPtr()));
} else {
info = new DatabaseActorInfo(
mMetadata.clonePtr(),
WrapNotNullUnchecked(mDatabase.unsafeGetRawPtr()));
gLiveDatabaseHashtable->Put(mDatabaseId, info);
// XXX Maybe use GetOrInsertWith above, to avoid a second lookup here?
info = gLiveDatabaseHashtable
->Put(mDatabaseId,
MakeUnique<DatabaseActorInfo>(
mMetadata.clonePtr(),
WrapNotNullUnchecked(mDatabase.unsafeGetRawPtr())))
.get();
}

// Balanced in Database::CleanupMetadata().
Expand Down
6 changes: 4 additions & 2 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,10 @@ mozilla::ipc::IPCResult BrowserChild::RecvRealMouseMoveEvent(
mToBeDispatchedMouseData.Push(dispatchData.release());

// Put new data to replace the old one in the hash table.
CoalescedMouseData* newData = new CoalescedMouseData();
mCoalescedMouseData.Put(aEvent.pointerId, newData);
CoalescedMouseData* newData =
mCoalescedMouseData
.Put(aEvent.pointerId, MakeUnique<CoalescedMouseData>())
.get();
newData->Coalesce(aEvent, aGuid, aInputBlockId);

// Dispatch all pending mouse events.
Expand Down
10 changes: 5 additions & 5 deletions dom/ipc/SharedMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ Result<Ok, nsresult> SharedMap::MaybeRebuild() {
// indicate memory corruption, and are fatal.
MOZ_RELEASE_ASSERT(!buffer.error());

// Note: Order of evaluation of function arguments is not guaranteed, so we
// can't use entry.release() in place of entry.get() without entry->Name()
// sometimes resulting in a null dereference.
mEntries.Put(entry->Name(), entry.get());
Unused << entry.release();
// Note: While the order of evaluation of the arguments to Put doesn't
// matter for this (the actual move will only happen within Put), to be
// clear about this, we call entry->Name() before calling Put.
const auto& name = entry->Name();
mEntries.Put(name, std::move(entry));
}

return Ok();
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/SharedStringMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool SharedStringMap::Find(const nsCString& aKey, size_t* aIndex) {

void SharedStringMapBuilder::Add(const nsCString& aKey,
const nsString& aValue) {
mEntries.Put(aKey, {mKeyTable.Add(aKey), mValueTable.Add(aValue)});
mEntries.Put(aKey, Entry{mKeyTable.Add(aKey), mValueTable.Add(aValue)});
}

Result<Ok, nsresult> SharedStringMapBuilder::Finalize(
Expand Down
11 changes: 4 additions & 7 deletions dom/localstorage/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7267,23 +7267,20 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) {

mDatastoreId = ++gLastDatastoreId;

auto preparedDatastore = MakeUnique<PreparedDatastore>(
mDatastore, mContentParentId, Origin(), mDatastoreId,
/* aForPreload */ mForPreload);

if (!gPreparedDatastores) {
gPreparedDatastores = new PreparedDatastoreHashtable();
}
gPreparedDatastores->Put(mDatastoreId, preparedDatastore.get());
const auto& preparedDatastore = gPreparedDatastores->Put(
mDatastoreId, MakeUnique<PreparedDatastore>(
mDatastore, mContentParentId, Origin(), mDatastoreId,
/* aForPreload */ mForPreload));

if (mInvalidated) {
preparedDatastore->Invalidate();
}

mPreparedDatastoreRegistered.Flip();

Unused << preparedDatastore.release();

if (mForPreload) {
LSRequestPreloadDatastoreResponse preloadDatastoreResponse;

Expand Down
2 changes: 1 addition & 1 deletion dom/media/gmp/GMPDiskStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class GMPDiskStorage : public GMPStorage {
continue;
}

mRecords.Put(recordName, new Record(filename, recordName));
mRecords.Put(recordName, MakeUnique<Record>(filename, recordName));
}

return NS_OK;
Expand Down
5 changes: 3 additions & 2 deletions dom/media/gmp/GMPUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ bool GMPInfoFileParser::Init(nsIFile* aInfoFile) {
ToLowerCase(key);
key.Trim(" ");

nsCString* value = new nsCString(Substring(line, colon + 1));
auto value = MakeUnique<nsCString>(Substring(line, colon + 1));
value->Trim(" ");
mValues.Put(key, value); // Hashtable assumes ownership of value.
mValues.Put(key,
std::move(value)); // Hashtable assumes ownership of value.
}

return true;
Expand Down
16 changes: 10 additions & 6 deletions dom/media/ogg/OggCodecState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ extern LazyLogModule gMediaDecoderLog;
using media::TimeUnit;

/** Decoder base class for Ogg-encapsulated streams. */
OggCodecState* OggCodecState::Create(rlbox_sandbox_ogg* aSandbox,
tainted_opaque_ogg<ogg_page*> aPage,
uint32_t aSerial) {
UniquePtr<OggCodecState> OggCodecState::Create(
rlbox_sandbox_ogg* aSandbox, tainted_opaque_ogg<ogg_page*> aPage,
uint32_t aSerial) {
NS_ASSERTION(sandbox_invoke(*aSandbox, ogg_page_bos, aPage)
.unverified_safe_because(RLBOX_SAFE_DEBUG_ASSERTION),
"Only call on BOS page!");
Expand Down Expand Up @@ -69,8 +69,12 @@ OggCodecState* OggCodecState::Create(rlbox_sandbox_ogg* aSandbox,
// Can't use MakeUnique here, OggCodecState is protected.
codecState.reset(new OggCodecState(aSandbox, aPage, aSerial, false));
}
return codecState->OggCodecState::InternalInit() ? codecState.release()
: nullptr;

if (!codecState->OggCodecState::InternalInit()) {
codecState.reset();
}

return codecState;
}

OggCodecState::OggCodecState(rlbox_sandbox_ogg* aSandbox,
Expand Down Expand Up @@ -1559,7 +1563,7 @@ bool SkeletonState::DecodeIndex(ogg_packet* aPacket) {

int32_t keyPointsRead = keyPoints->Length();
if (keyPointsRead > 0) {
mIndex.Put(serialno, keyPoints.release());
mIndex.Put(serialno, std::move(keyPoints));
}

LOG(LogLevel::Debug, ("Loaded %d keypoints for Skeleton on stream %u",
Expand Down
6 changes: 3 additions & 3 deletions dom/media/ogg/OggCodecState.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class OggCodecState {

// Factory for creating nsCodecStates. Use instead of constructor.
// aPage should be a beginning-of-stream page.
static OggCodecState* Create(rlbox_sandbox_ogg* aSandbox,
tainted_opaque_ogg<ogg_page*> aPage,
uint32_t aSerial);
static UniquePtr<OggCodecState> Create(rlbox_sandbox_ogg* aSandbox,
tainted_opaque_ogg<ogg_page*> aPage,
uint32_t aSerial);

virtual CodecType GetType() { return TYPE_UNKNOWN; }

Expand Down
5 changes: 3 additions & 2 deletions dom/media/ogg/OggCodecStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace mozilla {

OggCodecStore::OggCodecStore() : mMonitor("CodecStore") {}

void OggCodecStore::Add(uint32_t serial, OggCodecState* codecState) {
OggCodecState* OggCodecStore::Add(uint32_t serial,
UniquePtr<OggCodecState> codecState) {
MonitorAutoLock mon(mMonitor);
mCodecStates.Put(serial, codecState);
return mCodecStates.Put(serial, std::move(codecState)).get();
}

bool OggCodecStore::Contains(uint32_t serial) {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ogg/OggCodecStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace mozilla {
class OggCodecStore {
public:
OggCodecStore();
void Add(uint32_t serial, OggCodecState* codecState);
OggCodecState* Add(uint32_t serial, UniquePtr<OggCodecState> codecState);
bool Contains(uint32_t serial);
OggCodecState* Get(uint32_t serial);
bool IsKnownStream(uint32_t aSerial);
Expand Down
8 changes: 4 additions & 4 deletions dom/media/ogg/OggDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ nsresult OggDemuxer::ReadMetadata() {
// We've not encountered a stream with this serial number before. Create
// an OggCodecState to demux it, and map that to the OggCodecState
// in mCodecStates.
OggCodecState* codecState =
OggCodecState::Create(mSandbox.get(), page.to_opaque(), serial);
mCodecStore.Add(serial, codecState);
OggCodecState* const codecState = mCodecStore.Add(
serial,
OggCodecState::Create(mSandbox.get(), page.to_opaque(), serial));
bitstreams.AppendElement(codecState);
serials.AppendElement(serial);
}
Expand Down Expand Up @@ -685,7 +685,7 @@ bool OggDemuxer::ReadOggChain(const media::TimeUnit& aLastEndTime) {

OggCodecState* state;

mCodecStore.Add(serial, codecState.release());
mCodecStore.Add(serial, std::move(codecState));
state = mCodecStore.Get(serial);

NS_ENSURE_TRUE(state != nullptr, false);
Expand Down
2 changes: 1 addition & 1 deletion dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class EMEDecryptor : public MediaDataDecoder,
return;
}

mDecrypts.Put(aSample, new DecryptPromiseRequestHolder());
mDecrypts.Put(aSample, MakeUnique<DecryptPromiseRequestHolder>());
mProxy->Decrypt(aSample)
->Then(mThread, __func__, this, &EMEDecryptor::Decrypted,
&EMEDecryptor::Decrypted)
Expand Down
5 changes: 2 additions & 3 deletions dom/media/systemservices/MediaParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class OriginKeyStore : public nsISupports {
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
key = new OriginKey(salt);
mKeys.Put(principalString, key);
key = mKeys.Put(principalString, MakeUnique<OriginKey>(salt)).get();
}
if (aPersist && !key->mSecondsStamp) {
key->mSecondsStamp = PR_Now() / PR_USEC_PER_SEC;
Expand Down Expand Up @@ -259,7 +258,7 @@ class OriginKeyStore : public nsISupports {
if (NS_FAILED(rv)) {
continue;
}
mKeys.Put(origin, new OriginKey(key, secondsstamp));
mKeys.Put(origin, MakeUnique<OriginKey>(key, secondsstamp));
}
mPersistCount = mKeys.Count();
return NS_OK;
Expand Down
10 changes: 6 additions & 4 deletions dom/messagechannel/MessagePortService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ bool MessagePortService::RequestEntangling(MessagePortParent* aParent,
return false;
}

data = new MessagePortServiceData(aParent->ID());
mPorts.Put(aDestinationUUID, data);
mPorts.Put(aDestinationUUID,
MakeUnique<MessagePortServiceData>(aParent->ID()));

data = new MessagePortServiceData(aDestinationUUID);
mPorts.Put(aParent->ID(), data);
data = mPorts
.Put(aParent->ID(),
MakeUnique<MessagePortServiceData>(aDestinationUUID))
.get();
}

// This is a security check.
Expand Down
3 changes: 2 additions & 1 deletion dom/plugins/ipc/PluginInstanceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,8 @@ void PluginInstanceParent::SubclassPluginWindow(HWND aWnd) {
mPluginWndProc = nullptr;
// Note sPluginInstanceList wil delete 'this' if we do not remove
// it on shutdown.
sPluginInstanceList->Put((void*)mPluginHWND, this);
sPluginInstanceList->Put((void*)mPluginHWND,
UniquePtr<PluginInstanceParent>(this));
return;
}

Expand Down
Loading

0 comments on commit 661e25b

Please sign in to comment.