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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 SocketPermission::CheckParam param(SocketPermissionRequest::TCP_LISTEN, | 439 SocketPermission::CheckParam param(SocketPermissionRequest::TCP_LISTEN, |
440 params_->address, params_->port); | 440 params_->address, params_->port); |
441 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 441 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
442 APIPermission::kSocket, ¶m)) { | 442 APIPermission::kSocket, ¶m)) { |
443 error_ = kPermissionError; | 443 error_ = kPermissionError; |
444 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 444 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); |
445 AsyncWorkCompleted(); | 445 AsyncWorkCompleted(); |
446 return; | 446 return; |
447 } | 447 } |
448 | 448 |
449 int result = socket->Listen( | 449 int result = |
450 params_->address, params_->port, | 450 socket->Listen(params_->address, params_->port, |
451 params_->backlog.get() ? *params_->backlog.get() : 5, &error_); | 451 params_->backlog.get() ? *params_->backlog : 5, &error_); |
452 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 452 SetResult(base::MakeUnique<base::FundamentalValue>(result)); |
453 if (result != net::OK) { | 453 if (result != net::OK) { |
454 AsyncWorkCompleted(); | 454 AsyncWorkCompleted(); |
455 return; | 455 return; |
456 } | 456 } |
457 | 457 |
458 OpenFirewallHole(params_->address, params_->socket_id, socket); | 458 OpenFirewallHole(params_->address, params_->socket_id, socket); |
459 } | 459 } |
460 | 460 |
461 SocketAcceptFunction::SocketAcceptFunction() {} | 461 SocketAcceptFunction::SocketAcceptFunction() {} |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 504 } |
505 | 505 |
506 void SocketReadFunction::AsyncWorkStart() { | 506 void SocketReadFunction::AsyncWorkStart() { |
507 Socket* socket = GetSocket(params_->socket_id); | 507 Socket* socket = GetSocket(params_->socket_id); |
508 if (!socket) { | 508 if (!socket) { |
509 error_ = kSocketNotFoundError; | 509 error_ = kSocketNotFoundError; |
510 OnCompleted(-1, NULL); | 510 OnCompleted(-1, NULL); |
511 return; | 511 return; |
512 } | 512 } |
513 | 513 |
514 socket->Read(params_->buffer_size.get() ? *params_->buffer_size.get() : 4096, | 514 socket->Read(params_->buffer_size.get() ? *params_->buffer_size : 4096, |
515 base::Bind(&SocketReadFunction::OnCompleted, this)); | 515 base::Bind(&SocketReadFunction::OnCompleted, this)); |
516 } | 516 } |
517 | 517 |
518 void SocketReadFunction::OnCompleted(int bytes_read, | 518 void SocketReadFunction::OnCompleted(int bytes_read, |
519 scoped_refptr<net::IOBuffer> io_buffer) { | 519 scoped_refptr<net::IOBuffer> io_buffer) { |
520 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 520 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
521 result->SetInteger(kResultCodeKey, bytes_read); | 521 result->SetInteger(kResultCodeKey, bytes_read); |
522 if (bytes_read > 0) { | 522 if (bytes_read > 0) { |
523 result->Set(kDataKey, | 523 result->Set(kDataKey, |
524 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), | 524 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 } else { | 1092 } else { |
1093 RemoveSocket(params_->socket_id); | 1093 RemoveSocket(params_->socket_id); |
1094 error_ = net::ErrorToString(result); | 1094 error_ = net::ErrorToString(result); |
1095 } | 1095 } |
1096 | 1096 |
1097 results_ = api::socket::Secure::Results::Create(result); | 1097 results_ = api::socket::Secure::Results::Create(result); |
1098 AsyncWorkCompleted(); | 1098 AsyncWorkCompleted(); |
1099 } | 1099 } |
1100 | 1100 |
1101 } // namespace extensions | 1101 } // namespace extensions |
OLD | NEW |