Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/plugins/ppapi/ppb_websocket_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_websocket_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 close_was_clean_ = was_clean ? PP_TRUE : PP_FALSE; | 495 close_was_clean_ = was_clean ? PP_TRUE : PP_FALSE; |
| 496 | 496 |
| 497 // Update buffered_amount_. | 497 // Update buffered_amount_. |
| 498 buffered_amount_ = unhandled_buffered_amount; | 498 buffered_amount_ = unhandled_buffered_amount; |
| 499 | 499 |
| 500 // Handle state transition and invoking callback. | 500 // Handle state transition and invoking callback. |
| 501 DCHECK_NE(PP_WEBSOCKETREADYSTATE_CLOSED, state_); | 501 DCHECK_NE(PP_WEBSOCKETREADYSTATE_CLOSED, state_); |
| 502 PP_WebSocketReadyState state = state_; | 502 PP_WebSocketReadyState state = state_; |
| 503 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; | 503 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; |
| 504 | 504 |
| 505 if (state == PP_WEBSOCKETREADYSTATE_CONNECTING) | 505 const base::WeakPtr<PPB_WebSocket_Impl> weak_ptr = AsWeakPtr(); |
|
dmichael (off chromium)
2012/06/25 15:50:51
Another option might be to just take a reference f
Takashi Toyoshima
2012/06/26 09:19:10
If I took a reference of this here, I can continue
dmichael (off chromium)
2012/06/26 16:01:40
Are you sure? We keep 2 separate reference counts;
Takashi Toyoshima
2012/06/27 08:09:05
Thank you.
I didn't understand TrackedCallback co
| |
| 506 if (state == PP_WEBSOCKETREADYSTATE_CONNECTING) { | |
| 506 TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED); | 507 TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED); |
| 508 if (!weak_ptr) | |
| 509 return; | |
| 510 } | |
| 507 | 511 |
| 508 if (wait_for_receive_) { | 512 if (wait_for_receive_) { |
| 509 wait_for_receive_ = false; | 513 wait_for_receive_ = false; |
| 510 receive_callback_var_ = NULL; | 514 receive_callback_var_ = NULL; |
| 511 TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED); | 515 TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED); |
| 516 if (!weak_ptr) | |
| 517 return; | |
| 512 } | 518 } |
| 513 | 519 |
| 514 if ((state == PP_WEBSOCKETREADYSTATE_CLOSING) && close_callback_.get()) | 520 if ((state == PP_WEBSOCKETREADYSTATE_CLOSING) && close_callback_.get()) { |
| 515 TrackedCallback::ClearAndRun(&close_callback_, PP_OK); | 521 TrackedCallback::ClearAndRun(&close_callback_, PP_OK); |
| 522 if (!weak_ptr) | |
| 523 return; | |
| 524 } | |
| 516 | 525 |
| 517 // Disconnect. | 526 // Disconnect. |
| 518 if (websocket_.get()) | 527 if (websocket_.get()) |
| 519 websocket_->disconnect(); | 528 websocket_->disconnect(); |
| 520 } | 529 } |
| 521 | 530 |
| 522 int32_t PPB_WebSocket_Impl::DoReceive() { | 531 int32_t PPB_WebSocket_Impl::DoReceive() { |
| 523 if (!receive_callback_var_) | 532 if (!receive_callback_var_) |
| 524 return PP_OK; | 533 return PP_OK; |
| 525 | 534 |
| 526 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 535 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
| 527 received_messages_.pop(); | 536 received_messages_.pop(); |
| 528 receive_callback_var_ = NULL; | 537 receive_callback_var_ = NULL; |
| 529 wait_for_receive_ = false; | 538 wait_for_receive_ = false; |
| 530 return PP_OK; | 539 return PP_OK; |
| 531 } | 540 } |
| 532 | 541 |
| 533 } // namespace ppapi | 542 } // namespace ppapi |
| 534 } // namespace webkit | 543 } // namespace webkit |
| OLD | NEW |