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/broker_dispatcher.h" | 5 #include "ppapi/proxy/broker_dispatcher.h" |
6 | 6 |
7 #include "base/sync_socket.h" | 7 #include "base/sync_socket.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
| 10 #include "ppapi/shared_impl/platform_file.h" |
10 | 11 |
11 namespace ppapi { | 12 namespace ppapi { |
12 namespace proxy { | 13 namespace proxy { |
13 | 14 |
14 namespace { | |
15 | |
16 int32_t PlatformFileToInt(base::PlatformFile handle) { | |
17 #if defined(OS_WIN) | |
18 return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); | |
19 #elif defined(OS_POSIX) | |
20 return handle; | |
21 #else | |
22 #error Not implemented. | |
23 #endif | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 BrokerDispatcher::BrokerDispatcher(base::ProcessHandle remote_process_handle, | 15 BrokerDispatcher::BrokerDispatcher(base::ProcessHandle remote_process_handle, |
29 PP_ConnectInstance_Func connect_instance) | 16 PP_ConnectInstance_Func connect_instance) |
30 : ProxyChannel(remote_process_handle), | 17 : ProxyChannel(remote_process_handle), |
31 connect_instance_(connect_instance) { | 18 connect_instance_(connect_instance) { |
32 } | 19 } |
33 | 20 |
34 BrokerDispatcher::~BrokerDispatcher() { | 21 BrokerDispatcher::~BrokerDispatcher() { |
35 } | 22 } |
36 | 23 |
37 bool BrokerDispatcher::InitBrokerWithChannel( | 24 bool BrokerDispatcher::InitBrokerWithChannel( |
(...skipping 21 matching lines...) Expand all Loading... |
59 PP_Instance instance, | 46 PP_Instance instance, |
60 IPC::PlatformFileForTransit handle, | 47 IPC::PlatformFileForTransit handle, |
61 int32_t* result) { | 48 int32_t* result) { |
62 if (handle == IPC::InvalidPlatformFileForTransit()) { | 49 if (handle == IPC::InvalidPlatformFileForTransit()) { |
63 *result = PP_ERROR_FAILED; | 50 *result = PP_ERROR_FAILED; |
64 } else { | 51 } else { |
65 base::SyncSocket::Handle socket_handle = | 52 base::SyncSocket::Handle socket_handle = |
66 IPC::PlatformFileForTransitToPlatformFile(handle); | 53 IPC::PlatformFileForTransitToPlatformFile(handle); |
67 | 54 |
68 if (connect_instance_) { | 55 if (connect_instance_) { |
69 *result = connect_instance_(instance, PlatformFileToInt(socket_handle)); | 56 *result = connect_instance_(instance, |
| 57 ppapi::PlatformFileToInt(socket_handle)); |
70 } else { | 58 } else { |
71 *result = PP_ERROR_FAILED; | 59 *result = PP_ERROR_FAILED; |
72 // Close the handle since there is no other owner. | 60 // Close the handle since there is no other owner. |
73 // The easiest way to clean it up is to just put it in an object | 61 // The easiest way to clean it up is to just put it in an object |
74 // and then close them. This failure case is not performance critical. | 62 // and then close them. This failure case is not performance critical. |
75 base::SyncSocket temp_socket(socket_handle); | 63 base::SyncSocket temp_socket(socket_handle); |
76 } | 64 } |
77 } | 65 } |
78 } | 66 } |
79 | 67 |
(...skipping 24 matching lines...) Expand all Loading... |
104 // The renderer has crashed or exited. This channel and all instances | 92 // The renderer has crashed or exited. This channel and all instances |
105 // associated with it are no longer valid. | 93 // associated with it are no longer valid. |
106 // TODO(ddorwin): This causes the broker process to exit, which may not be | 94 // TODO(ddorwin): This causes the broker process to exit, which may not be |
107 // desirable in some use cases. | 95 // desirable in some use cases. |
108 delete this; | 96 delete this; |
109 } | 97 } |
110 | 98 |
111 | 99 |
112 } // namespace proxy | 100 } // namespace proxy |
113 } // namespace ppapi | 101 } // namespace ppapi |
OLD | NEW |