| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 net::Socket* channel = p2p_transport_->GetChannel(); | 313 net::Socket* channel = p2p_transport_->GetChannel(); |
| 318 if (!channel) | 314 if (!channel) |
| 319 return PP_ERROR_FAILED; | 315 return PP_ERROR_FAILED; |
| 320 | 316 |
| 321 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 317 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 322 if (!plugin_module) | 318 if (!plugin_module) |
| 323 return PP_ERROR_FAILED; | 319 return PP_ERROR_FAILED; |
| 324 | 320 |
| 325 scoped_refptr<net::IOBuffer> buffer = | 321 scoped_refptr<net::IOBuffer> buffer = |
| 326 new net::WrappedIOBuffer(static_cast<const char*>(data)); | 322 new net::WrappedIOBuffer(static_cast<const char*>(data)); |
| 327 int result = MapNetError(channel->Read(buffer, len, &channel_read_callback_)); | 323 int result = MapNetError( |
| 324 channel->Read(buffer, len, base::Bind(&PPB_Transport_Impl::OnRead, |
| 325 base::Unretained(this)))); |
| 328 if (result == PP_OK_COMPLETIONPENDING) { | 326 if (result == PP_OK_COMPLETIONPENDING) { |
| 329 recv_callback_ = new TrackedCompletionCallback( | 327 recv_callback_ = new TrackedCompletionCallback( |
| 330 plugin_module->GetCallbackTracker(), pp_resource(), callback); | 328 plugin_module->GetCallbackTracker(), pp_resource(), callback); |
| 331 } | 329 } |
| 332 | 330 |
| 333 return result; | 331 return result; |
| 334 } | 332 } |
| 335 | 333 |
| 336 int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, | 334 int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, |
| 337 PP_CompletionCallback callback) { | 335 PP_CompletionCallback callback) { |
| 338 if (!callback.func) | 336 if (!callback.func) |
| 339 return PP_ERROR_BLOCKS_MAIN_THREAD; | 337 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 340 if (!p2p_transport_.get()) | 338 if (!p2p_transport_.get()) |
| 341 return PP_ERROR_FAILED; | 339 return PP_ERROR_FAILED; |
| 342 | 340 |
| 343 if (send_callback_.get() && !send_callback_->completed()) | 341 if (send_callback_.get() && !send_callback_->completed()) |
| 344 return PP_ERROR_INPROGRESS; | 342 return PP_ERROR_INPROGRESS; |
| 345 | 343 |
| 346 net::Socket* channel = p2p_transport_->GetChannel(); | 344 net::Socket* channel = p2p_transport_->GetChannel(); |
| 347 if (!channel) | 345 if (!channel) |
| 348 return PP_ERROR_FAILED; | 346 return PP_ERROR_FAILED; |
| 349 | 347 |
| 350 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 348 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 351 if (!plugin_module) | 349 if (!plugin_module) |
| 352 return PP_ERROR_FAILED; | 350 return PP_ERROR_FAILED; |
| 353 | 351 |
| 354 scoped_refptr<net::IOBuffer> buffer = | 352 scoped_refptr<net::IOBuffer> buffer = |
| 355 new net::WrappedIOBuffer(static_cast<const char*>(data)); | 353 new net::WrappedIOBuffer(static_cast<const char*>(data)); |
| 356 int result = MapNetError(channel->Write(buffer, len, | 354 int result = MapNetError( |
| 357 &channel_write_callback_)); | 355 channel->Write(buffer, len, base::Bind(&PPB_Transport_Impl::OnWritten, |
| 356 base::Unretained(this)))); |
| 358 if (result == PP_OK_COMPLETIONPENDING) { | 357 if (result == PP_OK_COMPLETIONPENDING) { |
| 359 send_callback_ = new TrackedCompletionCallback( | 358 send_callback_ = new TrackedCompletionCallback( |
| 360 plugin_module->GetCallbackTracker(), pp_resource(), callback); | 359 plugin_module->GetCallbackTracker(), pp_resource(), callback); |
| 361 } | 360 } |
| 362 | 361 |
| 363 return result; | 362 return result; |
| 364 } | 363 } |
| 365 | 364 |
| 366 int32_t PPB_Transport_Impl::Close() { | 365 int32_t PPB_Transport_Impl::Close() { |
| 367 if (!p2p_transport_.get()) | 366 if (!p2p_transport_.get()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 void PPB_Transport_Impl::OnWritten(int result) { | 414 void PPB_Transport_Impl::OnWritten(int result) { |
| 416 DCHECK(send_callback_.get() && !send_callback_->completed()); | 415 DCHECK(send_callback_.get() && !send_callback_->completed()); |
| 417 | 416 |
| 418 scoped_refptr<TrackedCompletionCallback> callback; | 417 scoped_refptr<TrackedCompletionCallback> callback; |
| 419 callback.swap(send_callback_); | 418 callback.swap(send_callback_); |
| 420 callback->Run(MapNetError(result)); | 419 callback->Run(MapNetError(result)); |
| 421 } | 420 } |
| 422 | 421 |
| 423 } // namespace ppapi | 422 } // namespace ppapi |
| 424 } // namespace webkit | 423 } // namespace webkit |
| OLD | NEW |