OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/socket_api.h" | 5 #include "extensions/browser/api/socket/socket_api.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 SocketWriteFunction::SocketWriteFunction() | 532 SocketWriteFunction::SocketWriteFunction() |
533 : socket_id_(0), io_buffer_(NULL), io_buffer_size_(0) {} | 533 : socket_id_(0), io_buffer_(NULL), io_buffer_size_(0) {} |
534 | 534 |
535 SocketWriteFunction::~SocketWriteFunction() {} | 535 SocketWriteFunction::~SocketWriteFunction() {} |
536 | 536 |
537 bool SocketWriteFunction::Prepare() { | 537 bool SocketWriteFunction::Prepare() { |
538 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); | 538 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); |
539 base::Value* data = NULL; | 539 base::Value* data = NULL; |
540 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(1, &data)); | 540 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(1, &data)); |
541 | 541 |
542 io_buffer_size_ = data->GetSize(); | 542 io_buffer_size_ = data->GetBlob().size(); |
543 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); | 543 io_buffer_ = new net::WrappedIOBuffer(data->GetBlob().data()); |
544 return true; | 544 return true; |
545 } | 545 } |
546 | 546 |
547 void SocketWriteFunction::AsyncWorkStart() { | 547 void SocketWriteFunction::AsyncWorkStart() { |
548 Socket* socket = GetSocket(socket_id_); | 548 Socket* socket = GetSocket(socket_id_); |
549 | 549 |
550 if (!socket) { | 550 if (!socket) { |
551 error_ = kSocketNotFoundError; | 551 error_ = kSocketNotFoundError; |
552 OnCompleted(-1); | 552 OnCompleted(-1); |
553 return; | 553 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(1, &data)); | 620 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(1, &data)); |
621 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &hostname_)); | 621 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &hostname_)); |
622 int port; | 622 int port; |
623 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(3, &port)); | 623 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(3, &port)); |
624 if (!IsPortValid(port)) { | 624 if (!IsPortValid(port)) { |
625 error_ = kPortInvalidError; | 625 error_ = kPortInvalidError; |
626 return false; | 626 return false; |
627 } | 627 } |
628 port_ = static_cast<uint16_t>(port); | 628 port_ = static_cast<uint16_t>(port); |
629 | 629 |
630 io_buffer_size_ = data->GetSize(); | 630 io_buffer_size_ = data->GetBlob().size(); |
631 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); | 631 io_buffer_ = new net::WrappedIOBuffer(data->GetBlob().data()); |
632 return true; | 632 return true; |
633 } | 633 } |
634 | 634 |
635 void SocketSendToFunction::AsyncWorkStart() { | 635 void SocketSendToFunction::AsyncWorkStart() { |
636 Socket* socket = GetSocket(socket_id_); | 636 Socket* socket = GetSocket(socket_id_); |
637 if (!socket) { | 637 if (!socket) { |
638 error_ = kSocketNotFoundError; | 638 error_ = kSocketNotFoundError; |
639 SetResult(base::MakeUnique<base::Value>(-1)); | 639 SetResult(base::MakeUnique<base::Value>(-1)); |
640 AsyncWorkCompleted(); | 640 AsyncWorkCompleted(); |
641 return; | 641 return; |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 } else { | 1087 } else { |
1088 RemoveSocket(params_->socket_id); | 1088 RemoveSocket(params_->socket_id); |
1089 error_ = net::ErrorToString(result); | 1089 error_ = net::ErrorToString(result); |
1090 } | 1090 } |
1091 | 1091 |
1092 results_ = api::socket::Secure::Results::Create(result); | 1092 results_ = api::socket::Secure::Results::Create(result); |
1093 AsyncWorkCompleted(); | 1093 AsyncWorkCompleted(); |
1094 } | 1094 } |
1095 | 1095 |
1096 } // namespace extensions | 1096 } // namespace extensions |
OLD | NEW |