| 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 "ppapi/proxy/ppb_broker_proxy.h" | 5 #include "ppapi/proxy/ppb_broker_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/c/trusted/ppb_broker_trusted.h" | 9 #include "ppapi/c/trusted/ppb_broker_trusted.h" |
| 10 #include "ppapi/proxy/enter_proxy.h" | 10 #include "ppapi/proxy/enter_proxy.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (current_connect_callback_.func) | 105 if (current_connect_callback_.func) |
| 106 return PP_ERROR_INPROGRESS; | 106 return PP_ERROR_INPROGRESS; |
| 107 else if (called_connect_) | 107 else if (called_connect_) |
| 108 return PP_ERROR_FAILED; | 108 return PP_ERROR_FAILED; |
| 109 | 109 |
| 110 current_connect_callback_ = connect_callback; | 110 current_connect_callback_ = connect_callback; |
| 111 called_connect_ = true; | 111 called_connect_ = true; |
| 112 | 112 |
| 113 bool success = PluginDispatcher::GetForResource(this)->Send( | 113 bool success = PluginDispatcher::GetForResource(this)->Send( |
| 114 new PpapiHostMsg_PPBBroker_Connect( | 114 new PpapiHostMsg_PPBBroker_Connect( |
| 115 INTERFACE_ID_PPB_BROKER, host_resource())); | 115 API_ID_PPB_BROKER, host_resource())); |
| 116 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; | 116 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; |
| 117 } | 117 } |
| 118 | 118 |
| 119 int32_t Broker::GetHandle(int32_t* handle) { | 119 int32_t Broker::GetHandle(int32_t* handle) { |
| 120 if (socket_handle_ == base::kInvalidPlatformFileValue) | 120 if (socket_handle_ == base::kInvalidPlatformFileValue) |
| 121 return PP_ERROR_FAILED; | 121 return PP_ERROR_FAILED; |
| 122 *handle = PlatformFileToInt(socket_handle_); | 122 *handle = PlatformFileToInt(socket_handle_); |
| 123 return PP_OK; | 123 return PP_OK; |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 // static | 155 // static |
| 156 PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { | 156 PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { |
| 157 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 157 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 158 if (!dispatcher) | 158 if (!dispatcher) |
| 159 return 0; | 159 return 0; |
| 160 | 160 |
| 161 HostResource result; | 161 HostResource result; |
| 162 dispatcher->Send(new PpapiHostMsg_PPBBroker_Create( | 162 dispatcher->Send(new PpapiHostMsg_PPBBroker_Create( |
| 163 INTERFACE_ID_PPB_BROKER, instance, &result)); | 163 API_ID_PPB_BROKER, instance, &result)); |
| 164 if (result.is_null()) | 164 if (result.is_null()) |
| 165 return 0; | 165 return 0; |
| 166 return (new Broker(result))->GetReference(); | 166 return (new Broker(result))->GetReference(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { | 169 bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 170 bool handled = true; | 170 bool handled = true; |
| 171 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Proxy, msg) | 171 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Proxy, msg) |
| 172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Create, OnMsgCreate) | 172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Create, OnMsgCreate) |
| 173 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Connect, OnMsgConnect) | 173 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Connect, OnMsgConnect) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 result = PP_ERROR_FAILED; | 241 result = PP_ERROR_FAILED; |
| 242 // Assume the local handle was closed even if the foreign handle could | 242 // Assume the local handle was closed even if the foreign handle could |
| 243 // not be created. | 243 // not be created. |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 DCHECK(result == PP_OK || | 247 DCHECK(result == PP_OK || |
| 248 foreign_socket_handle == IPC::InvalidPlatformFileForTransit()); | 248 foreign_socket_handle == IPC::InvalidPlatformFileForTransit()); |
| 249 | 249 |
| 250 bool success = dispatcher()->Send(new PpapiMsg_PPBBroker_ConnectComplete( | 250 bool success = dispatcher()->Send(new PpapiMsg_PPBBroker_ConnectComplete( |
| 251 INTERFACE_ID_PPB_BROKER, broker, foreign_socket_handle, result)); | 251 API_ID_PPB_BROKER, broker, foreign_socket_handle, result)); |
| 252 | 252 |
| 253 if (!success || result != PP_OK) { | 253 if (!success || result != PP_OK) { |
| 254 // The plugin did not receive the handle, so it must be closed. | 254 // The plugin did not receive the handle, so it must be closed. |
| 255 // The easiest way to clean it up is to just put it in an object | 255 // The easiest way to clean it up is to just put it in an object |
| 256 // and then close it. This failure case is not performance critical. | 256 // and then close it. This failure case is not performance critical. |
| 257 // The handle could still leak if Send succeeded but the IPC later failed. | 257 // The handle could still leak if Send succeeded but the IPC later failed. |
| 258 base::SyncSocket temp_socket( | 258 base::SyncSocket temp_socket( |
| 259 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); | 259 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace proxy | 263 } // namespace proxy |
| 264 } // namespace ppapi | 264 } // namespace ppapi |
| OLD | NEW |