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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 namespace webkit { | 26 namespace webkit { |
27 namespace ppapi { | 27 namespace ppapi { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kUdpProtocolName[] = "udp"; | 31 const char kUdpProtocolName[] = "udp"; |
32 const char kTcpProtocolName[] = "tcp"; | 32 const char kTcpProtocolName[] = "tcp"; |
33 | 33 |
34 const int kMinBufferSize = 1024; | 34 const int kMinBufferSize = 1024; |
35 const int kMaxBufferSize = 1024 * 1024; | 35 const int kMaxBufferSize = 1024 * 1024; |
36 const int kMinAckDelay = 10; | |
37 const int kMaxAckDelay = 1000; | |
36 | 38 |
37 int MapNetError(int result) { | 39 int MapNetError(int result) { |
38 if (result > 0) | 40 if (result > 0) |
39 return result; | 41 return result; |
40 | 42 |
41 switch (result) { | 43 switch (result) { |
42 case net::OK: | 44 case net::OK: |
43 return PP_OK; | 45 return PP_OK; |
44 case net::ERR_IO_PENDING: | 46 case net::ERR_IO_PENDING: |
45 return PP_OK_COMPLETIONPENDING; | 47 return PP_OK_COMPLETIONPENDING; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 165 |
164 int32_t int_value = value.value.as_int; | 166 int32_t int_value = value.value.as_int; |
165 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize || | 167 if (value.type != PP_VARTYPE_INT32 || int_value < kMinBufferSize || |
166 int_value > kMaxBufferSize) { | 168 int_value > kMaxBufferSize) { |
167 return PP_ERROR_BADARGUMENT; | 169 return PP_ERROR_BADARGUMENT; |
168 } | 170 } |
169 config_.tcp_send_window = int_value; | 171 config_.tcp_send_window = int_value; |
170 break; | 172 break; |
171 } | 173 } |
172 | 174 |
175 case PP_TRANSPORTPROPERTY_TCP_NO_DELAY: { | |
176 if (!use_tcp_) | |
177 return PP_ERROR_BADARGUMENT; | |
178 | |
179 if (value.type != PP_VARTYPE_BOOL) { | |
brettw
2011/09/01 16:49:19
No {} for single-line (for consistency).
Sergey Ulanov
2011/09/03 21:10:02
Done.
| |
180 return PP_ERROR_BADARGUMENT; | |
181 } | |
182 config_.tcp_receive_window = value.value.as_bool; | |
brettw
2011/09/01 16:49:19
Copy paste error: you meant to set no_delay.
Sergey Ulanov
2011/09/03 21:10:02
Done.
| |
183 break; | |
184 } | |
185 | |
186 case PP_TRANSPORTPROPERTY_TCP_ACK_DELAY: { | |
187 if (!use_tcp_) | |
188 return PP_ERROR_BADARGUMENT; | |
189 | |
190 int32_t int_value = value.value.as_int; | |
191 if (value.type != PP_VARTYPE_INT32 || int_value < kMinAckDelay || | |
192 int_value > kMaxAckDelay) { | |
193 return PP_ERROR_BADARGUMENT; | |
194 } | |
195 config_.tcp_ack_delay_ms = int_value; | |
196 break; | |
197 } | |
198 | |
173 default: | 199 default: |
174 return PP_ERROR_BADARGUMENT; | 200 return PP_ERROR_BADARGUMENT; |
175 } | 201 } |
176 | 202 |
177 return PP_OK; | 203 return PP_OK; |
178 } | 204 } |
179 | 205 |
180 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { | 206 int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { |
181 if (!p2p_transport_.get()) | 207 if (!p2p_transport_.get()) |
182 return PP_ERROR_FAILED; | 208 return PP_ERROR_FAILED; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 | 318 |
293 return result; | 319 return result; |
294 } | 320 } |
295 | 321 |
296 int32_t PPB_Transport_Impl::Close() { | 322 int32_t PPB_Transport_Impl::Close() { |
297 if (!p2p_transport_.get()) | 323 if (!p2p_transport_.get()) |
298 return PP_ERROR_FAILED; | 324 return PP_ERROR_FAILED; |
299 | 325 |
300 p2p_transport_.reset(); | 326 p2p_transport_.reset(); |
301 | 327 |
302 | |
303 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 328 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
304 if (plugin_module) | 329 if (plugin_module) |
305 plugin_module->GetCallbackTracker()->AbortAll(); | 330 plugin_module->GetCallbackTracker()->AbortAll(); |
306 return PP_OK; | 331 return PP_OK; |
307 } | 332 } |
308 | 333 |
309 void PPB_Transport_Impl::OnCandidateReady(const std::string& address) { | 334 void PPB_Transport_Impl::OnCandidateReady(const std::string& address) { |
310 // Store the candidate first before calling the callback. | 335 // Store the candidate first before calling the callback. |
311 local_candidates_.push_back(address); | 336 local_candidates_.push_back(address); |
312 | 337 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 void PPB_Transport_Impl::OnWritten(int result) { | 371 void PPB_Transport_Impl::OnWritten(int result) { |
347 DCHECK(send_callback_.get() && !send_callback_->completed()); | 372 DCHECK(send_callback_.get() && !send_callback_->completed()); |
348 | 373 |
349 scoped_refptr<TrackedCompletionCallback> callback; | 374 scoped_refptr<TrackedCompletionCallback> callback; |
350 callback.swap(send_callback_); | 375 callback.swap(send_callback_); |
351 callback->Run(MapNetError(result)); | 376 callback->Run(MapNetError(result)); |
352 } | 377 } |
353 | 378 |
354 } // namespace ppapi | 379 } // namespace ppapi |
355 } // namespace webkit | 380 } // namespace webkit |
OLD | NEW |