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 "ppapi/proxy/websocket_resource.h" | 5 #include "ppapi/proxy/websocket_resource.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 const std::string& protocol) { | 364 const std::string& protocol) { |
365 if (!TrackedCallback::IsPending(connect_callback_)) | 365 if (!TrackedCallback::IsPending(connect_callback_)) |
366 return; | 366 return; |
367 | 367 |
368 int32_t result = params.result(); | 368 int32_t result = params.result(); |
369 if (result == PP_OK) { | 369 if (result == PP_OK) { |
370 state_ = PP_WEBSOCKETREADYSTATE_OPEN; | 370 state_ = PP_WEBSOCKETREADYSTATE_OPEN; |
371 protocol_ = new StringVar(protocol); | 371 protocol_ = new StringVar(protocol); |
372 url_ = new StringVar(url); | 372 url_ = new StringVar(url); |
373 } | 373 } |
374 TrackedCallback::ClearAndRun(&connect_callback_, params.result()); | 374 connect_callback_->Run(params.result()); |
375 } | 375 } |
376 | 376 |
377 void WebSocketResource::OnPluginMsgCloseReply( | 377 void WebSocketResource::OnPluginMsgCloseReply( |
378 const ResourceMessageReplyParams& params, | 378 const ResourceMessageReplyParams& params, |
379 unsigned long buffered_amount, | 379 unsigned long buffered_amount, |
380 bool was_clean, | 380 bool was_clean, |
381 unsigned short code, | 381 unsigned short code, |
382 const std::string& reason) { | 382 const std::string& reason) { |
383 // Set close related properties. | 383 // Set close related properties. |
384 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; | 384 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; |
(...skipping 20 matching lines...) Expand all Loading... |
405 // Dispose packets after receiving an error or in invalid state. | 405 // Dispose packets after receiving an error or in invalid state. |
406 if (error_was_received_ || !InValidStateToReceive(state_)) | 406 if (error_was_received_ || !InValidStateToReceive(state_)) |
407 return; | 407 return; |
408 | 408 |
409 // Append received data to queue. | 409 // Append received data to queue. |
410 received_messages_.push(scoped_refptr<Var>(new StringVar(message))); | 410 received_messages_.push(scoped_refptr<Var>(new StringVar(message))); |
411 | 411 |
412 if (!TrackedCallback::IsPending(receive_callback_)) | 412 if (!TrackedCallback::IsPending(receive_callback_)) |
413 return; | 413 return; |
414 | 414 |
415 TrackedCallback::ClearAndRun(&receive_callback_, DoReceive()); | 415 receive_callback_->Run(DoReceive()); |
416 } | 416 } |
417 | 417 |
418 void WebSocketResource::OnPluginMsgReceiveBinaryReply( | 418 void WebSocketResource::OnPluginMsgReceiveBinaryReply( |
419 const ResourceMessageReplyParams& params, | 419 const ResourceMessageReplyParams& params, |
420 const std::vector<uint8_t>& message) { | 420 const std::vector<uint8_t>& message) { |
421 // Dispose packets after receiving an error or in invalid state. | 421 // Dispose packets after receiving an error or in invalid state. |
422 if (error_was_received_ || !InValidStateToReceive(state_)) | 422 if (error_was_received_ || !InValidStateToReceive(state_)) |
423 return; | 423 return; |
424 | 424 |
425 // Append received data to queue. | 425 // Append received data to queue. |
426 scoped_refptr<Var> message_var(ArrayBufferVar::FromPPVar( | 426 scoped_refptr<Var> message_var(ArrayBufferVar::FromPPVar( |
427 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 427 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
428 message.size(), | 428 message.size(), |
429 &message.front()))); | 429 &message.front()))); |
430 received_messages_.push(message_var); | 430 received_messages_.push(message_var); |
431 | 431 |
432 if (!TrackedCallback::IsPending(receive_callback_)) | 432 if (!TrackedCallback::IsPending(receive_callback_)) |
433 return; | 433 return; |
434 | 434 |
435 TrackedCallback::ClearAndRun(&receive_callback_, DoReceive()); | 435 receive_callback_->Run(DoReceive()); |
436 } | 436 } |
437 | 437 |
438 void WebSocketResource::OnPluginMsgErrorReply( | 438 void WebSocketResource::OnPluginMsgErrorReply( |
439 const ResourceMessageReplyParams& params) { | 439 const ResourceMessageReplyParams& params) { |
440 error_was_received_ = true; | 440 error_was_received_ = true; |
441 | 441 |
442 if (!TrackedCallback::IsPending(receive_callback_)) | 442 if (!TrackedCallback::IsPending(receive_callback_)) |
443 return; | 443 return; |
444 | 444 |
445 // No more text or binary messages will be received. If there is ongoing | 445 // No more text or binary messages will be received. If there is ongoing |
446 // ReceiveMessage(), we must invoke the callback with error code here. | 446 // ReceiveMessage(), we must invoke the callback with error code here. |
447 receive_callback_var_ = NULL; | 447 receive_callback_var_ = NULL; |
448 TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED); | 448 receive_callback_->Run(PP_ERROR_FAILED); |
449 } | 449 } |
450 | 450 |
451 void WebSocketResource::OnPluginMsgBufferedAmountReply( | 451 void WebSocketResource::OnPluginMsgBufferedAmountReply( |
452 const ResourceMessageReplyParams& params, | 452 const ResourceMessageReplyParams& params, |
453 unsigned long buffered_amount) { | 453 unsigned long buffered_amount) { |
454 buffered_amount_ = buffered_amount; | 454 buffered_amount_ = buffered_amount; |
455 } | 455 } |
456 | 456 |
457 void WebSocketResource::OnPluginMsgStateReply( | 457 void WebSocketResource::OnPluginMsgStateReply( |
458 const ResourceMessageReplyParams& params, | 458 const ResourceMessageReplyParams& params, |
(...skipping 15 matching lines...) Expand all Loading... |
474 return PP_OK; | 474 return PP_OK; |
475 | 475 |
476 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 476 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
477 received_messages_.pop(); | 477 received_messages_.pop(); |
478 receive_callback_var_ = NULL; | 478 receive_callback_var_ = NULL; |
479 return PP_OK; | 479 return PP_OK; |
480 } | 480 } |
481 | 481 |
482 } // namespace proxy | 482 } // namespace proxy |
483 } // namespace ppapi | 483 } // namespace ppapi |
OLD | NEW |