| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 AfterDnsLookup(resolve_result); | 210 AfterDnsLookup(resolve_result); |
| 211 } | 211 } |
| 212 | 212 |
| 213 SocketCreateFunction::SocketCreateFunction() | 213 SocketCreateFunction::SocketCreateFunction() |
| 214 : socket_type_(kSocketTypeInvalid) {} | 214 : socket_type_(kSocketTypeInvalid) {} |
| 215 | 215 |
| 216 SocketCreateFunction::~SocketCreateFunction() {} | 216 SocketCreateFunction::~SocketCreateFunction() {} |
| 217 | 217 |
| 218 bool SocketCreateFunction::Prepare() { | 218 bool SocketCreateFunction::Prepare() { |
| 219 params_ = core_api::socket::Create::Params::Create(*args_); | 219 params_ = api::socket::Create::Params::Create(*args_); |
| 220 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 220 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 221 | 221 |
| 222 switch (params_->type) { | 222 switch (params_->type) { |
| 223 case extensions::core_api::socket::SOCKET_TYPE_TCP: | 223 case extensions::api::socket::SOCKET_TYPE_TCP: |
| 224 socket_type_ = kSocketTypeTCP; | 224 socket_type_ = kSocketTypeTCP; |
| 225 break; | 225 break; |
| 226 case extensions::core_api::socket::SOCKET_TYPE_UDP: | 226 case extensions::api::socket::SOCKET_TYPE_UDP: |
| 227 socket_type_ = kSocketTypeUDP; | 227 socket_type_ = kSocketTypeUDP; |
| 228 break; | 228 break; |
| 229 case extensions::core_api::socket::SOCKET_TYPE_NONE: | 229 case extensions::api::socket::SOCKET_TYPE_NONE: |
| 230 NOTREACHED(); | 230 NOTREACHED(); |
| 231 break; | 231 break; |
| 232 } | 232 } |
| 233 | 233 |
| 234 return true; | 234 return true; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void SocketCreateFunction::Work() { | 237 void SocketCreateFunction::Work() { |
| 238 Socket* socket = NULL; | 238 Socket* socket = NULL; |
| 239 if (socket_type_ == kSocketTypeTCP) { | 239 if (socket_type_ == kSocketTypeTCP) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 394 } |
| 395 | 395 |
| 396 OpenFirewallHole(address_, socket_id_, socket); | 396 OpenFirewallHole(address_, socket_id_, socket); |
| 397 } | 397 } |
| 398 | 398 |
| 399 SocketListenFunction::SocketListenFunction() {} | 399 SocketListenFunction::SocketListenFunction() {} |
| 400 | 400 |
| 401 SocketListenFunction::~SocketListenFunction() {} | 401 SocketListenFunction::~SocketListenFunction() {} |
| 402 | 402 |
| 403 bool SocketListenFunction::Prepare() { | 403 bool SocketListenFunction::Prepare() { |
| 404 params_ = core_api::socket::Listen::Params::Create(*args_); | 404 params_ = api::socket::Listen::Params::Create(*args_); |
| 405 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 405 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 406 return true; | 406 return true; |
| 407 } | 407 } |
| 408 | 408 |
| 409 void SocketListenFunction::AsyncWorkStart() { | 409 void SocketListenFunction::AsyncWorkStart() { |
| 410 Socket* socket = GetSocket(params_->socket_id); | 410 Socket* socket = GetSocket(params_->socket_id); |
| 411 if (!socket) { | 411 if (!socket) { |
| 412 error_ = kSocketNotFoundError; | 412 error_ = kSocketNotFoundError; |
| 413 SetResult(new base::FundamentalValue(-1)); | 413 SetResult(new base::FundamentalValue(-1)); |
| 414 AsyncWorkCompleted(); | 414 AsyncWorkCompleted(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 435 } | 435 } |
| 436 | 436 |
| 437 OpenFirewallHole(params_->address, params_->socket_id, socket); | 437 OpenFirewallHole(params_->address, params_->socket_id, socket); |
| 438 } | 438 } |
| 439 | 439 |
| 440 SocketAcceptFunction::SocketAcceptFunction() {} | 440 SocketAcceptFunction::SocketAcceptFunction() {} |
| 441 | 441 |
| 442 SocketAcceptFunction::~SocketAcceptFunction() {} | 442 SocketAcceptFunction::~SocketAcceptFunction() {} |
| 443 | 443 |
| 444 bool SocketAcceptFunction::Prepare() { | 444 bool SocketAcceptFunction::Prepare() { |
| 445 params_ = core_api::socket::Accept::Params::Create(*args_); | 445 params_ = api::socket::Accept::Params::Create(*args_); |
| 446 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 446 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 447 return true; | 447 return true; |
| 448 } | 448 } |
| 449 | 449 |
| 450 void SocketAcceptFunction::AsyncWorkStart() { | 450 void SocketAcceptFunction::AsyncWorkStart() { |
| 451 Socket* socket = GetSocket(params_->socket_id); | 451 Socket* socket = GetSocket(params_->socket_id); |
| 452 if (socket) { | 452 if (socket) { |
| 453 socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this)); | 453 socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this)); |
| 454 } else { | 454 } else { |
| 455 error_ = kSocketNotFoundError; | 455 error_ = kSocketNotFoundError; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 468 SetResult(result); | 468 SetResult(result); |
| 469 | 469 |
| 470 AsyncWorkCompleted(); | 470 AsyncWorkCompleted(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 SocketReadFunction::SocketReadFunction() {} | 473 SocketReadFunction::SocketReadFunction() {} |
| 474 | 474 |
| 475 SocketReadFunction::~SocketReadFunction() {} | 475 SocketReadFunction::~SocketReadFunction() {} |
| 476 | 476 |
| 477 bool SocketReadFunction::Prepare() { | 477 bool SocketReadFunction::Prepare() { |
| 478 params_ = core_api::socket::Read::Params::Create(*args_); | 478 params_ = api::socket::Read::Params::Create(*args_); |
| 479 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 479 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 480 return true; | 480 return true; |
| 481 } | 481 } |
| 482 | 482 |
| 483 void SocketReadFunction::AsyncWorkStart() { | 483 void SocketReadFunction::AsyncWorkStart() { |
| 484 Socket* socket = GetSocket(params_->socket_id); | 484 Socket* socket = GetSocket(params_->socket_id); |
| 485 if (!socket) { | 485 if (!socket) { |
| 486 error_ = kSocketNotFoundError; | 486 error_ = kSocketNotFoundError; |
| 487 OnCompleted(-1, NULL); | 487 OnCompleted(-1, NULL); |
| 488 return; | 488 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 SetResult(result); | 543 SetResult(result); |
| 544 | 544 |
| 545 AsyncWorkCompleted(); | 545 AsyncWorkCompleted(); |
| 546 } | 546 } |
| 547 | 547 |
| 548 SocketRecvFromFunction::SocketRecvFromFunction() {} | 548 SocketRecvFromFunction::SocketRecvFromFunction() {} |
| 549 | 549 |
| 550 SocketRecvFromFunction::~SocketRecvFromFunction() {} | 550 SocketRecvFromFunction::~SocketRecvFromFunction() {} |
| 551 | 551 |
| 552 bool SocketRecvFromFunction::Prepare() { | 552 bool SocketRecvFromFunction::Prepare() { |
| 553 params_ = core_api::socket::RecvFrom::Params::Create(*args_); | 553 params_ = api::socket::RecvFrom::Params::Create(*args_); |
| 554 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 554 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 555 return true; | 555 return true; |
| 556 } | 556 } |
| 557 | 557 |
| 558 void SocketRecvFromFunction::AsyncWorkStart() { | 558 void SocketRecvFromFunction::AsyncWorkStart() { |
| 559 Socket* socket = GetSocket(params_->socket_id); | 559 Socket* socket = GetSocket(params_->socket_id); |
| 560 if (!socket || socket->GetSocketType() != Socket::TYPE_UDP) { | 560 if (!socket || socket->GetSocketType() != Socket::TYPE_UDP) { |
| 561 error_ = kSocketNotFoundError; | 561 error_ = kSocketNotFoundError; |
| 562 OnCompleted(-1, NULL, std::string(), 0); | 562 OnCompleted(-1, NULL, std::string(), 0); |
| 563 return; | 563 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 SetResult(result); | 660 SetResult(result); |
| 661 | 661 |
| 662 AsyncWorkCompleted(); | 662 AsyncWorkCompleted(); |
| 663 } | 663 } |
| 664 | 664 |
| 665 SocketSetKeepAliveFunction::SocketSetKeepAliveFunction() {} | 665 SocketSetKeepAliveFunction::SocketSetKeepAliveFunction() {} |
| 666 | 666 |
| 667 SocketSetKeepAliveFunction::~SocketSetKeepAliveFunction() {} | 667 SocketSetKeepAliveFunction::~SocketSetKeepAliveFunction() {} |
| 668 | 668 |
| 669 bool SocketSetKeepAliveFunction::Prepare() { | 669 bool SocketSetKeepAliveFunction::Prepare() { |
| 670 params_ = core_api::socket::SetKeepAlive::Params::Create(*args_); | 670 params_ = api::socket::SetKeepAlive::Params::Create(*args_); |
| 671 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 671 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 672 return true; | 672 return true; |
| 673 } | 673 } |
| 674 | 674 |
| 675 void SocketSetKeepAliveFunction::Work() { | 675 void SocketSetKeepAliveFunction::Work() { |
| 676 bool result = false; | 676 bool result = false; |
| 677 Socket* socket = GetSocket(params_->socket_id); | 677 Socket* socket = GetSocket(params_->socket_id); |
| 678 if (socket) { | 678 if (socket) { |
| 679 int delay = 0; | 679 int delay = 0; |
| 680 if (params_->delay.get()) | 680 if (params_->delay.get()) |
| 681 delay = *params_->delay; | 681 delay = *params_->delay; |
| 682 result = socket->SetKeepAlive(params_->enable, delay); | 682 result = socket->SetKeepAlive(params_->enable, delay); |
| 683 } else { | 683 } else { |
| 684 error_ = kSocketNotFoundError; | 684 error_ = kSocketNotFoundError; |
| 685 } | 685 } |
| 686 SetResult(new base::FundamentalValue(result)); | 686 SetResult(new base::FundamentalValue(result)); |
| 687 } | 687 } |
| 688 | 688 |
| 689 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} | 689 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} |
| 690 | 690 |
| 691 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} | 691 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} |
| 692 | 692 |
| 693 bool SocketSetNoDelayFunction::Prepare() { | 693 bool SocketSetNoDelayFunction::Prepare() { |
| 694 params_ = core_api::socket::SetNoDelay::Params::Create(*args_); | 694 params_ = api::socket::SetNoDelay::Params::Create(*args_); |
| 695 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 695 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 696 return true; | 696 return true; |
| 697 } | 697 } |
| 698 | 698 |
| 699 void SocketSetNoDelayFunction::Work() { | 699 void SocketSetNoDelayFunction::Work() { |
| 700 bool result = false; | 700 bool result = false; |
| 701 Socket* socket = GetSocket(params_->socket_id); | 701 Socket* socket = GetSocket(params_->socket_id); |
| 702 if (socket) | 702 if (socket) |
| 703 result = socket->SetNoDelay(params_->no_delay); | 703 result = socket->SetNoDelay(params_->no_delay); |
| 704 else | 704 else |
| 705 error_ = kSocketNotFoundError; | 705 error_ = kSocketNotFoundError; |
| 706 SetResult(new base::FundamentalValue(result)); | 706 SetResult(new base::FundamentalValue(result)); |
| 707 } | 707 } |
| 708 | 708 |
| 709 SocketGetInfoFunction::SocketGetInfoFunction() {} | 709 SocketGetInfoFunction::SocketGetInfoFunction() {} |
| 710 | 710 |
| 711 SocketGetInfoFunction::~SocketGetInfoFunction() {} | 711 SocketGetInfoFunction::~SocketGetInfoFunction() {} |
| 712 | 712 |
| 713 bool SocketGetInfoFunction::Prepare() { | 713 bool SocketGetInfoFunction::Prepare() { |
| 714 params_ = core_api::socket::GetInfo::Params::Create(*args_); | 714 params_ = api::socket::GetInfo::Params::Create(*args_); |
| 715 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 715 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 716 return true; | 716 return true; |
| 717 } | 717 } |
| 718 | 718 |
| 719 void SocketGetInfoFunction::Work() { | 719 void SocketGetInfoFunction::Work() { |
| 720 Socket* socket = GetSocket(params_->socket_id); | 720 Socket* socket = GetSocket(params_->socket_id); |
| 721 if (!socket) { | 721 if (!socket) { |
| 722 error_ = kSocketNotFoundError; | 722 error_ = kSocketNotFoundError; |
| 723 return; | 723 return; |
| 724 } | 724 } |
| 725 | 725 |
| 726 core_api::socket::SocketInfo info; | 726 api::socket::SocketInfo info; |
| 727 // This represents what we know about the socket, and does not call through | 727 // This represents what we know about the socket, and does not call through |
| 728 // to the system. | 728 // to the system. |
| 729 if (socket->GetSocketType() == Socket::TYPE_TCP) | 729 if (socket->GetSocketType() == Socket::TYPE_TCP) |
| 730 info.socket_type = extensions::core_api::socket::SOCKET_TYPE_TCP; | 730 info.socket_type = extensions::api::socket::SOCKET_TYPE_TCP; |
| 731 else | 731 else |
| 732 info.socket_type = extensions::core_api::socket::SOCKET_TYPE_UDP; | 732 info.socket_type = extensions::api::socket::SOCKET_TYPE_UDP; |
| 733 info.connected = socket->IsConnected(); | 733 info.connected = socket->IsConnected(); |
| 734 | 734 |
| 735 // Grab the peer address as known by the OS. This and the call below will | 735 // Grab the peer address as known by the OS. This and the call below will |
| 736 // always succeed while the socket is connected, even if the socket has | 736 // always succeed while the socket is connected, even if the socket has |
| 737 // been remotely closed by the peer; only reading the socket will reveal | 737 // been remotely closed by the peer; only reading the socket will reveal |
| 738 // that it should be closed locally. | 738 // that it should be closed locally. |
| 739 net::IPEndPoint peerAddress; | 739 net::IPEndPoint peerAddress; |
| 740 if (socket->GetPeerAddress(&peerAddress)) { | 740 if (socket->GetPeerAddress(&peerAddress)) { |
| 741 info.peer_address.reset(new std::string(peerAddress.ToStringWithoutPort())); | 741 info.peer_address.reset(new std::string(peerAddress.ToStringWithoutPort())); |
| 742 info.peer_port.reset(new int(peerAddress.port())); | 742 info.peer_port.reset(new int(peerAddress.port())); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 void SocketGetNetworkListFunction::HandleGetNetworkListError() { | 781 void SocketGetNetworkListFunction::HandleGetNetworkListError() { |
| 782 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 782 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 783 error_ = kNetworkListError; | 783 error_ = kNetworkListError; |
| 784 SendResponse(false); | 784 SendResponse(false); |
| 785 } | 785 } |
| 786 | 786 |
| 787 void SocketGetNetworkListFunction::SendResponseOnUIThread( | 787 void SocketGetNetworkListFunction::SendResponseOnUIThread( |
| 788 const net::NetworkInterfaceList& interface_list) { | 788 const net::NetworkInterfaceList& interface_list) { |
| 789 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 789 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 790 | 790 |
| 791 std::vector<linked_ptr<core_api::socket::NetworkInterface> > create_arg; | 791 std::vector<linked_ptr<api::socket::NetworkInterface>> create_arg; |
| 792 create_arg.reserve(interface_list.size()); | 792 create_arg.reserve(interface_list.size()); |
| 793 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin(); | 793 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin(); |
| 794 i != interface_list.end(); | 794 i != interface_list.end(); |
| 795 ++i) { | 795 ++i) { |
| 796 linked_ptr<core_api::socket::NetworkInterface> info = | 796 linked_ptr<api::socket::NetworkInterface> info = |
| 797 make_linked_ptr(new core_api::socket::NetworkInterface); | 797 make_linked_ptr(new api::socket::NetworkInterface); |
| 798 info->name = i->name; | 798 info->name = i->name; |
| 799 info->address = net::IPAddressToString(i->address); | 799 info->address = net::IPAddressToString(i->address); |
| 800 info->prefix_length = i->prefix_length; | 800 info->prefix_length = i->prefix_length; |
| 801 create_arg.push_back(info); | 801 create_arg.push_back(info); |
| 802 } | 802 } |
| 803 | 803 |
| 804 results_ = core_api::socket::GetNetworkList::Results::Create(create_arg); | 804 results_ = api::socket::GetNetworkList::Results::Create(create_arg); |
| 805 SendResponse(true); | 805 SendResponse(true); |
| 806 } | 806 } |
| 807 | 807 |
| 808 SocketJoinGroupFunction::SocketJoinGroupFunction() {} | 808 SocketJoinGroupFunction::SocketJoinGroupFunction() {} |
| 809 | 809 |
| 810 SocketJoinGroupFunction::~SocketJoinGroupFunction() {} | 810 SocketJoinGroupFunction::~SocketJoinGroupFunction() {} |
| 811 | 811 |
| 812 bool SocketJoinGroupFunction::Prepare() { | 812 bool SocketJoinGroupFunction::Prepare() { |
| 813 params_ = core_api::socket::JoinGroup::Params::Create(*args_); | 813 params_ = api::socket::JoinGroup::Params::Create(*args_); |
| 814 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 814 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 815 return true; | 815 return true; |
| 816 } | 816 } |
| 817 | 817 |
| 818 void SocketJoinGroupFunction::Work() { | 818 void SocketJoinGroupFunction::Work() { |
| 819 int result = -1; | 819 int result = -1; |
| 820 Socket* socket = GetSocket(params_->socket_id); | 820 Socket* socket = GetSocket(params_->socket_id); |
| 821 if (!socket) { | 821 if (!socket) { |
| 822 error_ = kSocketNotFoundError; | 822 error_ = kSocketNotFoundError; |
| 823 SetResult(new base::FundamentalValue(result)); | 823 SetResult(new base::FundamentalValue(result)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 847 error_ = net::ErrorToString(result); | 847 error_ = net::ErrorToString(result); |
| 848 } | 848 } |
| 849 SetResult(new base::FundamentalValue(result)); | 849 SetResult(new base::FundamentalValue(result)); |
| 850 } | 850 } |
| 851 | 851 |
| 852 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} | 852 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} |
| 853 | 853 |
| 854 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} | 854 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} |
| 855 | 855 |
| 856 bool SocketLeaveGroupFunction::Prepare() { | 856 bool SocketLeaveGroupFunction::Prepare() { |
| 857 params_ = core_api::socket::LeaveGroup::Params::Create(*args_); | 857 params_ = api::socket::LeaveGroup::Params::Create(*args_); |
| 858 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 858 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 859 return true; | 859 return true; |
| 860 } | 860 } |
| 861 | 861 |
| 862 void SocketLeaveGroupFunction::Work() { | 862 void SocketLeaveGroupFunction::Work() { |
| 863 int result = -1; | 863 int result = -1; |
| 864 Socket* socket = GetSocket(params_->socket_id); | 864 Socket* socket = GetSocket(params_->socket_id); |
| 865 | 865 |
| 866 if (!socket) { | 866 if (!socket) { |
| 867 error_ = kSocketNotFoundError; | 867 error_ = kSocketNotFoundError; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 890 if (result != 0) | 890 if (result != 0) |
| 891 error_ = net::ErrorToString(result); | 891 error_ = net::ErrorToString(result); |
| 892 SetResult(new base::FundamentalValue(result)); | 892 SetResult(new base::FundamentalValue(result)); |
| 893 } | 893 } |
| 894 | 894 |
| 895 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} | 895 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} |
| 896 | 896 |
| 897 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} | 897 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} |
| 898 | 898 |
| 899 bool SocketSetMulticastTimeToLiveFunction::Prepare() { | 899 bool SocketSetMulticastTimeToLiveFunction::Prepare() { |
| 900 params_ = core_api::socket::SetMulticastTimeToLive::Params::Create(*args_); | 900 params_ = api::socket::SetMulticastTimeToLive::Params::Create(*args_); |
| 901 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 901 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 902 return true; | 902 return true; |
| 903 } | 903 } |
| 904 void SocketSetMulticastTimeToLiveFunction::Work() { | 904 void SocketSetMulticastTimeToLiveFunction::Work() { |
| 905 int result = -1; | 905 int result = -1; |
| 906 Socket* socket = GetSocket(params_->socket_id); | 906 Socket* socket = GetSocket(params_->socket_id); |
| 907 if (!socket) { | 907 if (!socket) { |
| 908 error_ = kSocketNotFoundError; | 908 error_ = kSocketNotFoundError; |
| 909 SetResult(new base::FundamentalValue(result)); | 909 SetResult(new base::FundamentalValue(result)); |
| 910 return; | 910 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 923 SetResult(new base::FundamentalValue(result)); | 923 SetResult(new base::FundamentalValue(result)); |
| 924 } | 924 } |
| 925 | 925 |
| 926 SocketSetMulticastLoopbackModeFunction:: | 926 SocketSetMulticastLoopbackModeFunction:: |
| 927 SocketSetMulticastLoopbackModeFunction() {} | 927 SocketSetMulticastLoopbackModeFunction() {} |
| 928 | 928 |
| 929 SocketSetMulticastLoopbackModeFunction:: | 929 SocketSetMulticastLoopbackModeFunction:: |
| 930 ~SocketSetMulticastLoopbackModeFunction() {} | 930 ~SocketSetMulticastLoopbackModeFunction() {} |
| 931 | 931 |
| 932 bool SocketSetMulticastLoopbackModeFunction::Prepare() { | 932 bool SocketSetMulticastLoopbackModeFunction::Prepare() { |
| 933 params_ = core_api::socket::SetMulticastLoopbackMode::Params::Create(*args_); | 933 params_ = api::socket::SetMulticastLoopbackMode::Params::Create(*args_); |
| 934 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 934 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 935 return true; | 935 return true; |
| 936 } | 936 } |
| 937 | 937 |
| 938 void SocketSetMulticastLoopbackModeFunction::Work() { | 938 void SocketSetMulticastLoopbackModeFunction::Work() { |
| 939 int result = -1; | 939 int result = -1; |
| 940 Socket* socket = GetSocket(params_->socket_id); | 940 Socket* socket = GetSocket(params_->socket_id); |
| 941 if (!socket) { | 941 if (!socket) { |
| 942 error_ = kSocketNotFoundError; | 942 error_ = kSocketNotFoundError; |
| 943 SetResult(new base::FundamentalValue(result)); | 943 SetResult(new base::FundamentalValue(result)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 955 if (result != 0) | 955 if (result != 0) |
| 956 error_ = net::ErrorToString(result); | 956 error_ = net::ErrorToString(result); |
| 957 SetResult(new base::FundamentalValue(result)); | 957 SetResult(new base::FundamentalValue(result)); |
| 958 } | 958 } |
| 959 | 959 |
| 960 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} | 960 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} |
| 961 | 961 |
| 962 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} | 962 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} |
| 963 | 963 |
| 964 bool SocketGetJoinedGroupsFunction::Prepare() { | 964 bool SocketGetJoinedGroupsFunction::Prepare() { |
| 965 params_ = core_api::socket::GetJoinedGroups::Params::Create(*args_); | 965 params_ = api::socket::GetJoinedGroups::Params::Create(*args_); |
| 966 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 966 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 967 return true; | 967 return true; |
| 968 } | 968 } |
| 969 | 969 |
| 970 void SocketGetJoinedGroupsFunction::Work() { | 970 void SocketGetJoinedGroupsFunction::Work() { |
| 971 int result = -1; | 971 int result = -1; |
| 972 Socket* socket = GetSocket(params_->socket_id); | 972 Socket* socket = GetSocket(params_->socket_id); |
| 973 if (!socket) { | 973 if (!socket) { |
| 974 error_ = kSocketNotFoundError; | 974 error_ = kSocketNotFoundError; |
| 975 SetResult(new base::FundamentalValue(result)); | 975 SetResult(new base::FundamentalValue(result)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 SocketSecureFunction::SocketSecureFunction() { | 1002 SocketSecureFunction::SocketSecureFunction() { |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 SocketSecureFunction::~SocketSecureFunction() { | 1005 SocketSecureFunction::~SocketSecureFunction() { |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 bool SocketSecureFunction::Prepare() { | 1008 bool SocketSecureFunction::Prepare() { |
| 1009 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1009 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1010 params_ = core_api::socket::Secure::Params::Create(*args_); | 1010 params_ = api::socket::Secure::Params::Create(*args_); |
| 1011 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 1011 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 1012 url_request_getter_ = browser_context()->GetRequestContext(); | 1012 url_request_getter_ = browser_context()->GetRequestContext(); |
| 1013 return true; | 1013 return true; |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 // Override the regular implementation, which would call AsyncWorkCompleted | 1016 // Override the regular implementation, which would call AsyncWorkCompleted |
| 1017 // immediately after Work(). | 1017 // immediately after Work(). |
| 1018 void SocketSecureFunction::AsyncWorkStart() { | 1018 void SocketSecureFunction::AsyncWorkStart() { |
| 1019 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1019 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1020 | 1020 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 // if an error occurred, socket MUST be NULL. | 1060 // if an error occurred, socket MUST be NULL. |
| 1061 DCHECK(result == net::OK || socket == NULL); | 1061 DCHECK(result == net::OK || socket == NULL); |
| 1062 | 1062 |
| 1063 if (socket && result == net::OK) { | 1063 if (socket && result == net::OK) { |
| 1064 ReplaceSocket(params_->socket_id, socket.release()); | 1064 ReplaceSocket(params_->socket_id, socket.release()); |
| 1065 } else { | 1065 } else { |
| 1066 RemoveSocket(params_->socket_id); | 1066 RemoveSocket(params_->socket_id); |
| 1067 error_ = net::ErrorToString(result); | 1067 error_ = net::ErrorToString(result); |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 results_ = core_api::socket::Secure::Results::Create(result); | 1070 results_ = api::socket::Secure::Results::Create(result); |
| 1071 AsyncWorkCompleted(); | 1071 AsyncWorkCompleted(); |
| 1072 } | 1072 } |
| 1073 | 1073 |
| 1074 } // namespace extensions | 1074 } // namespace extensions |
| OLD | NEW |