Chromium Code Reviews| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) | 98 WorkerWebSocketChannel::WorkerWebSocketChannel(WorkerGlobalScope& workerGlobalSc ope, WebSocketChannelClient* client, std::unique_ptr<SourceLocation> location) |
| 99 : m_bridge(new Bridge(client, workerGlobalScope)) | 99 : m_bridge(new Bridge(client, workerGlobalScope)) |
| 100 , m_locationAtConnection(std::move(location)) | 100 , m_locationAtConnection(std::move(location)) |
| 101 { | 101 { |
| 102 } | 102 } |
| 103 | 103 |
| 104 WorkerWebSocketChannel::~WorkerWebSocketChannel() | 104 WorkerWebSocketChannel::~WorkerWebSocketChannel() |
| 105 { | 105 { |
| 106 ASSERT(!m_bridge); | 106 DCHECK(!m_bridge); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) | 109 bool WorkerWebSocketChannel::connect(const KURL& url, const String& protocol) |
| 110 { | 110 { |
| 111 ASSERT(m_bridge); | 111 DCHECK(m_bridge); |
| 112 return m_bridge->connect(m_locationAtConnection->clone(), url, protocol); | 112 return m_bridge->connect(m_locationAtConnection->clone(), url, protocol); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void WorkerWebSocketChannel::send(const CString& message) | 115 void WorkerWebSocketChannel::send(const CString& message) |
| 116 { | 116 { |
| 117 ASSERT(m_bridge); | 117 DCHECK(m_bridge); |
| 118 m_bridge->send(message); | 118 m_bridge->send(message); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength) | 121 void WorkerWebSocketChannel::send(const DOMArrayBuffer& binaryData, unsigned byt eOffset, unsigned byteLength) |
| 122 { | 122 { |
| 123 ASSERT(m_bridge); | 123 DCHECK(m_bridge); |
| 124 m_bridge->send(binaryData, byteOffset, byteLength); | 124 m_bridge->send(binaryData, byteOffset, byteLength); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void WorkerWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobData) | 127 void WorkerWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobData) |
| 128 { | 128 { |
| 129 ASSERT(m_bridge); | 129 DCHECK(m_bridge); |
| 130 m_bridge->send(std::move(blobData)); | 130 m_bridge->send(std::move(blobData)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void WorkerWebSocketChannel::close(int code, const String& reason) | 133 void WorkerWebSocketChannel::close(int code, const String& reason) |
| 134 { | 134 { |
| 135 ASSERT(m_bridge); | 135 DCHECK(m_bridge); |
| 136 m_bridge->close(code, reason); | 136 m_bridge->close(code, reason); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, std: :unique_ptr<SourceLocation> location) | 139 void WorkerWebSocketChannel::fail(const String& reason, MessageLevel level, std: :unique_ptr<SourceLocation> location) |
| 140 { | 140 { |
| 141 if (!m_bridge) | 141 if (!m_bridge) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 std::unique_ptr<SourceLocation> capturedLocation = SourceLocation::capture() ; | 144 std::unique_ptr<SourceLocation> capturedLocation = SourceLocation::capture() ; |
| 145 if (!capturedLocation->isUnknown()) { | 145 if (!capturedLocation->isUnknown()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 DCHECK(isMainThread()); | 177 DCHECK(isMainThread()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 Peer::~Peer() | 180 Peer::~Peer() |
| 181 { | 181 { |
| 182 DCHECK(isMainThread()); | 182 DCHECK(isMainThread()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context) | 185 bool Peer::initialize(std::unique_ptr<SourceLocation> location, ExecutionContext * context) |
| 186 { | 186 { |
| 187 ASSERT(isMainThread()); | 187 DCHECK(isMainThread()); |
| 188 if (wasContextDestroyedBeforeObserverCreation()) | 188 if (wasContextDestroyedBeforeObserverCreation()) |
| 189 return false; | 189 return false; |
| 190 Document* document = toDocument(context); | 190 Document* document = toDocument(context); |
| 191 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location)); | 191 m_mainWebSocketChannel = DocumentWebSocketChannel::create(document, this, st d::move(location)); |
| 192 return true; | 192 return true; |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool Peer::connect(const KURL& url, const String& protocol) | 195 bool Peer::connect(const KURL& url, const String& protocol) |
| 196 { | 196 { |
| 197 ASSERT(isMainThread()); | 197 DCHECK(isMainThread()); |
| 198 if (!m_mainWebSocketChannel) | 198 if (!m_mainWebSocketChannel) |
| 199 return false; | 199 return false; |
| 200 return m_mainWebSocketChannel->connect(url, protocol); | 200 return m_mainWebSocketChannel->connect(url, protocol); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) | 203 void Peer::sendTextAsCharVector(std::unique_ptr<Vector<char>> data) |
| 204 { | 204 { |
| 205 ASSERT(isMainThread()); | 205 DCHECK(isMainThread()); |
| 206 if (m_mainWebSocketChannel) | 206 if (m_mainWebSocketChannel) |
| 207 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); | 207 m_mainWebSocketChannel->sendTextAsCharVector(std::move(data)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) | 210 void Peer::sendBinaryAsCharVector(std::unique_ptr<Vector<char>> data) |
| 211 { | 211 { |
| 212 ASSERT(isMainThread()); | 212 DCHECK(isMainThread()); |
| 213 if (m_mainWebSocketChannel) | 213 if (m_mainWebSocketChannel) |
| 214 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data)); | 214 m_mainWebSocketChannel->sendBinaryAsCharVector(std::move(data)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) | 217 void Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) |
| 218 { | 218 { |
| 219 ASSERT(isMainThread()); | 219 DCHECK(isMainThread()); |
| 220 if (m_mainWebSocketChannel) | 220 if (m_mainWebSocketChannel) |
| 221 m_mainWebSocketChannel->send(std::move(blobData)); | 221 m_mainWebSocketChannel->send(std::move(blobData)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void Peer::close(int code, const String& reason) | 224 void Peer::close(int code, const String& reason) |
| 225 { | 225 { |
| 226 ASSERT(isMainThread()); | 226 DCHECK(isMainThread()); |
| 227 if (!m_mainWebSocketChannel) | 227 if (!m_mainWebSocketChannel) |
| 228 return; | 228 return; |
| 229 m_mainWebSocketChannel->close(code, reason); | 229 m_mainWebSocketChannel->close(code, reason); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void Peer::fail(const String& reason, MessageLevel level, std::unique_ptr<Source Location> location) | 232 void Peer::fail(const String& reason, MessageLevel level, std::unique_ptr<Source Location> location) |
| 233 { | 233 { |
| 234 ASSERT(isMainThread()); | 234 DCHECK(isMainThread()); |
| 235 if (!m_mainWebSocketChannel) | 235 if (!m_mainWebSocketChannel) |
| 236 return; | 236 return; |
| 237 m_mainWebSocketChannel->fail(reason, level, std::move(location)); | 237 m_mainWebSocketChannel->fail(reason, level, std::move(location)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void Peer::disconnect() | 240 void Peer::disconnect() |
| 241 { | 241 { |
| 242 ASSERT(isMainThread()); | 242 DCHECK(isMainThread()); |
| 243 if (!m_mainWebSocketChannel) | 243 if (!m_mainWebSocketChannel) |
| 244 return; | 244 return; |
| 245 m_mainWebSocketChannel->disconnect(); | 245 m_mainWebSocketChannel->disconnect(); |
| 246 m_mainWebSocketChannel = nullptr; | 246 m_mainWebSocketChannel = nullptr; |
| 247 } | 247 } |
| 248 | 248 |
| 249 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context) | 249 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context) |
| 250 { | 250 { |
| 251 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 251 ALLOW_UNUSED_LOCAL(context); |
|
yhirano
2016/09/30 01:50:30
Is this needed?
Ditto below.
hiroshige
2016/09/30 06:04:24
Oh, ALLOW_UNUSED_LOCAL() turned to be unnecessary
| |
| 252 DCHECK(context->isWorkerGlobalScope()); | |
| 252 if (bridge && bridge->client()) | 253 if (bridge && bridge->client()) |
| 253 bridge->client()->didConnect(subprotocol, extensions); | 254 bridge->client()->didConnect(subprotocol, extensions); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void Peer::didConnect(const String& subprotocol, const String& extensions) | 257 void Peer::didConnect(const String& subprotocol, const String& extensions) |
| 257 { | 258 { |
| 258 ASSERT(isMainThread()); | 259 DCHECK(isMainThread()); |
| 259 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConnect, m_bridge, subprotocol, extensions)); | 260 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConnect, m_bridge, subprotocol, extensions)); |
| 260 } | 261 } |
| 261 | 262 |
| 262 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context) | 263 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context) |
| 263 { | 264 { |
| 264 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 265 ALLOW_UNUSED_LOCAL(context); |
| 266 DCHECK(context->isWorkerGlobalScope()); | |
| 265 if (bridge && bridge->client()) | 267 if (bridge && bridge->client()) |
| 266 bridge->client()->didReceiveTextMessage(payload); | 268 bridge->client()->didReceiveTextMessage(payload); |
| 267 } | 269 } |
| 268 | 270 |
| 269 void Peer::didReceiveTextMessage(const String& payload) | 271 void Peer::didReceiveTextMessage(const String& payload) |
| 270 { | 272 { |
| 271 ASSERT(isMainThread()); | 273 DCHECK(isMainThread()); |
| 272 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveTextMessage, m_bridge, payload)); | 274 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveTextMessage, m_bridge, payload)); |
| 273 } | 275 } |
| 274 | 276 |
| 275 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context) | 277 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context) |
| 276 { | 278 { |
| 277 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 279 ALLOW_UNUSED_LOCAL(context); |
| 280 DCHECK(context->isWorkerGlobalScope()); | |
| 278 if (bridge && bridge->client()) | 281 if (bridge && bridge->client()) |
| 279 bridge->client()->didReceiveBinaryMessage(std::move(payload)); | 282 bridge->client()->didReceiveBinaryMessage(std::move(payload)); |
| 280 } | 283 } |
| 281 | 284 |
| 282 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) | 285 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) |
| 283 { | 286 { |
| 284 ASSERT(isMainThread()); | 287 DCHECK(isMainThread()); |
| 285 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payl oad)))); | 288 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payl oad)))); |
| 286 } | 289 } |
| 287 | 290 |
| 288 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context) | 291 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context) |
| 289 { | 292 { |
| 290 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 293 ALLOW_UNUSED_LOCAL(context); |
| 294 DCHECK(context->isWorkerGlobalScope()); | |
| 291 if (bridge && bridge->client()) | 295 if (bridge && bridge->client()) |
| 292 bridge->client()->didConsumeBufferedAmount(consumed); | 296 bridge->client()->didConsumeBufferedAmount(consumed); |
| 293 } | 297 } |
| 294 | 298 |
| 295 void Peer::didConsumeBufferedAmount(uint64_t consumed) | 299 void Peer::didConsumeBufferedAmount(uint64_t consumed) |
| 296 { | 300 { |
| 297 ASSERT(isMainThread()); | 301 DCHECK(isMainThread()); |
| 298 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConsumeBufferedAmount, m_bridge, consumed)); | 302 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidConsumeBufferedAmount, m_bridge, consumed)); |
| 299 } | 303 } |
| 300 | 304 |
| 301 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context) | 305 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context) |
| 302 { | 306 { |
| 303 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 307 ALLOW_UNUSED_LOCAL(context); |
| 308 DCHECK(context->isWorkerGlobalScope()); | |
| 304 if (bridge && bridge->client()) | 309 if (bridge && bridge->client()) |
| 305 bridge->client()->didStartClosingHandshake(); | 310 bridge->client()->didStartClosingHandshake(); |
| 306 } | 311 } |
| 307 | 312 |
| 308 void Peer::didStartClosingHandshake() | 313 void Peer::didStartClosingHandshake() |
| 309 { | 314 { |
| 310 ASSERT(isMainThread()); | 315 DCHECK(isMainThread()); |
| 311 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidStartClosingHandshake, m_bridge)); | 316 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidStartClosingHandshake, m_bridge)); |
| 312 } | 317 } |
| 313 | 318 |
| 314 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context) | 319 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context) |
| 315 { | 320 { |
| 316 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 321 ALLOW_UNUSED_LOCAL(context); |
| 322 DCHECK(context->isWorkerGlobalScope()); | |
| 317 if (bridge && bridge->client()) | 323 if (bridge && bridge->client()) |
| 318 bridge->client()->didClose(closingHandshakeCompletion, code, reason); | 324 bridge->client()->didClose(closingHandshakeCompletion, code, reason); |
| 319 } | 325 } |
| 320 | 326 |
| 321 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) | 327 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) |
| 322 { | 328 { |
| 323 ASSERT(isMainThread()); | 329 DCHECK(isMainThread()); |
| 324 if (m_mainWebSocketChannel) { | 330 if (m_mainWebSocketChannel) { |
| 325 m_mainWebSocketChannel->disconnect(); | 331 m_mainWebSocketChannel->disconnect(); |
| 326 m_mainWebSocketChannel = nullptr; | 332 m_mainWebSocketChannel = nullptr; |
| 327 } | 333 } |
| 328 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidClose, m_bridge, closingHandshakeCompletion, code, re ason)); | 334 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidClose, m_bridge, closingHandshakeCompletion, code, re ason)); |
| 329 } | 335 } |
| 330 | 336 |
| 331 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context) | 337 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context) |
| 332 { | 338 { |
| 333 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 339 ALLOW_UNUSED_LOCAL(context); |
| 340 DCHECK(context->isWorkerGlobalScope()); | |
| 334 if (bridge && bridge->client()) | 341 if (bridge && bridge->client()) |
| 335 bridge->client()->didError(); | 342 bridge->client()->didError(); |
| 336 } | 343 } |
| 337 | 344 |
| 338 void Peer::didError() | 345 void Peer::didError() |
| 339 { | 346 { |
| 340 ASSERT(isMainThread()); | 347 DCHECK(isMainThread()); |
| 341 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge)); | 348 m_loaderProxy->postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThrea dTask(&workerGlobalScopeDidError, m_bridge)); |
| 342 } | 349 } |
| 343 | 350 |
| 344 void Peer::contextDestroyed() | 351 void Peer::contextDestroyed() |
| 345 { | 352 { |
| 346 DCHECK(isMainThread()); | 353 DCHECK(isMainThread()); |
| 347 if (m_mainWebSocketChannel) { | 354 if (m_mainWebSocketChannel) { |
| 348 m_mainWebSocketChannel->disconnect(); | 355 m_mainWebSocketChannel->disconnect(); |
| 349 m_mainWebSocketChannel = nullptr; | 356 m_mainWebSocketChannel = nullptr; |
| 350 } | 357 } |
| 351 m_bridge = nullptr; | 358 m_bridge = nullptr; |
| 352 } | 359 } |
| 353 | 360 |
| 354 DEFINE_TRACE(Peer) | 361 DEFINE_TRACE(Peer) |
| 355 { | 362 { |
| 356 visitor->trace(m_mainWebSocketChannel); | 363 visitor->trace(m_mainWebSocketChannel); |
| 357 WebSocketChannelClient::trace(visitor); | 364 WebSocketChannelClient::trace(visitor); |
| 358 WorkerThreadLifecycleObserver::trace(visitor); | 365 WorkerThreadLifecycleObserver::trace(visitor); |
| 359 } | 366 } |
| 360 | 367 |
| 361 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc ope) | 368 Bridge::Bridge(WebSocketChannelClient* client, WorkerGlobalScope& workerGlobalSc ope) |
| 362 : m_client(client) | 369 : m_client(client) |
| 363 , m_workerGlobalScope(workerGlobalScope) | 370 , m_workerGlobalScope(workerGlobalScope) |
| 364 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) | 371 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) |
| 365 { | 372 { |
| 366 } | 373 } |
| 367 | 374 |
| 368 Bridge::~Bridge() | 375 Bridge::~Bridge() |
| 369 { | 376 { |
| 370 ASSERT(!m_peer); | 377 DCHECK(!m_peer); |
| 371 } | 378 } |
| 372 | 379 |
| 373 void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, Worke rThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const St ring& protocol, WebSocketChannelSyncHelper* syncHelper, ExecutionContext* contex t) | 380 void Bridge::connectOnMainThread(std::unique_ptr<SourceLocation> location, Worke rThreadLifecycleContext* workerThreadLifecycleContext, const KURL& url, const St ring& protocol, WebSocketChannelSyncHelper* syncHelper, ExecutionContext* contex t) |
| 374 { | 381 { |
| 375 DCHECK(isMainThread()); | 382 DCHECK(isMainThread()); |
| 376 DCHECK(!m_peer); | 383 DCHECK(!m_peer); |
| 377 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext); | 384 Peer* peer = new Peer(this, m_loaderProxy, workerThreadLifecycleContext); |
| 378 if (peer->initialize(std::move(location), context)) { | 385 if (peer->initialize(std::move(location), context)) { |
| 379 m_peer = peer; | 386 m_peer = peer; |
| 380 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol)); | 387 syncHelper->setConnectRequestResult(m_peer->connect(url, protocol)); |
| 381 } | 388 } |
| 382 syncHelper->signalWorkerThread(); | 389 syncHelper->signalWorkerThread(); |
| 383 } | 390 } |
| 384 | 391 |
| 385 bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol) | 392 bool Bridge::connect(std::unique_ptr<SourceLocation> location, const KURL& url, const String& protocol) |
| 386 { | 393 { |
| 387 // Wait for completion of the task on the main thread because the mixed | 394 // Wait for completion of the task on the main thread because the mixed |
| 388 // content check must synchronously be conducted. | 395 // content check must synchronously be conducted. |
| 389 WebSocketChannelSyncHelper syncHelper; | 396 WebSocketChannelSyncHelper syncHelper; |
| 390 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Brid ge::connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone ()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLif ecycleContext()), url, protocol, crossThreadUnretained(&syncHelper))); | 397 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Brid ge::connectOnMainThread, wrapCrossThreadPersistent(this), passed(location->clone ()), wrapCrossThreadPersistent(m_workerGlobalScope->thread()->getWorkerThreadLif ecycleContext()), url, protocol, crossThreadUnretained(&syncHelper))); |
| 391 syncHelper.wait(); | 398 syncHelper.wait(); |
| 392 return syncHelper.connectRequestResult(); | 399 return syncHelper.connectRequestResult(); |
| 393 } | 400 } |
| 394 | 401 |
| 395 void Bridge::send(const CString& message) | 402 void Bridge::send(const CString& message) |
| 396 { | 403 { |
| 397 ASSERT(m_peer); | 404 DCHECK(m_peer); |
| 398 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth())); | 405 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(message.len gth())); |
| 399 if (message.length()) | 406 if (message.length()) |
| 400 memcpy(data->data(), static_cast<const char*>(message.data()), message.l ength()); | 407 memcpy(data->data(), static_cast<const char*>(message.data()), message.l ength()); |
| 401 | 408 |
| 402 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendTextAsCharVector, m_peer, passed(std::move(data)))); | 409 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendTextAsCharVector, m_peer, passed(std::move(data)))); |
| 403 } | 410 } |
| 404 | 411 |
| 405 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne d byteLength) | 412 void Bridge::send(const DOMArrayBuffer& binaryData, unsigned byteOffset, unsigne d byteLength) |
| 406 { | 413 { |
| 407 ASSERT(m_peer); | 414 DCHECK(m_peer); |
| 408 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>. | 415 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied into Vector<char>. |
| 409 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(byteLength) ); | 416 std::unique_ptr<Vector<char>> data = wrapUnique(new Vector<char>(byteLength) ); |
| 410 if (binaryData.byteLength()) | 417 if (binaryData.byteLength()) |
| 411 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength); | 418 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO ffset, byteLength); |
| 412 | 419 |
| 413 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBinaryAsCharVector, m_peer, passed(std::move(data)))); | 420 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBinaryAsCharVector, m_peer, passed(std::move(data)))); |
| 414 } | 421 } |
| 415 | 422 |
| 416 void Bridge::send(PassRefPtr<BlobDataHandle> data) | 423 void Bridge::send(PassRefPtr<BlobDataHandle> data) |
| 417 { | 424 { |
| 418 ASSERT(m_peer); | 425 DCHECK(m_peer); |
| 419 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBlob, m_peer, std::move(data))); | 426 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::sendBlob, m_peer, std::move(data))); |
| 420 } | 427 } |
| 421 | 428 |
| 422 void Bridge::close(int code, const String& reason) | 429 void Bridge::close(int code, const String& reason) |
| 423 { | 430 { |
| 424 ASSERT(m_peer); | 431 DCHECK(m_peer); |
| 425 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::close, m_peer, code, reason)); | 432 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::close, m_peer, code, reason)); |
| 426 } | 433 } |
| 427 | 434 |
| 428 void Bridge::fail(const String& reason, MessageLevel level, std::unique_ptr<Sour ceLocation> location) | 435 void Bridge::fail(const String& reason, MessageLevel level, std::unique_ptr<Sour ceLocation> location) |
| 429 { | 436 { |
| 430 ASSERT(m_peer); | 437 DCHECK(m_peer); |
| 431 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::fail, m_peer, reason, level, passed(location->clone()))); | 438 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::fail, m_peer, reason, level, passed(location->clone()))); |
| 432 } | 439 } |
| 433 | 440 |
| 434 void Bridge::disconnect() | 441 void Bridge::disconnect() |
| 435 { | 442 { |
| 436 if (!m_peer) | 443 if (!m_peer) |
| 437 return; | 444 return; |
| 438 | 445 |
| 439 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::disconnect, m_peer)); | 446 m_loaderProxy->postTaskToLoader(BLINK_FROM_HERE, createCrossThreadTask(&Peer ::disconnect, m_peer)); |
| 440 | 447 |
| 441 m_client = nullptr; | 448 m_client = nullptr; |
| 442 m_peer = nullptr; | 449 m_peer = nullptr; |
| 443 m_workerGlobalScope.clear(); | 450 m_workerGlobalScope.clear(); |
| 444 } | 451 } |
| 445 | 452 |
| 446 DEFINE_TRACE(Bridge) | 453 DEFINE_TRACE(Bridge) |
| 447 { | 454 { |
| 448 visitor->trace(m_client); | 455 visitor->trace(m_client); |
| 449 visitor->trace(m_workerGlobalScope); | 456 visitor->trace(m_workerGlobalScope); |
| 450 } | 457 } |
| 451 | 458 |
| 452 } // namespace blink | 459 } // namespace blink |
| OLD | NEW |