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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 if (!plugin_instance) | 61 if (!plugin_instance) |
62 return NULL; | 62 return NULL; |
63 return plugin_instance->container()->element().document().frame(); | 63 return plugin_instance->container()->element().document().frame(); |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 PPB_Transport_Impl::PPB_Transport_Impl(PP_Instance instance) | 68 PPB_Transport_Impl::PPB_Transport_Impl(PP_Instance instance) |
69 : Resource(instance), | 69 : Resource(instance), |
70 started_(false), | 70 started_(false), |
71 writable_(false), | 71 writable_(false) { |
72 ALLOW_THIS_IN_INITIALIZER_LIST( | |
73 channel_write_callback_(this, &PPB_Transport_Impl::OnWritten)), | |
74 ALLOW_THIS_IN_INITIALIZER_LIST( | |
75 channel_read_callback_(this, &PPB_Transport_Impl::OnRead)) { | |
76 } | 72 } |
77 | 73 |
78 PPB_Transport_Impl::~PPB_Transport_Impl() { | 74 PPB_Transport_Impl::~PPB_Transport_Impl() { |
79 } | 75 } |
80 | 76 |
81 // static | 77 // static |
82 PP_Resource PPB_Transport_Impl::Create(PP_Instance instance, | 78 PP_Resource PPB_Transport_Impl::Create(PP_Instance instance, |
83 const char* name, | 79 const char* name, |
84 PP_TransportType type) { | 80 PP_TransportType type) { |
85 scoped_refptr<PPB_Transport_Impl> t(new PPB_Transport_Impl(instance)); | 81 scoped_refptr<PPB_Transport_Impl> t(new PPB_Transport_Impl(instance)); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 net::Socket* channel = p2p_transport_->GetChannel(); | 312 net::Socket* channel = p2p_transport_->GetChannel(); |
317 if (!channel) | 313 if (!channel) |
318 return PP_ERROR_FAILED; | 314 return PP_ERROR_FAILED; |
319 | 315 |
320 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 316 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
321 if (!plugin_module) | 317 if (!plugin_module) |
322 return PP_ERROR_FAILED; | 318 return PP_ERROR_FAILED; |
323 | 319 |
324 scoped_refptr<net::IOBuffer> buffer = | 320 scoped_refptr<net::IOBuffer> buffer = |
325 new net::WrappedIOBuffer(static_cast<const char*>(data)); | 321 new net::WrappedIOBuffer(static_cast<const char*>(data)); |
326 int result = MapNetError(channel->Read(buffer, len, &channel_read_callback_)); | 322 int result = MapNetError( |
| 323 channel->Read(buffer, len, base::Bind(&PPB_Transport_Impl::OnRead, |
| 324 base::Unretained(this)))); |
327 if (result == PP_OK_COMPLETIONPENDING) { | 325 if (result == PP_OK_COMPLETIONPENDING) { |
328 recv_callback_ = new TrackedCompletionCallback( | 326 recv_callback_ = new TrackedCompletionCallback( |
329 plugin_module->GetCallbackTracker(), pp_resource(), callback); | 327 plugin_module->GetCallbackTracker(), pp_resource(), callback); |
330 } | 328 } |
331 | 329 |
332 return result; | 330 return result; |
333 } | 331 } |
334 | 332 |
335 int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, | 333 int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, |
336 PP_CompletionCallback callback) { | 334 PP_CompletionCallback callback) { |
337 if (!callback.func) | 335 if (!callback.func) |
338 return PP_ERROR_BLOCKS_MAIN_THREAD; | 336 return PP_ERROR_BLOCKS_MAIN_THREAD; |
339 if (!p2p_transport_.get()) | 337 if (!p2p_transport_.get()) |
340 return PP_ERROR_FAILED; | 338 return PP_ERROR_FAILED; |
341 | 339 |
342 if (send_callback_.get() && !send_callback_->completed()) | 340 if (send_callback_.get() && !send_callback_->completed()) |
343 return PP_ERROR_INPROGRESS; | 341 return PP_ERROR_INPROGRESS; |
344 | 342 |
345 net::Socket* channel = p2p_transport_->GetChannel(); | 343 net::Socket* channel = p2p_transport_->GetChannel(); |
346 if (!channel) | 344 if (!channel) |
347 return PP_ERROR_FAILED; | 345 return PP_ERROR_FAILED; |
348 | 346 |
349 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 347 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
350 if (!plugin_module) | 348 if (!plugin_module) |
351 return PP_ERROR_FAILED; | 349 return PP_ERROR_FAILED; |
352 | 350 |
353 scoped_refptr<net::IOBuffer> buffer = | 351 scoped_refptr<net::IOBuffer> buffer = |
354 new net::WrappedIOBuffer(static_cast<const char*>(data)); | 352 new net::WrappedIOBuffer(static_cast<const char*>(data)); |
355 int result = MapNetError(channel->Write(buffer, len, | 353 int result = MapNetError( |
356 &channel_write_callback_)); | 354 channel->Write(buffer, len, base::Bind(&PPB_Transport_Impl::OnWritten, |
| 355 base::Unretained(this)))); |
357 if (result == PP_OK_COMPLETIONPENDING) { | 356 if (result == PP_OK_COMPLETIONPENDING) { |
358 send_callback_ = new TrackedCompletionCallback( | 357 send_callback_ = new TrackedCompletionCallback( |
359 plugin_module->GetCallbackTracker(), pp_resource(), callback); | 358 plugin_module->GetCallbackTracker(), pp_resource(), callback); |
360 } | 359 } |
361 | 360 |
362 return result; | 361 return result; |
363 } | 362 } |
364 | 363 |
365 int32_t PPB_Transport_Impl::Close() { | 364 int32_t PPB_Transport_Impl::Close() { |
366 if (!p2p_transport_.get()) | 365 if (!p2p_transport_.get()) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 void PPB_Transport_Impl::OnWritten(int result) { | 413 void PPB_Transport_Impl::OnWritten(int result) { |
415 DCHECK(send_callback_.get() && !send_callback_->completed()); | 414 DCHECK(send_callback_.get() && !send_callback_->completed()); |
416 | 415 |
417 scoped_refptr<TrackedCompletionCallback> callback; | 416 scoped_refptr<TrackedCompletionCallback> callback; |
418 callback.swap(send_callback_); | 417 callback.swap(send_callback_); |
419 callback->Run(MapNetError(result)); | 418 callback->Run(MapNetError(result)); |
420 } | 419 } |
421 | 420 |
422 } // namespace ppapi | 421 } // namespace ppapi |
423 } // namespace webkit | 422 } // namespace webkit |
OLD | NEW |