Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(yzshen): See the comment in corresponding .h file. | 5 // TODO(yzshen): See the comment in corresponding .h file. |
|
yzshen1
2011/11/09 23:53:55
If you remove the TODO in the .h file, please remo
Dmitry Polukhin
2011/11/10 15:10:11
Done.
| |
| 6 | 6 |
| 7 #include "ppapi/cpp/private/flash_tcp_socket.h" | 7 #include "ppapi/cpp/private/tcp_socket.h" |
| 8 | 8 |
| 9 #include "ppapi/c/pp_bool.h" | 9 #include "ppapi/c/pp_bool.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/cpp/completion_callback.h" | 11 #include "ppapi/cpp/completion_callback.h" |
| 12 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
| 13 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
| 14 #include "ppapi/cpp/module_impl.h" | 14 #include "ppapi/cpp/module_impl.h" |
| 15 | 15 |
| 16 namespace pp { | 16 namespace pp { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 template <> const char* interface_name<PPB_Flash_TCPSocket>() { | 20 template <> const char* interface_name<PPB_TCPSocket>() { |
| 21 return PPB_FLASH_TCPSOCKET_INTERFACE; | 21 return PPB_TCPSOCKET_INTERFACE; |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 namespace flash { | |
| 27 | |
| 28 TCPSocket::TCPSocket(Instance* instance) { | 26 TCPSocket::TCPSocket(Instance* instance) { |
| 29 if (has_interface<PPB_Flash_TCPSocket>() && instance) { | 27 if (has_interface<PPB_TCPSocket>() && instance) { |
| 30 PassRefFromConstructor(get_interface<PPB_Flash_TCPSocket>()->Create( | 28 PassRefFromConstructor(get_interface<PPB_TCPSocket>()->Create( |
| 31 instance->pp_instance())); | 29 instance->pp_instance())); |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 | 32 |
| 35 int32_t TCPSocket::Connect(const char* host, | 33 int32_t TCPSocket::Connect(const char* host, |
| 36 uint16_t port, | 34 uint16_t port, |
| 37 const CompletionCallback& callback) { | 35 const CompletionCallback& callback) { |
| 38 if (!has_interface<PPB_Flash_TCPSocket>()) | 36 if (!has_interface<PPB_TCPSocket>()) |
| 39 return callback.MayForce(PP_ERROR_NOINTERFACE); | 37 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 40 return get_interface<PPB_Flash_TCPSocket>()->Connect( | 38 return get_interface<PPB_TCPSocket>()->Connect( |
| 41 pp_resource(), host, port, callback.pp_completion_callback()); | 39 pp_resource(), host, port, callback.pp_completion_callback()); |
| 42 } | 40 } |
| 43 | 41 |
| 44 int32_t TCPSocket::ConnectWithNetAddress(const PP_Flash_NetAddress* addr, | 42 int32_t TCPSocket::ConnectWithNetAddress(const PP_NetAddress* addr, |
| 45 const CompletionCallback& callback) { | 43 const CompletionCallback& callback) { |
| 46 if (!has_interface<PPB_Flash_TCPSocket>()) | 44 if (!has_interface<PPB_TCPSocket>()) |
| 47 return callback.MayForce(PP_ERROR_NOINTERFACE); | 45 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 48 return get_interface<PPB_Flash_TCPSocket>()->ConnectWithNetAddress( | 46 return get_interface<PPB_TCPSocket>()->ConnectWithNetAddress( |
| 49 pp_resource(), addr, callback.pp_completion_callback()); | 47 pp_resource(), addr, callback.pp_completion_callback()); |
| 50 } | 48 } |
| 51 | 49 |
| 52 bool TCPSocket::GetLocalAddress(PP_Flash_NetAddress* local_addr) { | 50 bool TCPSocket::GetLocalAddress(PP_NetAddress* local_addr) { |
| 53 if (!has_interface<PPB_Flash_TCPSocket>()) | 51 if (!has_interface<PPB_TCPSocket>()) |
| 54 return false; | 52 return false; |
| 55 | 53 |
| 56 PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetLocalAddress( | 54 PP_Bool result = get_interface<PPB_TCPSocket>()->GetLocalAddress( |
| 57 pp_resource(), local_addr); | 55 pp_resource(), local_addr); |
| 58 return PP_ToBool(result); | 56 return PP_ToBool(result); |
| 59 } | 57 } |
| 60 | 58 |
| 61 bool TCPSocket::GetRemoteAddress(PP_Flash_NetAddress* remote_addr) { | 59 bool TCPSocket::GetRemoteAddress(PP_NetAddress* remote_addr) { |
| 62 if (!has_interface<PPB_Flash_TCPSocket>()) | 60 if (!has_interface<PPB_TCPSocket>()) |
| 63 return false; | 61 return false; |
| 64 PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetRemoteAddress( | 62 PP_Bool result = get_interface<PPB_TCPSocket>()->GetRemoteAddress( |
| 65 pp_resource(), remote_addr); | 63 pp_resource(), remote_addr); |
| 66 return PP_ToBool(result); | 64 return PP_ToBool(result); |
| 67 } | 65 } |
| 68 | 66 |
| 69 int32_t TCPSocket::SSLHandshake(const char* server_name, | 67 int32_t TCPSocket::SSLHandshake(const char* server_name, |
| 70 uint16_t server_port, | 68 uint16_t server_port, |
| 71 const CompletionCallback& callback) { | 69 const CompletionCallback& callback) { |
| 72 if (!has_interface<PPB_Flash_TCPSocket>()) | 70 if (!has_interface<PPB_TCPSocket>()) |
| 73 return callback.MayForce(PP_ERROR_NOINTERFACE); | 71 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 74 return get_interface<PPB_Flash_TCPSocket>()->SSLHandshake( | 72 return get_interface<PPB_TCPSocket>()->SSLHandshake( |
| 75 pp_resource(), server_name, server_port, | 73 pp_resource(), server_name, server_port, |
| 76 callback.pp_completion_callback()); | 74 callback.pp_completion_callback()); |
| 77 } | 75 } |
| 78 | 76 |
| 79 int32_t TCPSocket::Read(char* buffer, | 77 int32_t TCPSocket::Read(char* buffer, |
| 80 int32_t bytes_to_read, | 78 int32_t bytes_to_read, |
| 81 const CompletionCallback& callback) { | 79 const CompletionCallback& callback) { |
| 82 if (!has_interface<PPB_Flash_TCPSocket>()) | 80 if (!has_interface<PPB_TCPSocket>()) |
| 83 return callback.MayForce(PP_ERROR_NOINTERFACE); | 81 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 84 return get_interface<PPB_Flash_TCPSocket>()->Read( | 82 return get_interface<PPB_TCPSocket>()->Read( |
| 85 pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback()); | 83 pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback()); |
| 86 } | 84 } |
| 87 | 85 |
| 88 int32_t TCPSocket::Write(const char* buffer, | 86 int32_t TCPSocket::Write(const char* buffer, |
| 89 int32_t bytes_to_write, | 87 int32_t bytes_to_write, |
| 90 const CompletionCallback& callback) { | 88 const CompletionCallback& callback) { |
| 91 if (!has_interface<PPB_Flash_TCPSocket>()) | 89 if (!has_interface<PPB_TCPSocket>()) |
| 92 return callback.MayForce(PP_ERROR_NOINTERFACE); | 90 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 93 return get_interface<PPB_Flash_TCPSocket>()->Write( | 91 return get_interface<PPB_TCPSocket>()->Write( |
| 94 pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback()); | 92 pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback()); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void TCPSocket::Disconnect() { | 95 void TCPSocket::Disconnect() { |
| 98 if (!has_interface<PPB_Flash_TCPSocket>()) | 96 if (!has_interface<PPB_TCPSocket>()) |
| 99 return; | 97 return; |
| 100 return get_interface<PPB_Flash_TCPSocket>()->Disconnect(pp_resource()); | 98 return get_interface<PPB_TCPSocket>()->Disconnect(pp_resource()); |
| 101 } | 99 } |
| 102 | 100 |
| 103 } // namespace flash | |
| 104 } // namespace pp | 101 } // namespace pp |
| OLD | NEW |