| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "core/fileapi/Blob.h" | 38 #include "core/fileapi/Blob.h" |
| 39 #include "core/workers/WorkerGlobalScope.h" | 39 #include "core/workers/WorkerGlobalScope.h" |
| 40 #include "core/workers/WorkerLoaderProxy.h" | 40 #include "core/workers/WorkerLoaderProxy.h" |
| 41 #include "core/workers/WorkerThread.h" | 41 #include "core/workers/WorkerThread.h" |
| 42 #include "modules/websockets/DocumentWebSocketChannel.h" | 42 #include "modules/websockets/DocumentWebSocketChannel.h" |
| 43 #include "platform/WaitableEvent.h" | 43 #include "platform/WaitableEvent.h" |
| 44 #include "platform/heap/SafePoint.h" | 44 #include "platform/heap/SafePoint.h" |
| 45 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 46 #include "wtf/Assertions.h" | 46 #include "wtf/Assertions.h" |
| 47 #include "wtf/Functional.h" | 47 #include "wtf/Functional.h" |
| 48 #include "wtf/PtrUtil.h" |
| 48 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 49 #include "wtf/text/WTFString.h" | 50 #include "wtf/text/WTFString.h" |
| 51 #include <memory> |
| 50 | 52 |
| 51 namespace blink { | 53 namespace blink { |
| 52 | 54 |
| 53 typedef WorkerWebSocketChannel::Bridge Bridge; | 55 typedef WorkerWebSocketChannel::Bridge Bridge; |
| 54 typedef WorkerWebSocketChannel::Peer Peer; | 56 typedef WorkerWebSocketChannel::Peer Peer; |
| 55 | 57 |
| 56 // Created and destroyed on the worker thread. All setters of this class are | 58 // Created and destroyed on the worker thread. All setters of this class are |
| 57 // called on the main thread, while all getters are called on the worker | 59 // called on the main thread, while all getters are called on the worker |
| 58 // thread. signalWorkerThread() must be called before any getters are called. | 60 // thread. signalWorkerThread() must be called before any getters are called. |
| 59 class WebSocketChannelSyncHelper : public GarbageCollectedFinalized<WebSocketCha
nnelSyncHelper> { | 61 class WebSocketChannelSyncHelper : public GarbageCollectedFinalized<WebSocketCha
nnelSyncHelper> { |
| 60 public: | 62 public: |
| 61 static WebSocketChannelSyncHelper* create(PassOwnPtr<WaitableEvent> event) | 63 static WebSocketChannelSyncHelper* create(std::unique_ptr<WaitableEvent> eve
nt) |
| 62 { | 64 { |
| 63 return new WebSocketChannelSyncHelper(std::move(event)); | 65 return new WebSocketChannelSyncHelper(std::move(event)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 ~WebSocketChannelSyncHelper() | 68 ~WebSocketChannelSyncHelper() |
| 67 { | 69 { |
| 68 } | 70 } |
| 69 | 71 |
| 70 // All setters are called on the main thread. | 72 // All setters are called on the main thread. |
| 71 void setConnectRequestResult(bool connectRequestResult) | 73 void setConnectRequestResult(bool connectRequestResult) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 m_event->signal(); | 88 m_event->signal(); |
| 87 } | 89 } |
| 88 void wait() | 90 void wait() |
| 89 { | 91 { |
| 90 m_event->wait(); | 92 m_event->wait(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 DEFINE_INLINE_TRACE() { } | 95 DEFINE_INLINE_TRACE() { } |
| 94 | 96 |
| 95 private: | 97 private: |
| 96 explicit WebSocketChannelSyncHelper(PassOwnPtr<WaitableEvent> event) | 98 explicit WebSocketChannelSyncHelper(std::unique_ptr<WaitableEvent> event) |
| 97 : m_event(std::move(event)) | 99 : m_event(std::move(event)) |
| 98 , m_connectRequestResult(false) | 100 , m_connectRequestResult(false) |
| 99 { | 101 { |
| 100 } | 102 } |
| 101 | 103 |
| 102 OwnPtr<WaitableEvent> m_event; | 104 std::unique_ptr<WaitableEvent> m_event; |
| 103 bool m_connectRequestResult; | 105 bool m_connectRequestResult; |
| 104 }; | 106 }; |
| 105 | 107 |
| 106 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc
ope, WebSocketChannelClient* client, PassOwnPtr<SourceLocation> location) | 108 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc
ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) |
| 107 : m_bridge(new Bridge(client, workerGlobalScope)) | 109 : m_bridge(new Bridge(client, workerGlobalScope)) |
| 108 , m_locationAtConnection(std::move(location)) | 110 , m_locationAtConnection(std::move(location)) |
| 109 { | 111 { |
| 110 m_bridge->initialize(m_locationAtConnection->clone()); | 112 m_bridge->initialize(m_locationAtConnection->clone()); |
| 111 } | 113 } |
| 112 | 114 |
| 113 WorkerWebSocketChannel::~WorkerWebSocketChannel() | 115 WorkerWebSocketChannel::~WorkerWebSocketChannel() |
| 114 { | 116 { |
| 115 ASSERT(!m_bridge); | 117 ASSERT(!m_bridge); |
| 116 } | 118 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 ASSERT(m_bridge); | 140 ASSERT(m_bridge); |
| 139 m_bridge->send(blobData); | 141 m_bridge->send(blobData); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void WorkerWebSocketChannel::close(int code, const String& reason) | 144 void WorkerWebSocketChannel::close(int code, const String& reason) |
| 143 { | 145 { |
| 144 ASSERT(m_bridge); | 146 ASSERT(m_bridge); |
| 145 m_bridge->close(code, reason); | 147 m_bridge->close(code, reason); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, Pass
OwnPtr<SourceLocation> location) | 150 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, std:
:unique_ptr<SourceLocation> location) |
| 149 { | 151 { |
| 150 if (!m_bridge) | 152 if (!m_bridge) |
| 151 return; | 153 return; |
| 152 | 154 |
| 153 OwnPtr<SourceLocation> capturedLocation = SourceLocation::capture(); | 155 std::unique_ptr<SourceLocation> capturedLocation = SourceLocation::capture()
; |
| 154 if (!capturedLocation->isUnknown()) { | 156 if (!capturedLocation->isUnknown()) { |
| 155 // If we are in JavaScript context, use the current location instead | 157 // If we are in JavaScript context, use the current location instead |
| 156 // of passed one - it's more precise. | 158 // of passed one - it's more precise. |
| 157 m_bridge->fail(reason, level, std::move(capturedLocation)); | 159 m_bridge->fail(reason, level, std::move(capturedLocation)); |
| 158 } else if (location->isUnknown()) { | 160 } else if (location->isUnknown()) { |
| 159 // No information is specified by the caller - use the url | 161 // No information is specified by the caller - use the url |
| 160 // and the line number at the connection. | 162 // and the line number at the connection. |
| 161 m_bridge->fail(reason, level, m_locationAtConnection->clone()); | 163 m_bridge->fail(reason, level, m_locationAtConnection->clone()); |
| 162 } else { | 164 } else { |
| 163 // Use the specified information. | 165 // Use the specified information. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 185 , m_syncHelper(syncHelper) | 187 , m_syncHelper(syncHelper) |
| 186 { | 188 { |
| 187 DCHECK(isMainThread()); | 189 DCHECK(isMainThread()); |
| 188 } | 190 } |
| 189 | 191 |
| 190 Peer::~Peer() | 192 Peer::~Peer() |
| 191 { | 193 { |
| 192 DCHECK(isMainThread()); | 194 DCHECK(isMainThread()); |
| 193 } | 195 } |
| 194 | 196 |
| 195 bool Peer::initialize(PassOwnPtr<SourceLocation> location, ExecutionContext* con
text) | 197 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext
* context) |
| 196 { | 198 { |
| 197 ASSERT(isMainThread()); | 199 ASSERT(isMainThread()); |
| 198 if (wasContextDestroyedBeforeObserverCreation()) | 200 if (wasContextDestroyedBeforeObserverCreation()) |
| 199 return false; | 201 return false; |
| 200 Document* document = toDocument(context); | 202 Document* document = toDocument(context); |
| 201 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st
d::move(location)); | 203 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st
d::move(location)); |
| 202 return true; | 204 return true; |
| 203 } | 205 } |
| 204 | 206 |
| 205 void Peer::connect(const KURL& url, const String& protocol) | 207 void Peer::connect(const KURL& url, const String& protocol) |
| 206 { | 208 { |
| 207 ASSERT(isMainThread()); | 209 ASSERT(isMainThread()); |
| 208 ASSERT(m_syncHelper); | 210 ASSERT(m_syncHelper); |
| 209 if (!m_mainWebSocketChannel) { | 211 if (!m_mainWebSocketChannel) { |
| 210 m_syncHelper->setConnectRequestResult(false); | 212 m_syncHelper->setConnectRequestResult(false); |
| 211 } else { | 213 } else { |
| 212 bool connectRequestResult = m_mainWebSocketChannel->connect(url, protoco
l); | 214 bool connectRequestResult = m_mainWebSocketChannel->connect(url, protoco
l); |
| 213 m_syncHelper->setConnectRequestResult(connectRequestResult); | 215 m_syncHelper->setConnectRequestResult(connectRequestResult); |
| 214 } | 216 } |
| 215 m_syncHelper->signalWorkerThread(); | 217 m_syncHelper->signalWorkerThread(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void Peer::sendTextAsCharVector(PassOwnPtr<Vector<char>> data) | 220 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) |
| 219 { | 221 { |
| 220 ASSERT(isMainThread()); | 222 ASSERT(isMainThread()); |
| 221 if (m_mainWebSocketChannel) | 223 if (m_mainWebSocketChannel) |
| 222 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); | 224 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); |
| 223 } | 225 } |
| 224 | 226 |
| 225 void Peer::sendBinaryAsCharVector(PassOwnPtr<Vector<char>> data) | 227 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) |
| 226 { | 228 { |
| 227 ASSERT(isMainThread()); | 229 ASSERT(isMainThread()); |
| 228 if (m_mainWebSocketChannel) | 230 if (m_mainWebSocketChannel) |
| 229 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data)); | 231 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data)); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) | 234 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) |
| 233 { | 235 { |
| 234 ASSERT(isMainThread()); | 236 ASSERT(isMainThread()); |
| 235 if (m_mainWebSocketChannel) | 237 if (m_mainWebSocketChannel) |
| 236 m_mainWebSocketChannel->send(blobData); | 238 m_mainWebSocketChannel->send(blobData); |
| 237 } | 239 } |
| 238 | 240 |
| 239 void Peer::close(int code, const String& reason) | 241 void Peer::close(int code, const String& reason) |
| 240 { | 242 { |
| 241 ASSERT(isMainThread()); | 243 ASSERT(isMainThread()); |
| 242 ASSERT(m_syncHelper); | 244 ASSERT(m_syncHelper); |
| 243 if (!m_mainWebSocketChannel) | 245 if (!m_mainWebSocketChannel) |
| 244 return; | 246 return; |
| 245 m_mainWebSocketChannel->close(code, reason); | 247 m_mainWebSocketChannel->close(code, reason); |
| 246 } | 248 } |
| 247 | 249 |
| 248 void Peer::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLocat
ion> location) | 250 void Peer::fail(const String& reason, MessageLevel level, std::unique_ptr<Source
Location> location) |
| 249 { | 251 { |
| 250 ASSERT(isMainThread()); | 252 ASSERT(isMainThread()); |
| 251 ASSERT(m_syncHelper); | 253 ASSERT(m_syncHelper); |
| 252 if (!m_mainWebSocketChannel) | 254 if (!m_mainWebSocketChannel) |
| 253 return; | 255 return; |
| 254 m_mainWebSocketChannel->fail(reason, level, std::move(location)); | 256 m_mainWebSocketChannel->fail(reason, level, std::move(location)); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void Peer::disconnect() | 259 void Peer::disconnect() |
| 258 { | 260 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 284 if (bridge->client()) | 286 if (bridge->client()) |
| 285 bridge->client()->didReceiveTextMessage(payload); | 287 bridge->client()->didReceiveTextMessage(payload); |
| 286 } | 288 } |
| 287 | 289 |
| 288 void Peer::didReceiveTextMessage(const String& payload) | 290 void Peer::didReceiveTextMessage(const String& payload) |
| 289 { | 291 { |
| 290 ASSERT(isMainThread()); | 292 ASSERT(isMainThread()); |
| 291 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveTextMessage, m_bridge, payload)); | 293 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveTextMessage, m_bridge, payload)); |
| 292 } | 294 } |
| 293 | 295 |
| 294 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, PassOwnPtr<
Vector<char>> payload, ExecutionContext* context) | 296 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique
_ptr<Vector<char>> payload, ExecutionContext* context) |
| 295 { | 297 { |
| 296 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 298 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 297 if (bridge->client()) | 299 if (bridge->client()) |
| 298 bridge->client()->didReceiveBinaryMessage(std::move(payload)); | 300 bridge->client()->didReceiveBinaryMessage(std::move(payload)); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void Peer::didReceiveBinaryMessage(PassOwnPtr<Vector<char>> payload) | 303 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) |
| 302 { | 304 { |
| 303 ASSERT(isMainThread()); | 305 ASSERT(isMainThread()); |
| 304 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payload)))); | 306 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob
alScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payload)))); |
| 305 } | 307 } |
| 306 | 308 |
| 307 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c
onsumed, ExecutionContext* context) | 309 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c
onsumed, ExecutionContext* context) |
| 308 { | 310 { |
| 309 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 311 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
| 310 if (bridge->client()) | 312 if (bridge->client()) |
| 311 bridge->client()->didConsumeBufferedAmount(consumed); | 313 bridge->client()->didConsumeBufferedAmount(consumed); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 visitor->trace(m_mainWebSocketChannel); | 377 visitor->trace(m_mainWebSocketChannel); |
| 376 visitor->trace(m_syncHelper); | 378 visitor->trace(m_syncHelper); |
| 377 WebSocketChannelClient::trace(visitor); | 379 WebSocketChannelClient::trace(visitor); |
| 378 WorkerThreadLifecycleObserver::trace(visitor); | 380 WorkerThreadLifecycleObserver::trace(visitor); |
| 379 } | 381 } |
| 380 | 382 |
| 381 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc
ope) | 383 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc
ope) |
| 382 : m_client(client) | 384 : m_client(client) |
| 383 , m_workerGlobalScope(workerGlobalScope) | 385 , m_workerGlobalScope(workerGlobalScope) |
| 384 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) | 386 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) |
| 385 , m_syncHelper(WebSocketChannelSyncHelper::create(adoptPtr(new WaitableEvent
()))) | 387 , m_syncHelper(WebSocketChannelSyncHelper::create(wrapUnique(new WaitableEve
nt()))) |
| 386 { | 388 { |
| 387 } | 389 } |
| 388 | 390 |
| 389 Bridge::~Bridge() | 391 Bridge::~Bridge() |
| 390 { | 392 { |
| 391 ASSERT(!m_peer); | 393 ASSERT(!m_peer); |
| 392 } | 394 } |
| 393 | 395 |
| 394 void Bridge::createPeerOnMainThread(PassOwnPtr<SourceLocation> location, WorkerT
hreadLifecycleContext* workerThreadLifecycleContext, ExecutionContext* context) | 396 void Bridge::createPeerOnMainThread(std::unique_ptr<SourceLocation> location, Wo
rkerThreadLifecycleContext* workerThreadLifecycleContext, ExecutionContext* cont
ext) |
| 395 { | 397 { |
| 396 DCHECK(isMainThread()); | 398 DCHECK(isMainThread()); |
| 397 DCHECK(!m_peer); | 399 DCHECK(!m_peer); |
| 398 Peer* peer = new Peer(this, m_loaderProxy, m_syncHelper, workerThreadLifecyc
leContext); | 400 Peer* peer = new Peer(this, m_loaderProxy, m_syncHelper, workerThreadLifecyc
leContext); |
| 399 if (peer->initialize(std::move(location), context)) | 401 if (peer->initialize(std::move(location), context)) |
| 400 m_peer = peer; | 402 m_peer = peer; |
| 401 m_syncHelper->signalWorkerThread(); | 403 m_syncHelper->signalWorkerThread(); |
| 402 } | 404 } |
| 403 | 405 |
| 404 void Bridge::initialize(PassOwnPtr<SourceLocation> location) | 406 void Bridge::initialize(std::unique_ptr<SourceLocation> location) |
| 405 { | 407 { |
| 406 // Wait for completion of the task on the main thread because the connection | 408 // Wait for completion of the task on the main thread because the connection |
| 407 // must synchronously be established (see Bridge::connect). | 409 // must synchronously be established (see Bridge::connect). |
| 408 if (!waitForMethodCompletion(createCrossThreadTask(&Bridge::createPeerOnMain
Thread, wrapCrossThreadPersistent(this), passed(std::move(location)), wrapCrossT
hreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLifecycleContext()
)))) { | 410 if (!waitForMethodCompletion(createCrossThreadTask(&Bridge::createPeerOnMain
Thread, wrapCrossThreadPersistent(this), passed(std::move(location)), wrapCrossT
hreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLifecycleContext()
)))) { |
| 409 // The worker thread has been signalled to shutdown before method comple
tion. | 411 // The worker thread has been signalled to shutdown before method comple
tion. |
| 410 disconnect(); | 412 disconnect(); |
| 411 } | 413 } |
| 412 } | 414 } |
| 413 | 415 |
| 414 bool Bridge::connect(const KURL& url, const String& protocol) | 416 bool Bridge::connect(const KURL& url, const String& protocol) |
| 415 { | 417 { |
| 416 if (!m_peer) | 418 if (!m_peer) |
| 417 return false; | 419 return false; |
| 418 | 420 |
| 419 // Wait for completion of the task on the main thread because the mixed | 421 // Wait for completion of the task on the main thread because the mixed |
| 420 // content check must synchronously be conducted. | 422 // content check must synchronously be conducted. |
| 421 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::connect, wrapCross
ThreadPersistent(m_peer.get()), url, protocol))) | 423 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::connect, wrapCross
ThreadPersistent(m_peer.get()), url, protocol))) |
| 422 return false; | 424 return false; |
| 423 | 425 |
| 424 return m_syncHelper->connectRequestResult(); | 426 return m_syncHelper->connectRequestResult(); |
| 425 } | 427 } |
| 426 | 428 |
| 427 void Bridge::send(const CString& message) | 429 void Bridge::send(const CString& message) |
| 428 { | 430 { |
| 429 ASSERT(m_peer); | 431 ASSERT(m_peer); |
| 430 OwnPtr<Vector<char>> data = adoptPtr(new Vector<char>(message.length())); | 432 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len
gth())); |
| 431 if (message.length()) | 433 if (message.length()) |
| 432 memcpy(data->data(), static_cast<const char*>(message.data()), message.l
ength()); | 434 memcpy(data->data(), static_cast<const char*>(message.data()), message.l
ength()); |
| 433 | 435 |
| 434 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendTextAsCharV
ector, wrapCrossThreadPersistent(m_peer.get()), passed(std::move(data)))); | 436 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendTextAsCharV
ector, wrapCrossThreadPersistent(m_peer.get()), passed(std::move(data)))); |
| 435 } | 437 } |
| 436 | 438 |
| 437 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne
d byteLength) | 439 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne
d byteLength) |
| 438 { | 440 { |
| 439 ASSERT(m_peer); | 441 ASSERT(m_peer); |
| 440 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied
into Vector<char>. | 442 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied
into Vector<char>. |
| 441 OwnPtr<Vector<char>> data = adoptPtr(new Vector<char>(byteLength)); | 443 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(byteLength)
); |
| 442 if (binaryData.byteLength()) | 444 if (binaryData.byteLength()) |
| 443 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO
ffset, byteLength); | 445 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO
ffset, byteLength); |
| 444 | 446 |
| 445 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBinaryAsCha
rVector, wrapCrossThreadPersistent(m_peer.get()), passed(std::move(data)))); | 447 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBinaryAsCha
rVector, wrapCrossThreadPersistent(m_peer.get()), passed(std::move(data)))); |
| 446 } | 448 } |
| 447 | 449 |
| 448 void Bridge::send(PassRefPtr<BlobDataHandle> data) | 450 void Bridge::send(PassRefPtr<BlobDataHandle> data) |
| 449 { | 451 { |
| 450 ASSERT(m_peer); | 452 ASSERT(m_peer); |
| 451 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC
rossThreadPersistent(m_peer.get()), data)); | 453 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::sendBlob, wrapC
rossThreadPersistent(m_peer.get()), data)); |
| 452 } | 454 } |
| 453 | 455 |
| 454 void Bridge::close(int code, const String& reason) | 456 void Bridge::close(int code, const String& reason) |
| 455 { | 457 { |
| 456 ASSERT(m_peer); | 458 ASSERT(m_peer); |
| 457 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros
sThreadPersistent(m_peer.get()), code, reason)); | 459 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::close, wrapCros
sThreadPersistent(m_peer.get()), code, reason)); |
| 458 } | 460 } |
| 459 | 461 |
| 460 void Bridge::fail(const String& reason, MessageLevel level, PassOwnPtr<SourceLoc
ation> location) | 462 void Bridge::fail(const String& reason, MessageLevel level, std::unique_ptr<Sour
ceLocation> location) |
| 461 { | 463 { |
| 462 ASSERT(m_peer); | 464 ASSERT(m_peer); |
| 463 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross
ThreadPersistent(m_peer.get()), reason, level, passed(std::move(location)))); | 465 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&Peer::fail, wrapCross
ThreadPersistent(m_peer.get()), reason, level, passed(std::move(location)))); |
| 464 } | 466 } |
| 465 | 467 |
| 466 void Bridge::disconnect() | 468 void Bridge::disconnect() |
| 467 { | 469 { |
| 468 if (!m_peer) | 470 if (!m_peer) |
| 469 return; | 471 return; |
| 470 | 472 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 497 } | 499 } |
| 498 | 500 |
| 499 DEFINE_TRACE(Bridge) | 501 DEFINE_TRACE(Bridge) |
| 500 { | 502 { |
| 501 visitor->trace(m_client); | 503 visitor->trace(m_client); |
| 502 visitor->trace(m_workerGlobalScope); | 504 visitor->trace(m_workerGlobalScope); |
| 503 visitor->trace(m_syncHelper); | 505 visitor->trace(m_syncHelper); |
| 504 } | 506 } |
| 505 | 507 |
| 506 } // namespace blink | 508 } // namespace blink |
| OLD | NEW |