Skip to content
Permalink
Browse files
[MediaStream] Use std::unique_ptr instead of OwnPtr/PassOwnPtr
https://bugs.webkit.org/show_bug.cgi?id=124858

Patch by Sergio Correia <sergio.correia@openbossa.org> on 2013-11-25
Reviewed by Eric Carlson.

Another step of the OwnPtr/PassOwnPtr => std::unique_ptr conversion,
now targeting mediastream-related code.

No new tests, covered by existing ones.

* Modules/mediastream/RTCDTMFSender.cpp:
* Modules/mediastream/RTCDTMFSender.h:
* Modules/mediastream/RTCDataChannel.cpp:
* Modules/mediastream/RTCDataChannel.h:
* Modules/mediastream/RTCPeerConnection.cpp:
* Modules/mediastream/RTCPeerConnection.h:
* platform/mediastream/MediaStreamSource.cpp:
* platform/mediastream/RTCPeerConnectionHandler.cpp:
* platform/mediastream/RTCPeerConnectionHandler.h:
* platform/mediastream/RTCPeerConnectionHandlerClient.h:
* platform/mock/RTCNotifiersMock.cpp:
* platform/mock/RTCPeerConnectionHandlerMock.cpp:
* platform/mock/RTCPeerConnectionHandlerMock.h:

Canonical link: https://commits.webkit.org/143020@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
qrwteyrutiyoup authored and webkit-commit-queue committed Nov 25, 2013
1 parent 660dccb commit ed2b3d666a85aa353fd5c31f10e668cc088ce8dc
Showing 14 changed files with 58 additions and 47 deletions.
@@ -1,3 +1,29 @@
2013-11-25 Sergio Correia <sergio.correia@openbossa.org>

[MediaStream] Use std::unique_ptr instead of OwnPtr/PassOwnPtr
https://bugs.webkit.org/show_bug.cgi?id=124858

Reviewed by Eric Carlson.

Another step of the OwnPtr/PassOwnPtr => std::unique_ptr conversion,
now targeting mediastream-related code.

No new tests, covered by existing ones.

* Modules/mediastream/RTCDTMFSender.cpp:
* Modules/mediastream/RTCDTMFSender.h:
* Modules/mediastream/RTCDataChannel.cpp:
* Modules/mediastream/RTCDataChannel.h:
* Modules/mediastream/RTCPeerConnection.cpp:
* Modules/mediastream/RTCPeerConnection.h:
* platform/mediastream/MediaStreamSource.cpp:
* platform/mediastream/RTCPeerConnectionHandler.cpp:
* platform/mediastream/RTCPeerConnectionHandler.h:
* platform/mediastream/RTCPeerConnectionHandlerClient.h:
* platform/mock/RTCNotifiersMock.cpp:
* platform/mock/RTCPeerConnectionHandlerMock.cpp:
* platform/mock/RTCPeerConnectionHandlerMock.h:

2013-11-25 Nick Diego Yamane <nick.yamane@openbossa.org>

MediaStreamRegistry should store MediaStreams instead of MediaStreamPrivates
@@ -47,23 +47,23 @@ static const long defaultInterToneGapMs = 50;
PassRefPtr<RTCDTMFSender> RTCDTMFSender::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* peerConnectionHandler, PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode& ec)
{
RefPtr<MediaStreamTrack> track = prpTrack;
OwnPtr<RTCDTMFSenderHandler> handler = peerConnectionHandler->createDTMFSender(track->source());
std::unique_ptr<RTCDTMFSenderHandler> handler = peerConnectionHandler->createDTMFSender(track->source());
if (!handler) {
ec = NOT_SUPPORTED_ERR;
return nullptr;
}

RefPtr<RTCDTMFSender> dtmfSender = adoptRef(new RTCDTMFSender(context, track, handler.release()));
RefPtr<RTCDTMFSender> dtmfSender = adoptRef(new RTCDTMFSender(context, track, std::move(handler)));
dtmfSender->suspendIfNeeded();
return dtmfSender.release();
}

RTCDTMFSender::RTCDTMFSender(ScriptExecutionContext* context, PassRefPtr<MediaStreamTrack> track, PassOwnPtr<RTCDTMFSenderHandler> handler)
RTCDTMFSender::RTCDTMFSender(ScriptExecutionContext* context, PassRefPtr<MediaStreamTrack> track, std::unique_ptr<RTCDTMFSenderHandler> handler)
: ActiveDOMObject(context)
, m_track(track)
, m_duration(defaultToneDurationMs)
, m_interToneGap(defaultInterToneGapMs)
, m_handler(handler)
, m_handler(std::move(handler))
, m_stopped(false)
, m_scheduledEventTimer(this, &RTCDTMFSender::scheduledEventTimerFired)
{
@@ -69,7 +69,7 @@ class RTCDTMFSender FINAL : public RefCounted<RTCDTMFSender>, public ScriptWrapp
using RefCounted<RTCDTMFSender>::deref;

private:
RTCDTMFSender(ScriptExecutionContext*, PassRefPtr<MediaStreamTrack>, PassOwnPtr<RTCDTMFSenderHandler>);
RTCDTMFSender(ScriptExecutionContext*, PassRefPtr<MediaStreamTrack>, std::unique_ptr<RTCDTMFSenderHandler>);

void scheduleDispatchEvent(PassRefPtr<Event>);
void scheduledEventTimerFired(Timer<RTCDTMFSender>*);
@@ -85,7 +85,7 @@ class RTCDTMFSender FINAL : public RefCounted<RTCDTMFSender>, public ScriptWrapp
long m_duration;
long m_interToneGap;

OwnPtr<RTCDTMFSenderHandler> m_handler;
std::unique_ptr<RTCDTMFSenderHandler> m_handler;

bool m_stopped;

@@ -64,23 +64,23 @@ PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* contex
options.get("maxRetransmitTime", initData.maxRetransmitTime);
options.get("protocol", initData.protocol);

OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataChannel(label, initData);
std::unique_ptr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataChannel(label, initData);
if (!handler) {
ec = NOT_SUPPORTED_ERR;
return nullptr;
}
return adoptRef(new RTCDataChannel(context, handler.release()));
return adoptRef(new RTCDataChannel(context, std::move(handler)));
}

PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, PassOwnPtr<RTCDataChannelHandler> handler)
PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, std::unique_ptr<RTCDataChannelHandler> handler)
{
ASSERT(handler);
return adoptRef(new RTCDataChannel(context, handler));
return adoptRef(new RTCDataChannel(context, std::move(handler)));
}

RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, PassOwnPtr<RTCDataChannelHandler> handler)
RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, std::unique_ptr<RTCDataChannelHandler> handler)
: m_scriptExecutionContext(context)
, m_handler(handler)
, m_handler(std::move(handler))
, m_stopped(false)
, m_readyState(ReadyStateConnecting)
, m_binaryType(BinaryTypeArrayBuffer)
@@ -47,7 +47,7 @@ class RTCPeerConnectionHandler;

class RTCDataChannel FINAL : public RefCounted<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public RTCDataChannelHandlerClient {
public:
static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, PassOwnPtr<RTCDataChannelHandler>);
static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>);
static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& , const Dictionary&, ExceptionCode&);
~RTCDataChannel();

@@ -86,7 +86,7 @@ class RTCDataChannel FINAL : public RefCounted<RTCDataChannel>, public ScriptWra
using RefCounted<RTCDataChannel>::deref;

private:
RTCDataChannel(ScriptExecutionContext*, PassOwnPtr<RTCDataChannelHandler>);
RTCDataChannel(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>);

void scheduleDispatchEvent(PassRefPtr<Event>);
void scheduledEventTimerFired(Timer<RTCDataChannel>*);
@@ -103,7 +103,7 @@ class RTCDataChannel FINAL : public RefCounted<RTCDataChannel>, public ScriptWra
virtual void didReceiveRawData(const char*, size_t) OVERRIDE;
virtual void didDetectError() OVERRIDE;

OwnPtr<RTCDataChannelHandler> m_handler;
std::unique_ptr<RTCDataChannelHandler> m_handler;

bool m_stopped;

@@ -574,14 +574,14 @@ void RTCPeerConnection::didRemoveRemoteStream(MediaStreamPrivate* privateStream)
scheduleDispatchEvent(MediaStreamEvent::create(eventNames().removestreamEvent, false, false, stream.release()));
}

void RTCPeerConnection::didAddRemoteDataChannel(PassOwnPtr<RTCDataChannelHandler> handler)
void RTCPeerConnection::didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler> handler)
{
ASSERT(scriptExecutionContext()->isContextThread());

if (m_signalingState == SignalingStateClosed)
return;

RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), handler);
RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), std::move(handler));
m_dataChannels.append(channel);

scheduleDispatchEvent(RTCDataChannelEvent::create(eventNames().datachannelEvent, false, false, channel.release()));
@@ -118,7 +118,7 @@ class RTCPeerConnection FINAL : public RefCounted<RTCPeerConnection>, public Scr
virtual void didChangeIceConnectionState(IceConnectionState) OVERRIDE;
virtual void didAddRemoteStream(PassRefPtr<MediaStreamPrivate>) OVERRIDE;
virtual void didRemoveRemoteStream(MediaStreamPrivate*) OVERRIDE;
virtual void didAddRemoteDataChannel(PassOwnPtr<RTCDataChannelHandler>) OVERRIDE;
virtual void didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler>) OVERRIDE;

// EventTarget
virtual EventTargetInterface eventTargetInterface() const OVERRIDE { return RTCPeerConnectionEventTargetInterfaceType; }
@@ -155,7 +155,7 @@ class RTCPeerConnection FINAL : public RefCounted<RTCPeerConnection>, public Scr

Vector<RefPtr<RTCDataChannel>> m_dataChannels;

OwnPtr<RTCPeerConnectionHandler> m_peerHandler;
std::unique_ptr<RTCPeerConnectionHandler> m_peerHandler;

Timer<RTCPeerConnection> m_scheduledEventTimer;
Vector<RefPtr<Event>> m_scheduledEvents;
@@ -40,8 +40,6 @@
#include "MediaStreamSourceCapabilities.h"
#include "UUID.h"

#include <wtf/PassOwnPtr.h>

namespace WebCore {

MediaStreamSource::MediaStreamSource(const String& id, Type type, const String& name)
@@ -34,12 +34,10 @@

#include "RTCPeerConnectionHandler.h"

#include <wtf/PassOwnPtr.h>

namespace WebCore {
class RTCPeerConnectionHandlerClient;

static PassOwnPtr<RTCPeerConnectionHandler> createHandler(RTCPeerConnectionHandlerClient*)
static std::unique_ptr<RTCPeerConnectionHandler> createHandler(RTCPeerConnectionHandlerClient*)
{
return nullptr;
}
@@ -34,7 +34,6 @@
#if ENABLE(MEDIA_STREAM)

#include "MediaStreamPrivate.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>

namespace WebCore {
@@ -68,7 +67,7 @@ struct RTCDataChannelInit {
int id;
};

typedef PassOwnPtr<RTCPeerConnectionHandler> (*CreatePeerConnectionHandler)(RTCPeerConnectionHandlerClient*);
typedef std::unique_ptr<RTCPeerConnectionHandler> (*CreatePeerConnectionHandler)(RTCPeerConnectionHandlerClient*);

class RTCPeerConnectionHandler {
public:
@@ -88,12 +87,9 @@ class RTCPeerConnectionHandler {
virtual bool addStream(PassRefPtr<MediaStreamPrivate>, PassRefPtr<MediaConstraints>) = 0;
virtual void removeStream(PassRefPtr<MediaStreamPrivate>) = 0;
virtual void getStats(PassRefPtr<RTCStatsRequest>) = 0;
virtual PassOwnPtr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) = 0;
virtual PassOwnPtr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamSource>) = 0;
virtual std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) = 0;
virtual std::unique_ptr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamSource>) = 0;
virtual void stop() = 0;

protected:
RTCPeerConnectionHandler() { }
};

} // namespace WebCore
@@ -33,7 +33,6 @@

#if ENABLE(MEDIA_STREAM)

#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>

namespace WebCore {
@@ -78,7 +77,7 @@ class RTCPeerConnectionHandlerClient {
virtual void didChangeIceConnectionState(IceConnectionState) = 0;
virtual void didAddRemoteStream(PassRefPtr<MediaStreamPrivate>) = 0;
virtual void didRemoveRemoteStream(MediaStreamPrivate*) = 0;
virtual void didAddRemoteDataChannel(PassOwnPtr<RTCDataChannelHandler>) = 0;
virtual void didAddRemoteDataChannel(std::unique_ptr<RTCDataChannelHandler>) = 0;
};

} // namespace WebCore
@@ -84,7 +84,7 @@ RemoteDataChannelNotifier::RemoteDataChannelNotifier(RTCPeerConnectionHandlerCli

void RemoteDataChannelNotifier::fire()
{
m_client->didAddRemoteDataChannel(adoptPtr(new RTCDataChannelHandlerMock("RTCDataChannelHandlerMock", RTCDataChannelInit())));
m_client->didAddRemoteDataChannel(std::make_unique<RTCDataChannelHandlerMock>("RTCDataChannelHandlerMock", RTCDataChannelInit()));
}

DataChannelStateNotifier::DataChannelStateNotifier(RTCDataChannelHandlerClient* client, RTCDataChannelHandlerClient::ReadyState state)
@@ -40,11 +40,6 @@

namespace WebCore {

PassOwnPtr<RTCPeerConnectionHandler> RTCPeerConnectionHandlerMock::create(RTCPeerConnectionHandlerClient* client)
{
return adoptPtr(new RTCPeerConnectionHandlerMock(client));
}

RTCPeerConnectionHandlerMock::RTCPeerConnectionHandlerMock(RTCPeerConnectionHandlerClient* client)
: m_client(client)
{
@@ -153,19 +148,19 @@ void RTCPeerConnectionHandlerMock::getStats(PassRefPtr<RTCStatsRequest>)
notImplemented();
}

PassOwnPtr<RTCDataChannelHandler> RTCPeerConnectionHandlerMock::createDataChannel(const String& label, const RTCDataChannelInit& init)
std::unique_ptr<RTCDataChannelHandler> RTCPeerConnectionHandlerMock::createDataChannel(const String& label, const RTCDataChannelInit& init)
{
RefPtr<RemoteDataChannelNotifier> notifier = adoptRef(new RemoteDataChannelNotifier(m_client));
m_timerEvents.append(adoptRef(new TimerEvent(this, notifier)));
return adoptPtr(new RTCDataChannelHandlerMock(label, init));
return std::make_unique<RTCDataChannelHandlerMock>(label, init);
}

PassOwnPtr<RTCDTMFSenderHandler> RTCPeerConnectionHandlerMock::createDTMFSender(PassRefPtr<MediaStreamSource>)
std::unique_ptr<RTCDTMFSenderHandler> RTCPeerConnectionHandlerMock::createDTMFSender(PassRefPtr<MediaStreamSource>)
{
// Requires a mock implementation of RTCDTMFSenderHandler.
// This must be implemented once the mock implementation of RTCDataChannelHandler is ready.
notImplemented();
return 0;
return nullptr;
}

void RTCPeerConnectionHandlerMock::stop()
@@ -36,7 +36,6 @@ namespace WebCore {

class RTCPeerConnectionHandlerMock FINAL : public RTCPeerConnectionHandler, public TimerEventBasedMock {
public:
static PassOwnPtr<RTCPeerConnectionHandler> create(RTCPeerConnectionHandlerClient*);
virtual ~RTCPeerConnectionHandlerMock() { }

virtual bool initialize(PassRefPtr<RTCConfiguration>, PassRefPtr<MediaConstraints>) OVERRIDE;
@@ -52,12 +51,12 @@ class RTCPeerConnectionHandlerMock FINAL : public RTCPeerConnectionHandler, publ
virtual bool addStream(PassRefPtr<MediaStreamPrivate>, PassRefPtr<MediaConstraints>) OVERRIDE;
virtual void removeStream(PassRefPtr<MediaStreamPrivate>) OVERRIDE;
virtual void getStats(PassRefPtr<RTCStatsRequest>) OVERRIDE;
virtual PassOwnPtr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) OVERRIDE;
virtual PassOwnPtr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamSource>) OVERRIDE;
virtual std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String& label, const RTCDataChannelInit&) OVERRIDE;
virtual std::unique_ptr<RTCDTMFSenderHandler> createDTMFSender(PassRefPtr<MediaStreamSource>) OVERRIDE;
virtual void stop() OVERRIDE;

protected:
RTCPeerConnectionHandlerMock(RTCPeerConnectionHandlerClient*);
explicit RTCPeerConnectionHandlerMock(RTCPeerConnectionHandlerClient*);

private:
RTCPeerConnectionHandlerClient* m_client;

0 comments on commit ed2b3d6

Please sign in to comment.