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 #include "webkit/plugins/ppapi/ppb_transport_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_transport_impl.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/json/json_writer.h" | |
| 7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/values.h" | |
| 9 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 11 #include "net/socket/socket.h" | 14 #include "net/socket/socket.h" |
| 12 #include "ppapi/c/dev/ppb_transport_dev.h" | 15 #include "ppapi/c/dev/ppb_transport_dev.h" |
| 13 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
| 14 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 15 #include "ppapi/shared_impl/var.h" | 18 #include "ppapi/shared_impl/var.h" |
| 16 #include "webkit/plugins/ppapi/common.h" | 19 #include "webkit/plugins/ppapi/common.h" |
| 17 #include "webkit/plugins/ppapi/plugin_module.h" | 20 #include "webkit/plugins/ppapi/plugin_module.h" |
| 18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 19 | 22 |
| 20 using ppapi::StringVar; | 23 using ppapi::StringVar; |
| 21 using ppapi::thunk::PPB_Transport_API; | 24 using ppapi::thunk::PPB_Transport_API; |
| 22 using webkit_glue::P2PTransport; | 25 using webkit_glue::P2PTransport; |
| 23 | 26 |
| 24 namespace webkit { | 27 namespace webkit { |
| 25 namespace ppapi { | 28 namespace ppapi { |
| 26 | 29 |
| 27 namespace { | 30 namespace { |
| 28 | 31 |
| 29 const char kUdpProtocolName[] = "udp"; | 32 const char kUdpProtocolName[] = "udp"; |
| 30 const char kTcpProtocolName[] = "tcp"; | 33 const char kTcpProtocolName[] = "tcp"; |
| 31 | 34 |
| 35 const int kMinBufferSize = 1024; | |
| 36 const int kMaxBufferSize = 1024 * 1024; | |
| 37 | |
| 32 int MapNetError(int result) { | 38 int MapNetError(int result) { |
| 33 if (result > 0) | 39 if (result > 0) |
| 34 return result; | 40 return result; |
| 35 | 41 |
| 36 switch (result) { | 42 switch (result) { |
| 37 case net::OK: | 43 case net::OK: |
| 38 return PP_OK; | 44 return PP_OK; |
| 39 case net::ERR_IO_PENDING: | 45 case net::ERR_IO_PENDING: |
| 40 return PP_OK_COMPLETIONPENDING; | 46 return PP_OK_COMPLETIONPENDING; |
| 41 case net::ERR_INVALID_ARGUMENT: | 47 case net::ERR_INVALID_ARGUMENT: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 return p2p_transport_.get() != NULL; | 96 return p2p_transport_.get() != NULL; |
| 91 } | 97 } |
| 92 | 98 |
| 93 PP_Bool PPB_Transport_Impl::IsWritable() { | 99 PP_Bool PPB_Transport_Impl::IsWritable() { |
| 94 if (!p2p_transport_.get()) | 100 if (!p2p_transport_.get()) |
| 95 return PP_FALSE; | 101 return PP_FALSE; |
| 96 | 102 |
| 97 return PP_FromBool(writable_); | 103 return PP_FromBool(writable_); |
| 98 } | 104 } |
| 99 | 105 |
| 106 const char kStringListSeparator = ','; | |
|
brettw
2011/08/25 16:48:43
It doesn't look like you use this.
Sergey Ulanov
2011/08/25 17:36:53
Done.
| |
| 107 | |
| 108 int32_t PPB_Transport_Impl::SetProperty(PP_TransportProperty property, | |
| 109 PP_Var value) { | |
| 110 // SetProperty() may be called only before Connect(). | |
| 111 if (started_) | |
| 112 return PP_ERROR_FAILED; | |
| 113 | |
| 114 switch (property) { | |
| 115 case PP_TRANSPORTPROPERTY_STUN_SERVER: { | |
| 116 StringVar* value_str = StringVar::FromPPVar(value); | |
| 117 if (!value_str) | |
| 118 return PP_ERROR_BADARGUMENT; | |
| 119 config_.stun_server = value_str->value(); | |
| 120 break; | |
| 121 } | |
| 122 | |
| 123 case PP_TRANSPORTPROPERTY_RELAY_SERVER: { | |
| 124 StringVar* value_str = StringVar::FromPPVar(value); | |
| 125 if (!value_str) | |
| 126 return PP_ERROR_BADARGUMENT; | |
| 127 config_.relay_server = value_str->value(); | |
| 128 break; | |
| 129 } | |
| 130 | |
| 131 case PP_TRANSPORTPROPERTY_RELAY_TOKEN: { | |
| 132 StringVar* value_str = StringVar::FromPPVar(value); | |
| 133 if (!value_str) | |
| 134 return PP_ERROR_BADARGUMENT; | |
| 135 config_.relay_token = value_str->value(); | |
| 136 break; | |
| 137 } | |
| 138 | |
| 139 case PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW: { | |
| 140 if (!use_tcp_) | |
| 141 return PP_ERROR_BADARGUMENT; | |
| 142 | |
| 143 int32_t int_value = value.value.as_int; | |
| 144 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize || | |
| 145 int_value > kMaxBufferSize) { | |
| 146 return PP_ERROR_BADARGUMENT; | |
| 147 } | |
| 148 config_.tcp_receive_window = int_value; | |
| 149 break; | |
| 150 } | |
| 151 | |
| 152 case PP_TRANSPORTPROPERTY_TCP_SEND_WINDOW: { | |
| 153 if (!use_tcp_) | |
| 154 return PP_ERROR_BADARGUMENT; | |
| 155 | |
| 156 int32_t int_value = value.value.as_int; | |
| 157 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize || | |
| 158 int_value > kMaxBufferSize) { | |
| 159 return PP_ERROR_BADARGUMENT; | |
| 160 } | |
| 161 config_.tcp_send_window = int_value; | |
| 162 break; | |
| 163 } | |
| 164 | |
| 165 default: | |
| 166 return PP_ERROR_BADARGUMENT; | |
| 167 }; | |
|
brettw
2011/08/25 16:48:43
Don't think you need the ;
Sergey Ulanov
2011/08/25 17:36:53
Done.
| |
| 168 | |
| 169 return PP_OK; | |
| 170 } | |
| 171 | |
| 100 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { | 172 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { |
| 101 if (!p2p_transport_.get()) | 173 if (!p2p_transport_.get()) |
| 102 return PP_ERROR_FAILED; | 174 return PP_ERROR_FAILED; |
| 103 | 175 |
| 104 // Connect() has already been called. | 176 // Connect() has already been called. |
| 105 if (started_) | 177 if (started_) |
| 106 return PP_ERROR_INPROGRESS; | 178 return PP_ERROR_INPROGRESS; |
| 107 | 179 |
| 108 P2PTransport::Protocol protocol = use_tcp_ ? | 180 P2PTransport::Protocol protocol = use_tcp_ ? |
| 109 P2PTransport::PROTOCOL_TCP : P2PTransport::PROTOCOL_UDP; | 181 P2PTransport::PROTOCOL_TCP : P2PTransport::PROTOCOL_UDP; |
| 110 | 182 |
| 111 if (!p2p_transport_->Init(name_, protocol, "", this)) | 183 if (!p2p_transport_->Init(name_, protocol, config_, this)) |
| 112 return PP_ERROR_FAILED; | 184 return PP_ERROR_FAILED; |
| 113 | 185 |
| 114 started_ = true; | 186 started_ = true; |
| 115 | 187 |
| 116 connect_callback_ = new TrackedCompletionCallback( | 188 connect_callback_ = new TrackedCompletionCallback( |
| 117 instance()->module()->GetCallbackTracker(), pp_resource(), callback); | 189 instance()->module()->GetCallbackTracker(), pp_resource(), callback); |
| 118 return PP_OK_COMPLETIONPENDING; | 190 return PP_OK_COMPLETIONPENDING; |
| 119 } | 191 } |
| 120 | 192 |
| 121 int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, | 193 int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 void PPB_Transport_Impl::OnWritten(int result) { | 318 void PPB_Transport_Impl::OnWritten(int result) { |
| 247 DCHECK(send_callback_.get() && !send_callback_->completed()); | 319 DCHECK(send_callback_.get() && !send_callback_->completed()); |
| 248 | 320 |
| 249 scoped_refptr<TrackedCompletionCallback> callback; | 321 scoped_refptr<TrackedCompletionCallback> callback; |
| 250 callback.swap(send_callback_); | 322 callback.swap(send_callback_); |
| 251 callback->Run(MapNetError(result)); | 323 callback->Run(MapNetError(result)); |
| 252 } | 324 } |
| 253 | 325 |
| 254 } // namespace ppapi | 326 } // namespace ppapi |
| 255 } // namespace webkit | 327 } // namespace webkit |
| OLD | NEW |