Commit 353f2d5d authored by yutak's avatar yutak Committed by Commit bot

Remove the use of OwnedPtrDeleter in WebMessagePortChannel.

It's hard to mechanically replace specializations of OwnedPtrDeleter<T>
to std::unique_ptr equivalents, so they are converted manually.

A new typedef WebMessagePortChannelUniquePtr is introduced so people can
always use std::unique_ptr with a correct deleter.

BUG=617504

Review-Url: https://codereview.chromium.org/2043583002
Cr-Commit-Position: refs/heads/master@{#398213}
parent d0039e58
......@@ -41,8 +41,8 @@ static void createChannel(MessagePort* port1, MessagePort* port2)
DCHECK(channel2);
// Now entangle the proxies with the appropriate local ports.
port1->entangle(adoptPtr(channel2));
port2->entangle(adoptPtr(channel1));
port1->entangle(WebMessagePortChannelUniquePtr(channel2));
port2->entangle(WebMessagePortChannelUniquePtr(channel1));
}
MessageChannel::MessageChannel(ExecutionContext* context)
......
......@@ -98,7 +98,7 @@ PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray
if (channels && channels->size()) {
webChannels = adoptPtr(new WebMessagePortChannelArray(channels->size()));
for (size_t i = 0; i < channels->size(); ++i)
(*webChannels)[i] = (*channels)[i].leakPtr();
(*webChannels)[i] = (*channels)[i].release();
}
return webChannels;
}
......@@ -108,11 +108,11 @@ MessagePortArray* MessagePort::toMessagePortArray(ExecutionContext* context, con
{
OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
for (size_t i = 0; i < webChannels.size(); ++i)
(*channels)[i] = adoptPtr(webChannels[i]);
(*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]);
return MessagePort::entanglePorts(*context, std::move(channels));
}
PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle()
WebMessagePortChannelUniquePtr MessagePort::disentangle()
{
DCHECK(m_entangledChannel);
m_entangledChannel->setClient(0);
......@@ -148,7 +148,7 @@ void MessagePort::close()
m_closed = true;
}
void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote)
void MessagePort::entangle(WebMessagePortChannelUniquePtr remote)
{
// Only invoked to set our initial entanglement.
DCHECK(!m_entangledChannel);
......@@ -173,7 +173,7 @@ static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ
if (webChannels.size()) {
channels = adoptPtr(new MessagePortChannelArray(webChannels.size()));
for (size_t i = 0; i < webChannels.size(); ++i)
(*channels)[i] = adoptPtr(webChannels[i]);
(*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]);
}
message = SerializedScriptValue::create(messageString);
return true;
......
......@@ -40,6 +40,7 @@
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
#include <memory>
namespace blink {
......@@ -49,8 +50,8 @@ class MessagePort;
class ScriptState;
class SerializedScriptValue;
// Not to be confused with WebMessagePortChannelArray; this one uses Vector and OwnPtr instead of WebVector and raw pointers.
typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray;
// Not to be confused with WebMessagePortChannelArray; this one uses Vector and std::unique_ptr instead of WebVector and raw pointers.
typedef Vector<WebMessagePortChannelUniquePtr, 1> MessagePortChannelArray;
class CORE_EXPORT MessagePort
: public EventTargetWithInlineData
......@@ -68,8 +69,8 @@ public:
void start();
void close();
void entangle(PassOwnPtr<WebMessagePortChannel>);
PassOwnPtr<WebMessagePortChannel> disentangle();
void entangle(WebMessagePortChannelUniquePtr);
WebMessagePortChannelUniquePtr disentangle();
// Returns nullptr if the passed-in array is nullptr/empty.
static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(PassOwnPtr<MessagePortChannelArray>);
......@@ -119,7 +120,7 @@ private:
void messageAvailable() override;
void dispatchMessages();
OwnPtr<WebMessagePortChannel> m_entangledChannel;
WebMessagePortChannelUniquePtr m_entangledChannel;
bool m_started;
bool m_closed;
......
......@@ -64,7 +64,7 @@ SharedWorker* SharedWorker::create(ExecutionContext* context, const String& url,
MessageChannel* channel = MessageChannel::create(context);
worker->m_port = channel->port1();
OwnPtr<WebMessagePortChannel> remotePort = channel->port2()->disentangle();
WebMessagePortChannelUniquePtr remotePort = channel->port2()->disentangle();
DCHECK(remotePort);
worker->suspendIfNeeded();
......
......@@ -32,13 +32,10 @@
#define SharedWorkerRepositoryClient_h
#include "platform/heap/Handle.h"
#include "public/platform/WebMessagePortChannel.h"
#include "wtf/Forward.h"
#include "wtf/Noncopyable.h"
namespace blink {
class WebMessagePortChannel;
}
namespace blink {
class Document;
......@@ -53,7 +50,7 @@ public:
SharedWorkerRepositoryClient() { }
virtual ~SharedWorkerRepositoryClient() { }
virtual void connect(SharedWorker*, PassOwnPtr<WebMessagePortChannel>, const KURL&, const String& name, ExceptionState&) = 0;
virtual void connect(SharedWorker*, WebMessagePortChannelUniquePtr, const KURL&, const String& name, ExceptionState&) = 0;
virtual void documentDetached(Document*) = 0;
};
......
......@@ -144,11 +144,11 @@ struct CrossThreadCopier<PassOwnPtr<T>> {
}
};
template <typename T>
struct CrossThreadCopier<std::unique_ptr<T>> {
template <typename T, typename Deleter>
struct CrossThreadCopier<std::unique_ptr<T, Deleter>> {
STATIC_ONLY(CrossThreadCopier);
using Type = std::unique_ptr<T>;
static std::unique_ptr<T> copy(std::unique_ptr<T> pointer)
using Type = std::unique_ptr<T, Deleter>;
static std::unique_ptr<T, Deleter> copy(std::unique_ptr<T, Deleter> pointer)
{
return pointer; // This is in fact a move.
}
......
......@@ -56,7 +56,7 @@ namespace blink {
// Callback class that keeps the SharedWorker and WebSharedWorker objects alive while connecting.
class SharedWorkerConnector : private WebSharedWorkerConnector::ConnectListener {
public:
SharedWorkerConnector(SharedWorker* worker, const KURL& url, const String& name, PassOwnPtr<WebMessagePortChannel> channel, PassOwnPtr<WebSharedWorkerConnector> webWorkerConnector)
SharedWorkerConnector(SharedWorker* worker, const KURL& url, const String& name, WebMessagePortChannelUniquePtr channel, PassOwnPtr<WebSharedWorkerConnector> webWorkerConnector)
: m_worker(worker)
, m_url(url)
, m_name(name)
......@@ -75,7 +75,7 @@ private:
KURL m_url;
String m_name;
OwnPtr<WebSharedWorkerConnector> m_webWorkerConnector;
OwnPtr<WebMessagePortChannel> m_channel;
WebMessagePortChannelUniquePtr m_channel;
};
SharedWorkerConnector::~SharedWorkerConnector()
......@@ -86,7 +86,7 @@ SharedWorkerConnector::~SharedWorkerConnector()
void SharedWorkerConnector::connect()
{
m_worker->setIsBeingConnected(true);
m_webWorkerConnector->connect(m_channel.leakPtr(), this);
m_webWorkerConnector->connect(m_channel.release(), this);
}
void SharedWorkerConnector::connected()
......@@ -108,7 +108,7 @@ static WebSharedWorkerRepositoryClient::DocumentID getId(void* document)
return reinterpret_cast<WebSharedWorkerRepositoryClient::DocumentID>(document);
}
void SharedWorkerRepositoryClientImpl::connect(SharedWorker* worker, PassOwnPtr<WebMessagePortChannel> port, const KURL& url, const String& name, ExceptionState& exceptionState)
void SharedWorkerRepositoryClientImpl::connect(SharedWorker* worker, WebMessagePortChannelUniquePtr port, const KURL& url, const String& name, ExceptionState& exceptionState)
{
DCHECK(m_client);
......
......@@ -51,7 +51,7 @@ public:
~SharedWorkerRepositoryClientImpl() override { }
void connect(SharedWorker*, PassOwnPtr<WebMessagePortChannel>, const KURL&, const String& name, ExceptionState&) override;
void connect(SharedWorker*, WebMessagePortChannelUniquePtr, const KURL&, const String& name, ExceptionState&) override;
void documentDetached(Document*) override;
private:
......
......@@ -78,7 +78,7 @@ WebMessagePortChannelArray WebDOMMessageEvent::releaseChannels()
WebMessagePortChannelArray webChannels(channels ? channels->size() : 0);
if (channels) {
for (size_t i = 0; i < channels->size(); ++i)
webChannels[i] = (*channels)[i].leakPtr();
webChannels[i] = (*channels)[i].release();
}
return webChannels;
}
......
......@@ -276,10 +276,10 @@ bool WebSharedWorkerImpl::postTaskToWorkerGlobalScope(std::unique_ptr<ExecutionC
void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel)
{
workerThread()->postTask(
BLINK_FROM_HERE, createCrossThreadTask(&connectTask, passed(adoptPtr(webChannel))));
BLINK_FROM_HERE, createCrossThreadTask(&connectTask, passed(WebMessagePortChannelUniquePtr(webChannel))));
}
void WebSharedWorkerImpl::connectTask(PassOwnPtr<WebMessagePortChannel> channel, ExecutionContext* context)
void WebSharedWorkerImpl::connectTask(WebMessagePortChannelUniquePtr channel, ExecutionContext* context)
{
// Wrap the passed-in channel in a MessagePort, and send it off via a connect event.
MessagePort* port = MessagePort::create(*context);
......
......@@ -122,7 +122,7 @@ private:
void didReceiveScriptLoaderResponse();
void onScriptLoaderFinished();
static void connectTask(PassOwnPtr<WebMessagePortChannel>, ExecutionContext*);
static void connectTask(WebMessagePortChannelUniquePtr, ExecutionContext*);
// Tasks that are run on the main thread.
void workerGlobalScopeClosedOnMainThread();
void workerThreadTerminatedOnMainThread();
......
......@@ -34,6 +34,10 @@
#include "WebCommon.h"
#include "WebVector.h"
#if INSIDE_BLINK
#include <memory>
#endif
namespace blink {
class WebMessagePortChannelClient;
......@@ -56,23 +60,20 @@ protected:
~WebMessagePortChannel() { }
};
} // namespace blink
#if INSIDE_BLINK
namespace WTF {
template<typename T> struct OwnedPtrDeleter;
template<> struct OwnedPtrDeleter<blink::WebMessagePortChannel> {
static void deletePtr(blink::WebMessagePortChannel* channel)
struct WebMessagePortChannelDeleter {
void operator()(WebMessagePortChannel* channel)
{
if (channel)
channel->destroy();
}
};
} // namespace WTF
using WebMessagePortChannelUniquePtr = std::unique_ptr<WebMessagePortChannel, WebMessagePortChannelDeleter>;
#endif // INSIDE_BLINK
} // namespace blink
#endif // WebMessagePortChannel_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment