| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 disconnect(); | 490 disconnect(); |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 bool WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const St
ring& protocol) | 494 bool WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const St
ring& protocol) |
| 495 { | 495 { |
| 496 if (hasTerminatedPeer()) | 496 if (hasTerminatedPeer()) |
| 497 return false; | 497 return false; |
| 498 | 498 |
| 499 RefPtrWillBeRawPtr<Bridge> protect(this); | 499 RefPtrWillBeRawPtr<Bridge> protect(this); |
| 500 // It is important to seprate task creation from calling | 500 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::connect, m_peer, u
rl, protocol))) |
| 501 // waitForMethodCompletion. See the above comment. | |
| 502 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::conn
ect, m_peer, url.copy(), protocol.isolatedCopy())); | |
| 503 if (!waitForMethodCompletion(task.release())) | |
| 504 return false; | 501 return false; |
| 505 | 502 |
| 506 return m_syncHelper->connectRequestResult(); | 503 return m_syncHelper->connectRequestResult(); |
| 507 } | 504 } |
| 508 | 505 |
| 509 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons
t String& message) | 506 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons
t String& message) |
| 510 { | 507 { |
| 511 if (hasTerminatedPeer()) | 508 if (hasTerminatedPeer()) |
| 512 return WebSocketChannel::SendFail; | 509 return WebSocketChannel::SendFail; |
| 513 | 510 |
| 514 RefPtrWillBeRawPtr<Bridge> protect(this); | 511 RefPtrWillBeRawPtr<Bridge> protect(this); |
| 515 // It is important to seprate task creation from calling | 512 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::send, m_peer, mess
age))) |
| 516 // waitForMethodCompletion. See the above comment. | |
| 517 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::send
, m_peer, message.isolatedCopy())); | |
| 518 if (!waitForMethodCompletion(task.release())) | |
| 519 return WebSocketChannel::SendFail; | 513 return WebSocketChannel::SendFail; |
| 520 | 514 |
| 521 return m_syncHelper->sendRequestResult(); | 515 return m_syncHelper->sendRequestResult(); |
| 522 } | 516 } |
| 523 | 517 |
| 524 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons
t ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength) | 518 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(cons
t ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength) |
| 525 { | 519 { |
| 526 if (hasTerminatedPeer()) | 520 if (hasTerminatedPeer()) |
| 527 return WebSocketChannel::SendFail; | 521 return WebSocketChannel::SendFail; |
| 528 | 522 |
| 529 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied
into Vector<char>. | 523 // ArrayBuffer isn't thread-safe, hence the content of ArrayBuffer is copied
into Vector<char>. |
| 530 OwnPtr<Vector<char> > data = adoptPtr(new Vector<char>(byteLength)); | 524 OwnPtr<Vector<char> > data = adoptPtr(new Vector<char>(byteLength)); |
| 531 if (binaryData.byteLength()) | 525 if (binaryData.byteLength()) |
| 532 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO
ffset, byteLength); | 526 memcpy(data->data(), static_cast<const char*>(binaryData.data()) + byteO
ffset, byteLength); |
| 533 | 527 |
| 534 RefPtrWillBeRawPtr<Bridge> protect(this); | 528 RefPtrWillBeRawPtr<Bridge> protect(this); |
| 535 // It is important to seprate task creation from calling | 529 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::sendArrayBuffer, m
_peer, data.release()))) |
| 536 // waitForMethodCompletion. See the above comment. | |
| 537 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::send
ArrayBuffer, m_peer, data.release())); | |
| 538 if (!waitForMethodCompletion(task.release())) | |
| 539 return WebSocketChannel::SendFail; | 530 return WebSocketChannel::SendFail; |
| 540 | 531 |
| 541 return m_syncHelper->sendRequestResult(); | 532 return m_syncHelper->sendRequestResult(); |
| 542 } | 533 } |
| 543 | 534 |
| 544 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(Pass
RefPtr<BlobDataHandle> data) | 535 WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::Bridge::send(Pass
RefPtr<BlobDataHandle> data) |
| 545 { | 536 { |
| 546 if (hasTerminatedPeer()) | 537 if (hasTerminatedPeer()) |
| 547 return WebSocketChannel::SendFail; | 538 return WebSocketChannel::SendFail; |
| 548 | 539 |
| 549 RefPtrWillBeRawPtr<Bridge> protect(this); | 540 RefPtrWillBeRawPtr<Bridge> protect(this); |
| 550 // It is important to seprate task creation from calling | 541 if (!waitForMethodCompletion(createCrossThreadTask(&Peer::sendBlob, m_peer,
data))) |
| 551 // waitForMethodCompletion. See the above comment. | |
| 552 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::send
Blob, m_peer, data)); | |
| 553 if (!waitForMethodCompletion(task.release())) | |
| 554 return WebSocketChannel::SendFail; | 542 return WebSocketChannel::SendFail; |
| 555 | 543 |
| 556 return m_syncHelper->sendRequestResult(); | 544 return m_syncHelper->sendRequestResult(); |
| 557 } | 545 } |
| 558 | 546 |
| 559 void WorkerThreadableWebSocketChannel::Bridge::close(int code, const String& rea
son) | 547 void WorkerThreadableWebSocketChannel::Bridge::close(int code, const String& rea
son) |
| 560 { | 548 { |
| 561 if (hasTerminatedPeer()) | 549 if (hasTerminatedPeer()) |
| 562 return; | 550 return; |
| 563 | 551 |
| 564 // It is important to seprate task creation from calling | 552 m_loaderProxy.postTaskToLoader(createCrossThreadTask(&Peer::close, m_peer, c
ode, reason)); |
| 565 // waitForMethodCompletion. See the above comment. | |
| 566 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::clos
e, m_peer, code, reason.isolatedCopy())); | |
| 567 m_loaderProxy.postTaskToLoader(task.release()); | |
| 568 } | 553 } |
| 569 | 554 |
| 570 void WorkerThreadableWebSocketChannel::Bridge::fail(const String& reason, Messag
eLevel level, const String& sourceURL, unsigned lineNumber) | 555 void WorkerThreadableWebSocketChannel::Bridge::fail(const String& reason, Messag
eLevel level, const String& sourceURL, unsigned lineNumber) |
| 571 { | 556 { |
| 572 if (hasTerminatedPeer()) | 557 if (hasTerminatedPeer()) |
| 573 return; | 558 return; |
| 574 | 559 |
| 575 // It is important to seprate task creation from calling | 560 m_loaderProxy.postTaskToLoader(createCrossThreadTask(&Peer::fail, m_peer, re
ason, level, sourceURL, lineNumber)); |
| 576 // waitForMethodCompletion. See the above comment. | |
| 577 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::fail
, m_peer, reason.isolatedCopy(), level, sourceURL.isolatedCopy(), lineNumber)); | |
| 578 m_loaderProxy.postTaskToLoader(task.release()); | |
| 579 } | 561 } |
| 580 | 562 |
| 581 void WorkerThreadableWebSocketChannel::Bridge::disconnect() | 563 void WorkerThreadableWebSocketChannel::Bridge::disconnect() |
| 582 { | 564 { |
| 583 if (hasTerminatedPeer()) | 565 if (hasTerminatedPeer()) |
| 584 return; | 566 return; |
| 585 | 567 |
| 586 clearClientWrapper(); | 568 clearClientWrapper(); |
| 587 terminatePeer(); | 569 terminatePeer(); |
| 588 } | 570 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 608 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); | 590 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); |
| 609 blink::Platform::current()->waitMultipleEvents(events); | 591 blink::Platform::current()->waitMultipleEvents(events); |
| 610 // This is checking whether a shutdown event is fired or not. | 592 // This is checking whether a shutdown event is fired or not. |
| 611 return !m_workerGlobalScope->thread()->runLoop().terminated(); | 593 return !m_workerGlobalScope->thread()->runLoop().terminated(); |
| 612 } | 594 } |
| 613 | 595 |
| 614 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer() | 596 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer() |
| 615 { | 597 { |
| 616 ASSERT(!hasTerminatedPeer()); | 598 ASSERT(!hasTerminatedPeer()); |
| 617 | 599 |
| 618 // It is important to seprate task creation from calling | |
| 619 // waitForMethodCompletion. See the above comment. | |
| 620 OwnPtr<ExecutionContextTask> task = CallClosureTask::create(bind(&Peer::dest
roy, m_peer)); | |
| 621 #if ENABLE(OILPAN) | 600 #if ENABLE(OILPAN) |
| 622 // The worker thread has to wait for the main thread to complete Peer::destr
oy, | 601 // The worker thread has to wait for the main thread to complete Peer::destr
oy, |
| 623 // because the worker thread has to make sure that the main thread does not
have any | 602 // because the worker thread has to make sure that the main thread does not
have any |
| 624 // references to on-heap objects allocated in the thread heap of the worker
thread | 603 // references to on-heap objects allocated in the thread heap of the worker
thread |
| 625 // before the worker thread shuts down. | 604 // before the worker thread shuts down. |
| 626 waitForMethodCompletion(task.release()); | 605 waitForMethodCompletion(createCrossThreadTask(&Peer::destroy, m_peer)); |
| 627 #else | 606 #else |
| 628 m_loaderProxy.postTaskToLoader(task.release()); | 607 m_loaderProxy.postTaskToLoader(createCrossThreadTask(&Peer::destroy, m_peer)
); |
| 629 #endif | 608 #endif |
| 630 | 609 |
| 631 // Peer::destroy() deletes m_peer and then m_syncHelper will be released. | 610 // Peer::destroy() deletes m_peer and then m_syncHelper will be released. |
| 632 // We must not touch m_syncHelper any more. | 611 // We must not touch m_syncHelper any more. |
| 633 m_syncHelper = nullptr; | 612 m_syncHelper = nullptr; |
| 634 | 613 |
| 635 // We won't use this any more. | 614 // We won't use this any more. |
| 636 m_workerGlobalScope = nullptr; | 615 m_workerGlobalScope = nullptr; |
| 637 } | 616 } |
| 638 | 617 |
| 639 void WorkerThreadableWebSocketChannel::Bridge::trace(Visitor* visitor) | 618 void WorkerThreadableWebSocketChannel::Bridge::trace(Visitor* visitor) |
| 640 { | 619 { |
| 641 visitor->trace(m_workerClientWrapper); | 620 visitor->trace(m_workerClientWrapper); |
| 642 visitor->trace(m_workerGlobalScope); | 621 visitor->trace(m_workerGlobalScope); |
| 643 visitor->trace(m_syncHelper); | 622 visitor->trace(m_syncHelper); |
| 644 visitor->trace(m_peer); | 623 visitor->trace(m_peer); |
| 645 } | 624 } |
| 646 | 625 |
| 647 } // namespace WebCore | 626 } // namespace WebCore |
| OLD | NEW |