| 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 | 10 | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 52   return broker->GetHandle(handle); | 52   return broker->GetHandle(handle); | 
| 53 } | 53 } | 
| 54 | 54 | 
| 55 const PPB_BrokerTrusted ppb_brokertrusted = { | 55 const PPB_BrokerTrusted ppb_brokertrusted = { | 
| 56   &CreateTrusted, | 56   &CreateTrusted, | 
| 57   &IsBrokerTrusted, | 57   &IsBrokerTrusted, | 
| 58   &Connect, | 58   &Connect, | 
| 59   &GetHandle, | 59   &GetHandle, | 
| 60 }; | 60 }; | 
| 61 | 61 | 
|  | 62 // TODO(ddorwin): Put conversion functions in a common place and/or add an | 
|  | 63 // invalid value to sync_socket.h. | 
|  | 64 int32_t PlatformFileToInt(base::PlatformFile handle) { | 
|  | 65 #if defined(OS_WIN) | 
|  | 66   return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); | 
|  | 67 #elif defined(OS_POSIX) | 
|  | 68   return handle; | 
|  | 69 #else | 
|  | 70   #error Not implemented. | 
|  | 71 #endif | 
|  | 72 } | 
|  | 73 | 
| 62 }  // namespace | 74 }  // namespace | 
| 63 | 75 | 
| 64 // PPB_Broker_Impl ------------------------------------------------------ | 76 // PPB_Broker_Impl ------------------------------------------------------ | 
| 65 | 77 | 
| 66 PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) | 78 PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) | 
| 67     : Resource(instance), | 79     : Resource(instance), | 
| 68       broker_(NULL), | 80       broker_(NULL), | 
| 69       connect_callback_(), | 81       connect_callback_(), | 
| 70       pipe_handle_(0) { | 82       pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { | 
| 71 } | 83 } | 
| 72 | 84 | 
| 73 PPB_Broker_Impl::~PPB_Broker_Impl() { | 85 PPB_Broker_Impl::~PPB_Broker_Impl() { | 
| 74   if (broker_) { | 86   if (broker_) { | 
| 75     broker_->Disconnect(this); | 87     broker_->Disconnect(this); | 
| 76     broker_ = NULL; | 88     broker_ = NULL; | 
| 77   } | 89   } | 
| 78 | 90 | 
| 79   // TODO(ddorwin): Should the plugin or Chrome free the handle? | 91   // The plugin owns the handle. | 
| 80   pipe_handle_ = 0; | 92   pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); | 
| 81 } | 93 } | 
| 82 | 94 | 
| 83 const PPB_BrokerTrusted* PPB_Broker_Impl::GetTrustedInterface() { | 95 const PPB_BrokerTrusted* PPB_Broker_Impl::GetTrustedInterface() { | 
| 84   return &ppb_brokertrusted; | 96   return &ppb_brokertrusted; | 
| 85 } | 97 } | 
| 86 | 98 | 
| 87 int32_t PPB_Broker_Impl::Connect( | 99 int32_t PPB_Broker_Impl::Connect( | 
| 88     PluginDelegate* plugin_delegate, | 100     PluginDelegate* plugin_delegate, | 
| 89     PP_CompletionCallback connect_callback) { | 101     PP_CompletionCallback connect_callback) { | 
| 90   // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 102   // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 101   PP_Resource resource_id = GetReferenceNoAddRef(); | 113   PP_Resource resource_id = GetReferenceNoAddRef(); | 
| 102   CHECK(resource_id); | 114   CHECK(resource_id); | 
| 103   connect_callback_ = new TrackedCompletionCallback( | 115   connect_callback_ = new TrackedCompletionCallback( | 
| 104       instance()->module()->GetCallbackTracker(), resource_id, | 116       instance()->module()->GetCallbackTracker(), resource_id, | 
| 105       connect_callback); | 117       connect_callback); | 
| 106   return PP_OK_COMPLETIONPENDING; | 118   return PP_OK_COMPLETIONPENDING; | 
| 107 } | 119 } | 
| 108 | 120 | 
| 109 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { | 121 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { | 
| 110   *handle = pipe_handle_; | 122   *handle = pipe_handle_; | 
| 111 |  | 
| 112   if (!*handle) |  | 
| 113     return PP_ERROR_FAILED; |  | 
| 114 |  | 
| 115   return PP_OK; | 123   return PP_OK; | 
| 116 } | 124 } | 
| 117 | 125 | 
| 118 PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() { | 126 PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() { | 
| 119   return this; | 127   return this; | 
| 120 } | 128 } | 
| 121 | 129 | 
|  | 130 // Transfers ownership of the handle to the plugin. | 
| 122 void PPB_Broker_Impl::BrokerConnected(int32_t handle) { | 131 void PPB_Broker_Impl::BrokerConnected(int32_t handle) { | 
| 123   DCHECK(handle); | 132   DCHECK(handle); | 
| 124   pipe_handle_ = handle; | 133   pipe_handle_ = handle; | 
| 125 | 134 | 
| 126   // Synchronous calls are not supported. | 135   // Synchronous calls are not supported. | 
| 127   DCHECK(connect_callback_.get() && !connect_callback_->completed()); | 136   DCHECK(connect_callback_.get() && !connect_callback_->completed()); | 
| 128 | 137 | 
| 129   scoped_refptr<TrackedCompletionCallback> callback; | 138   scoped_refptr<TrackedCompletionCallback> callback; | 
| 130   callback.swap(connect_callback_); | 139   callback.swap(connect_callback_); | 
| 131   callback->Run(0);  // Will complete abortively if necessary. | 140   callback->Run(PP_OK);  // Will complete abortively if necessary. | 
| 132 } | 141 } | 
| 133 | 142 | 
| 134 }  // namespace ppapi | 143 }  // namespace ppapi | 
| 135 }  // namespace webkit | 144 }  // namespace webkit | 
| OLD | NEW | 
|---|