| 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_broker_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_broker_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "webkit/plugins/ppapi/common.h" | 8 #include "webkit/plugins/ppapi/common.h" |
| 9 #include "webkit/plugins/ppapi/plugin_module.h" | 9 #include "webkit/plugins/ppapi/plugin_module.h" |
| 10 #include "webkit/plugins/ppapi/resource_helper.h" |
| 10 | 11 |
| 11 using ::ppapi::thunk::PPB_Broker_API; | 12 using ::ppapi::thunk::PPB_Broker_API; |
| 12 | 13 |
| 13 namespace webkit { | 14 namespace webkit { |
| 14 namespace ppapi { | 15 namespace ppapi { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // TODO(ddorwin): Put conversion functions in a common place and/or add an | 19 // TODO(ddorwin): Put conversion functions in a common place and/or add an |
| 19 // invalid value to sync_socket.h. | 20 // invalid value to sync_socket.h. |
| 20 int32_t PlatformFileToInt(base::PlatformFile handle) { | 21 int32_t PlatformFileToInt(base::PlatformFile handle) { |
| 21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 22 return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); | 23 return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); |
| 23 #elif defined(OS_POSIX) | 24 #elif defined(OS_POSIX) |
| 24 return handle; | 25 return handle; |
| 25 #else | 26 #else |
| 26 #error Not implemented. | 27 #error Not implemented. |
| 27 #endif | 28 #endif |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 // PPB_Broker_Impl ------------------------------------------------------ | 33 // PPB_Broker_Impl ------------------------------------------------------ |
| 33 | 34 |
| 34 PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) | 35 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) |
| 35 : Resource(instance), | 36 : Resource(instance), |
| 36 broker_(NULL), | 37 broker_(NULL), |
| 37 connect_callback_(), | 38 connect_callback_(), |
| 38 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { | 39 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 PPB_Broker_Impl::~PPB_Broker_Impl() { | 42 PPB_Broker_Impl::~PPB_Broker_Impl() { |
| 42 if (broker_) { | 43 if (broker_) { |
| 43 broker_->Disconnect(this); | 44 broker_->Disconnect(this); |
| 44 broker_ = NULL; | 45 broker_ = NULL; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 return PP_ERROR_BADARGUMENT; | 59 return PP_ERROR_BADARGUMENT; |
| 59 } | 60 } |
| 60 | 61 |
| 61 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 62 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. |
| 62 | 63 |
| 63 if (broker_) { | 64 if (broker_) { |
| 64 // May only be called once. | 65 // May only be called once. |
| 65 return PP_ERROR_FAILED; | 66 return PP_ERROR_FAILED; |
| 66 } | 67 } |
| 67 | 68 |
| 69 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 70 if (!plugin_instance) |
| 71 return PP_ERROR_FAILED; |
| 72 |
| 68 // The callback must be populated now in case we are connected to the broker | 73 // The callback must be populated now in case we are connected to the broker |
| 69 // and BrokerConnected is called before ConnectToPpapiBroker returns. | 74 // and BrokerConnected is called before ConnectToPpapiBroker returns. |
| 70 // Because it must be created now, it must be aborted and cleared if | 75 // Because it must be created now, it must be aborted and cleared if |
| 71 // ConnectToPpapiBroker fails. | 76 // ConnectToPpapiBroker fails. |
| 72 connect_callback_ = new TrackedCompletionCallback( | 77 connect_callback_ = new TrackedCompletionCallback( |
| 73 instance()->module()->GetCallbackTracker(), pp_resource(), | 78 plugin_instance->module()->GetCallbackTracker(), pp_resource(), |
| 74 connect_callback); | 79 connect_callback); |
| 75 | 80 |
| 76 broker_ = instance()->delegate()->ConnectToPpapiBroker(this); | 81 broker_ = plugin_instance->delegate()->ConnectToPpapiBroker(this); |
| 77 if (!broker_) { | 82 if (!broker_) { |
| 78 scoped_refptr<TrackedCompletionCallback> callback; | 83 scoped_refptr<TrackedCompletionCallback> callback; |
| 79 callback.swap(connect_callback_); | 84 callback.swap(connect_callback_); |
| 80 callback->Abort(); | 85 callback->Abort(); |
| 81 return PP_ERROR_FAILED; | 86 return PP_ERROR_FAILED; |
| 82 } | 87 } |
| 83 | 88 |
| 84 return PP_OK_COMPLETIONPENDING; | 89 return PP_OK_COMPLETIONPENDING; |
| 85 } | 90 } |
| 86 | 91 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 103 // Synchronous calls are not supported. | 108 // Synchronous calls are not supported. |
| 104 DCHECK(connect_callback_.get() && !connect_callback_->completed()); | 109 DCHECK(connect_callback_.get() && !connect_callback_->completed()); |
| 105 | 110 |
| 106 scoped_refptr<TrackedCompletionCallback> callback; | 111 scoped_refptr<TrackedCompletionCallback> callback; |
| 107 callback.swap(connect_callback_); | 112 callback.swap(connect_callback_); |
| 108 callback->Run(result); // Will complete abortively if necessary. | 113 callback->Run(result); // Will complete abortively if necessary. |
| 109 } | 114 } |
| 110 | 115 |
| 111 } // namespace ppapi | 116 } // namespace ppapi |
| 112 } // namespace webkit | 117 } // namespace webkit |
| OLD | NEW |