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 "chrome/browser/extensions/api/socket/socket_api.h" | 5 #include "chrome/browser/extensions/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/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 const char kSocketIdKey[] = "socketId"; | 36 const char kSocketIdKey[] = "socketId"; |
| 37 | 37 |
| 38 const char kSocketNotFoundError[] = "Socket not found"; | 38 const char kSocketNotFoundError[] = "Socket not found"; |
| 39 const char kDnsLookupFailedError[] = "DNS resolution failed"; | 39 const char kDnsLookupFailedError[] = "DNS resolution failed"; |
| 40 const char kPermissionError[] = "App does not have permission"; | 40 const char kPermissionError[] = "App does not have permission"; |
| 41 const char kNetworkListError[] = "Network lookup failed or unsupported"; | 41 const char kNetworkListError[] = "Network lookup failed or unsupported"; |
| 42 const char kTCPSocketBindError[] = | 42 const char kTCPSocketBindError[] = |
| 43 "TCP socket does not support bind. For TCP server please use listen."; | 43 "TCP socket does not support bind. For TCP server please use listen."; |
| 44 const char kMulticastSocketTypeError[] = | 44 const char kMulticastSocketTypeError[] = |
| 45 "Only UDP socket supports multicast."; | 45 "Only UDP socket supports multicast."; |
| 46 const char kAddressReuseSocketTypeError[] = | |
| 47 "There is no need AllowReuseAddress on TCP sockets, as TCP sockets support" | |
| 48 " address reuse by default."; | |
|
miket_OOO
2013/05/24 20:53:48
I think you accidentally a word.
Noam Samuel
2013/05/24 21:43:53
Fixed.
| |
| 46 const char kWildcardAddress[] = "*"; | 49 const char kWildcardAddress[] = "*"; |
| 47 const int kWildcardPort = 0; | 50 const int kWildcardPort = 0; |
| 48 | 51 |
| 49 SocketAsyncApiFunction::SocketAsyncApiFunction() | 52 SocketAsyncApiFunction::SocketAsyncApiFunction() |
| 50 : manager_(NULL) { | 53 : manager_(NULL) { |
| 51 } | 54 } |
| 52 | 55 |
| 53 SocketAsyncApiFunction::~SocketAsyncApiFunction() { | 56 SocketAsyncApiFunction::~SocketAsyncApiFunction() { |
| 54 } | 57 } |
| 55 | 58 |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 return; | 731 return; |
| 729 } | 732 } |
| 730 | 733 |
| 731 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); | 734 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); |
| 732 if (result != 0) { | 735 if (result != 0) { |
| 733 error_ = net::ErrorToString(result); | 736 error_ = net::ErrorToString(result); |
| 734 } | 737 } |
| 735 SetResult(Value::CreateIntegerValue(result)); | 738 SetResult(Value::CreateIntegerValue(result)); |
| 736 } | 739 } |
| 737 | 740 |
| 738 | |
| 739 SocketLeaveGroupFunction::SocketLeaveGroupFunction() | 741 SocketLeaveGroupFunction::SocketLeaveGroupFunction() |
| 740 : params_(NULL) {} | 742 : params_(NULL) {} |
| 741 | 743 |
| 742 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} | 744 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} |
| 743 | 745 |
| 744 bool SocketLeaveGroupFunction::Prepare() { | 746 bool SocketLeaveGroupFunction::Prepare() { |
| 745 params_ = api::socket::LeaveGroup::Params::Create(*args_); | 747 params_ = api::socket::LeaveGroup::Params::Create(*args_); |
| 746 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 748 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 747 return true; | 749 return true; |
| 748 } | 750 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 SetResult(Value::CreateIntegerValue(result)); | 884 SetResult(Value::CreateIntegerValue(result)); |
| 883 return; | 885 return; |
| 884 } | 886 } |
| 885 | 887 |
| 886 base::ListValue* values = new base::ListValue(); | 888 base::ListValue* values = new base::ListValue(); |
| 887 values->AppendStrings((std::vector<std::string>&) | 889 values->AppendStrings((std::vector<std::string>&) |
| 888 static_cast<UDPSocket*>(socket)->GetJoinedGroups()); | 890 static_cast<UDPSocket*>(socket)->GetJoinedGroups()); |
| 889 SetResult(values); | 891 SetResult(values); |
| 890 } | 892 } |
| 891 | 893 |
| 894 SocketAllowAddressReuseFunction::SocketAllowAddressReuseFunction() | |
| 895 : params_(NULL) {} | |
|
mmenke
2013/05/24 21:12:00
nit: Should be 4-space indent.
Noam Samuel
2013/05/24 21:43:53
Done.
| |
| 896 | |
| 897 SocketAllowAddressReuseFunction:: | |
| 898 ~SocketAllowAddressReuseFunction() {} | |
|
mmenke
2013/05/24 21:12:00
nit: This should be 4-space indent or 0-space (Bo
Noam Samuel
2013/05/24 21:43:53
Looks like it fits on one line. Not sure why I for
| |
| 899 | |
| 900 bool SocketAllowAddressReuseFunction::Prepare() { | |
| 901 params_ = api::socket::AllowAddressReuse::Params::Create(*args_); | |
| 902 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
| 903 return true; | |
| 904 } | |
| 905 | |
| 906 void SocketAllowAddressReuseFunction::Work() { | |
| 907 int result = -1; | |
| 908 Socket* socket = GetSocket(params_->socket_id); | |
| 909 if (!socket) { | |
| 910 error_ = kSocketNotFoundError; | |
| 911 SetResult(Value::CreateIntegerValue(result)); | |
|
mmenke
2013/05/24 21:12:00
I know this is done elsewhere, but this is really
| |
| 912 return; | |
| 913 } | |
| 914 | |
| 915 if (socket->GetSocketType() != Socket::TYPE_UDP) { | |
| 916 error_ = kAddressReuseSocketTypeError; | |
| 917 SetResult(Value::CreateIntegerValue(result)); | |
| 918 return; | |
| 919 } | |
| 920 | |
| 921 result = static_cast<UDPSocket*>(socket)->AllowAddressReuse(); | |
| 922 if (result != 0) | |
| 923 error_ = net::ErrorToString(result); | |
| 924 SetResult(Value::CreateIntegerValue(result)); | |
| 925 } | |
| 926 | |
| 892 } // namespace extensions | 927 } // namespace extensions |
| OLD | NEW |