mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1251715 - use UniquePtr instead of ScopedDeletePtr in dom/media/; r=gerald
UniquePtr is more standard than ScopedDeletePtr; using standard constructs whenever possible is preferable.
This commit is contained in:
parent
119e7f4cad
commit
710083b54a
@ -1103,7 +1103,7 @@ static auto& MediaManager_AnonymizeDevices = MediaManager::AnonymizeDevices;
|
||||
already_AddRefed<MediaManager::PledgeChar>
|
||||
MediaManager::SelectSettings(
|
||||
MediaStreamConstraints& aConstraints,
|
||||
RefPtr<Refcountable<ScopedDeletePtr<SourceSet>>>& aSources)
|
||||
RefPtr<Refcountable<UniquePtr<SourceSet>>>& aSources)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
RefPtr<PledgeChar> p = new PledgeChar();
|
||||
@ -1414,7 +1414,7 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
|
||||
realBackend = manager->GetBackend(aWindowId);
|
||||
}
|
||||
|
||||
ScopedDeletePtr<SourceSet> result(new SourceSet);
|
||||
auto result = MakeUnique<SourceSet>();
|
||||
|
||||
if (hasVideo) {
|
||||
nsTArray<RefPtr<VideoDevice>> videos;
|
||||
@ -1432,16 +1432,16 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId,
|
||||
result->AppendElement(source);
|
||||
}
|
||||
}
|
||||
SourceSet* handoff = result.forget();
|
||||
SourceSet* handoff = result.release();
|
||||
NS_DispatchToMainThread(do_AddRef(NewRunnableFrom([id, handoff]() mutable {
|
||||
ScopedDeletePtr<SourceSet> result(handoff); // grab result
|
||||
UniquePtr<SourceSet> result(handoff); // grab result
|
||||
RefPtr<MediaManager> mgr = MediaManager_GetInstance();
|
||||
if (!mgr) {
|
||||
return NS_OK;
|
||||
}
|
||||
RefPtr<PledgeSourceSet> p = mgr->mOutstandingPledges.Remove(id);
|
||||
if (p) {
|
||||
p->Resolve(result.forget());
|
||||
p->Resolve(result.release());
|
||||
}
|
||||
return NS_OK;
|
||||
})));
|
||||
@ -1609,9 +1609,9 @@ media::Parent<media::NonE10s>*
|
||||
MediaManager::GetNonE10sParent()
|
||||
{
|
||||
if (!mNonE10sParent) {
|
||||
mNonE10sParent = new media::Parent<media::NonE10s>(true);
|
||||
mNonE10sParent = MakeUnique<media::Parent<media::NonE10s>>(true);
|
||||
}
|
||||
return mNonE10sParent;
|
||||
return mNonE10sParent.get();
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
@ -2115,8 +2115,8 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
|
||||
p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission,
|
||||
prefs, isHTTPS, callID, origin](SourceSet*& aDevices) mutable {
|
||||
|
||||
RefPtr<Refcountable<ScopedDeletePtr<SourceSet>>> devices(
|
||||
new Refcountable<ScopedDeletePtr<SourceSet>>(aDevices)); // grab result
|
||||
RefPtr<Refcountable<UniquePtr<SourceSet>>> devices(
|
||||
new Refcountable<UniquePtr<SourceSet>>(aDevices)); // grab result
|
||||
|
||||
// Ensure that the captured 'this' pointer and our windowID are still good.
|
||||
if (!MediaManager::Exists() ||
|
||||
@ -2176,7 +2176,7 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow,
|
||||
onFailure.forget(),
|
||||
windowID, listener,
|
||||
prefs, origin,
|
||||
devices->forget()));
|
||||
devices->release()));
|
||||
// Store the task w/callbacks.
|
||||
mActiveCallbacks.Put(callID, task.forget());
|
||||
|
||||
@ -2335,7 +2335,7 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
|
||||
aVideoType, aAudioType,
|
||||
aFake, aFakeTracks);
|
||||
p->Then([id, aWindowId, aOriginKey](SourceSet*& aDevices) mutable {
|
||||
ScopedDeletePtr<SourceSet> devices(aDevices); // secondary result
|
||||
UniquePtr<SourceSet> devices(aDevices); // secondary result
|
||||
|
||||
// Only run if window is still on our active list.
|
||||
RefPtr<MediaManager> mgr = MediaManager_GetInstance();
|
||||
@ -2347,7 +2347,7 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
|
||||
return NS_OK;
|
||||
}
|
||||
MediaManager_AnonymizeDevices(*devices, aOriginKey);
|
||||
p->Resolve(devices.forget());
|
||||
p->Resolve(devices.release());
|
||||
return NS_OK;
|
||||
});
|
||||
});
|
||||
@ -2381,7 +2381,7 @@ MediaManager::EnumerateDevices(nsPIDOMWindowInner* aWindow,
|
||||
MediaSourceEnum::Microphone,
|
||||
fake);
|
||||
p->Then([onSuccess, windowId, listener](SourceSet*& aDevices) mutable {
|
||||
ScopedDeletePtr<SourceSet> devices(aDevices); // grab result
|
||||
UniquePtr<SourceSet> devices(aDevices); // grab result
|
||||
RefPtr<MediaManager> mgr = MediaManager_GetInstance();
|
||||
mgr->RemoveFromWindowList(windowId, listener);
|
||||
nsCOMPtr<nsIWritableVariant> array = MediaManager_ToJSArray(*devices);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "mozilla/media/MediaChild.h"
|
||||
#include "mozilla/media/MediaParent.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "DOMMediaStream.h"
|
||||
|
||||
#ifdef MOZ_WEBRTC
|
||||
@ -501,7 +502,7 @@ private:
|
||||
already_AddRefed<PledgeChar>
|
||||
SelectSettings(
|
||||
dom::MediaStreamConstraints& aConstraints,
|
||||
RefPtr<media::Refcountable<ScopedDeletePtr<SourceSet>>>& aSources);
|
||||
RefPtr<media::Refcountable<UniquePtr<SourceSet>>>& aSources);
|
||||
|
||||
StreamListeners* AddWindowID(uint64_t aWindowId);
|
||||
WindowTable *GetActiveWindows() {
|
||||
@ -550,7 +551,7 @@ private:
|
||||
#endif
|
||||
public:
|
||||
media::CoatCheck<media::Pledge<nsCString>> mGetOriginKeyPledges;
|
||||
ScopedDeletePtr<media::Parent<media::NonE10s>> mNonE10sParent;
|
||||
UniquePtr<media::Parent<media::NonE10s>> mNonE10sParent;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "gfx2DGlue.h"
|
||||
#include "ImageContainer.h"
|
||||
#include "Layers.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -52,18 +53,18 @@ VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
|
||||
int len = ((aSize.width * aSize.height) * 3 / 2);
|
||||
|
||||
// Generate a black image.
|
||||
ScopedDeletePtr<uint8_t> frame(new uint8_t[len]);
|
||||
auto frame = MakeUnique<uint8_t[]>(len);
|
||||
int y = aSize.width * aSize.height;
|
||||
// Fill Y plane.
|
||||
memset(frame.rwget(), 0x10, y);
|
||||
memset(frame.get(), 0x10, y);
|
||||
// Fill Cb/Cr planes.
|
||||
memset(frame.rwget() + y, 0x80, (len - y));
|
||||
memset(frame.get() + y, 0x80, (len - y));
|
||||
|
||||
const uint8_t lumaBpp = 8;
|
||||
const uint8_t chromaBpp = 4;
|
||||
|
||||
layers::PlanarYCbCrData data;
|
||||
data.mYChannel = frame.rwget();
|
||||
data.mYChannel = frame.get();
|
||||
data.mYSize = gfx::IntSize(aSize.width, aSize.height);
|
||||
data.mYStride = (int32_t) (aSize.width * lumaBpp / 8.0);
|
||||
data.mCbCrStride = (int32_t) (aSize.width * chromaBpp / 8.0);
|
||||
|
@ -46,7 +46,7 @@ SanitizeOriginKeys(const uint64_t& aSinceWhen, bool aOnlyPrivateBrowsing)
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||
// Avoid opening MediaManager in this case, since this is called by
|
||||
// sanitize.js when cookies are cleared, which can happen on startup.
|
||||
ScopedDeletePtr<Parent<NonE10s>> tmpParent(new Parent<NonE10s>(true));
|
||||
auto tmpParent = MakeUnique<Parent<NonE10s>>(true);
|
||||
tmpParent->RecvSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing);
|
||||
} else {
|
||||
Child::Get()->SendSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIAsyncShutdown.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "base/task.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -96,8 +97,8 @@ public:
|
||||
OnSuccessType mOnSuccess;
|
||||
OnFailureType mOnFailure;
|
||||
};
|
||||
mFunctors = new Functors(Forward<OnSuccessType>(aOnSuccess),
|
||||
Forward<OnFailureType>(aOnFailure));
|
||||
mFunctors = MakeUnique<Functors>(Forward<OnSuccessType>(aOnSuccess),
|
||||
Forward<OnFailureType>(aOnFailure));
|
||||
if (mDone) {
|
||||
if (!mRejected) {
|
||||
mFunctors->Succeed(mValue);
|
||||
@ -142,7 +143,7 @@ private:
|
||||
bool mDone;
|
||||
bool mRejected;
|
||||
ErrorType mError;
|
||||
ScopedDeletePtr<FunctorsBase> mFunctors;
|
||||
UniquePtr<FunctorsBase> mFunctors;
|
||||
};
|
||||
|
||||
/* media::NewRunnableFrom() - Create an nsRunnable from a lambda.
|
||||
@ -337,7 +338,7 @@ private:
|
||||
* (or owning smart-pointers to such objects) refcountable.
|
||||
*
|
||||
* Technical limitation: A template specialization is needed for types that take
|
||||
* a constructor. Please add below (ScopedDeletePtr covers a lot of ground though).
|
||||
* a constructor. Please add below (UniquePtr covers a lot of ground though).
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
@ -350,13 +351,13 @@ private:
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Refcountable<ScopedDeletePtr<T>> : public ScopedDeletePtr<T>
|
||||
class Refcountable<UniquePtr<T>> : public UniquePtr<T>
|
||||
{
|
||||
public:
|
||||
explicit Refcountable<ScopedDeletePtr<T>>(T* aPtr) : ScopedDeletePtr<T>(aPtr) {}
|
||||
explicit Refcountable<UniquePtr<T>>(T* aPtr) : UniquePtr<T>(aPtr) {}
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Refcountable<T>)
|
||||
private:
|
||||
~Refcountable<ScopedDeletePtr<T>>() {}
|
||||
~Refcountable<UniquePtr<T>>() {}
|
||||
};
|
||||
|
||||
/* media::ShutdownBlocker - Async shutdown helper.
|
||||
|
Loading…
Reference in New Issue
Block a user