Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ppapi/proxy/ppb_broker_proxy.cc

Issue 316363003: Remove base::kInvalidPlatformFileValue from components, ipc and ppapi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_platform_file.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // sends the IPC. This member holds the handle value for the plugin module 50 // sends the IPC. This member holds the handle value for the plugin module
51 // to read, but the plugin side of the proxy never takes ownership. 51 // to read, but the plugin side of the proxy never takes ownership.
52 base::SyncSocket::Handle socket_handle_; 52 base::SyncSocket::Handle socket_handle_;
53 53
54 DISALLOW_COPY_AND_ASSIGN(Broker); 54 DISALLOW_COPY_AND_ASSIGN(Broker);
55 }; 55 };
56 56
57 Broker::Broker(const HostResource& resource) 57 Broker::Broker(const HostResource& resource)
58 : Resource(OBJECT_IS_PROXY, resource), 58 : Resource(OBJECT_IS_PROXY, resource),
59 called_connect_(false), 59 called_connect_(false),
60 socket_handle_(base::kInvalidPlatformFileValue) { 60 socket_handle_(base::SyncSocket::kInvalidHandle) {
61 } 61 }
62 62
63 Broker::~Broker() { 63 Broker::~Broker() {
64 socket_handle_ = base::kInvalidPlatformFileValue; 64 socket_handle_ = base::SyncSocket::kInvalidHandle;
65 } 65 }
66 66
67 PPB_Broker_API* Broker::AsPPB_Broker_API() { 67 PPB_Broker_API* Broker::AsPPB_Broker_API() {
68 return this; 68 return this;
69 } 69 }
70 70
71 int32_t Broker::Connect(scoped_refptr<TrackedCallback> connect_callback) { 71 int32_t Broker::Connect(scoped_refptr<TrackedCallback> connect_callback) {
72 if (TrackedCallback::IsPending(current_connect_callback_)) 72 if (TrackedCallback::IsPending(current_connect_callback_))
73 return PP_ERROR_INPROGRESS; 73 return PP_ERROR_INPROGRESS;
74 else if (called_connect_) 74 else if (called_connect_)
75 return PP_ERROR_FAILED; 75 return PP_ERROR_FAILED;
76 76
77 current_connect_callback_ = connect_callback; 77 current_connect_callback_ = connect_callback;
78 called_connect_ = true; 78 called_connect_ = true;
79 79
80 bool success = PluginDispatcher::GetForResource(this)->Send( 80 bool success = PluginDispatcher::GetForResource(this)->Send(
81 new PpapiHostMsg_PPBBroker_Connect( 81 new PpapiHostMsg_PPBBroker_Connect(
82 API_ID_PPB_BROKER, host_resource())); 82 API_ID_PPB_BROKER, host_resource()));
83 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; 83 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED;
84 } 84 }
85 85
86 int32_t Broker::GetHandle(int32_t* handle) { 86 int32_t Broker::GetHandle(int32_t* handle) {
87 if (socket_handle_ == base::kInvalidPlatformFileValue) 87 if (socket_handle_ == base::SyncSocket::kInvalidHandle)
88 return PP_ERROR_FAILED; 88 return PP_ERROR_FAILED;
89 *handle = PlatformFileToInt(socket_handle_); 89 *handle = PlatformFileToInt(socket_handle_);
90 return PP_OK; 90 return PP_OK;
91 } 91 }
92 92
93 void Broker::ConnectComplete(IPC::PlatformFileForTransit socket_handle, 93 void Broker::ConnectComplete(IPC::PlatformFileForTransit socket_handle,
94 int32_t result) { 94 int32_t result) {
95 if (result == PP_OK) { 95 if (result == PP_OK) {
96 DCHECK(socket_handle_ == base::kInvalidPlatformFileValue); 96 DCHECK(socket_handle_ == base::SyncSocket::kInvalidHandle);
97 socket_handle_ = IPC::PlatformFileForTransitToPlatformFile(socket_handle); 97 socket_handle_ = IPC::PlatformFileForTransitToPlatformFile(socket_handle);
98 } else { 98 } else {
99 // The caller may still have given us a handle in the failure case. 99 // The caller may still have given us a handle in the failure case.
100 // The easiest way to clean it up is to just put it in an object 100 // The easiest way to clean it up is to just put it in an object
101 // and then close them. This failure case is not performance critical. 101 // and then close them. This failure case is not performance critical.
102 base::SyncSocket temp_socket( 102 base::SyncSocket temp_socket(
103 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); 103 IPC::PlatformFileForTransitToPlatformFile(socket_handle));
104 } 104 }
105 105
106 if (!TrackedCallback::IsPending(current_connect_callback_)) { 106 if (!TrackedCallback::IsPending(current_connect_callback_)) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 // Callback on the host side. 192 // Callback on the host side.
193 // Transfers ownership of the handle to the plugin side. This function must 193 // Transfers ownership of the handle to the plugin side. This function must
194 // either successfully call the callback or close the handle. 194 // either successfully call the callback or close the handle.
195 void PPB_Broker_Proxy::ConnectCompleteInHost(int32_t result, 195 void PPB_Broker_Proxy::ConnectCompleteInHost(int32_t result,
196 const HostResource& broker) { 196 const HostResource& broker) {
197 IPC::PlatformFileForTransit foreign_socket_handle = 197 IPC::PlatformFileForTransit foreign_socket_handle =
198 IPC::InvalidPlatformFileForTransit(); 198 IPC::InvalidPlatformFileForTransit();
199 if (result == PP_OK) { 199 if (result == PP_OK) {
200 int32_t socket_handle = PlatformFileToInt(base::kInvalidPlatformFileValue); 200 int32_t socket_handle = PlatformFileToInt(base::SyncSocket::kInvalidHandle);
201 EnterHostFromHostResource<PPB_Broker_API> enter(broker); 201 EnterHostFromHostResource<PPB_Broker_API> enter(broker);
202 if (enter.succeeded()) 202 if (enter.succeeded())
203 result = enter.object()->GetHandle(&socket_handle); 203 result = enter.object()->GetHandle(&socket_handle);
204 DCHECK(result == PP_OK || 204 DCHECK(result == PP_OK ||
205 socket_handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); 205 socket_handle ==
206 PlatformFileToInt(base::SyncSocket::kInvalidHandle));
206 207
207 if (result == PP_OK) { 208 if (result == PP_OK) {
208 foreign_socket_handle = 209 foreign_socket_handle =
209 dispatcher()->ShareHandleWithRemote(IntToPlatformFile(socket_handle), 210 dispatcher()->ShareHandleWithRemote(IntToPlatformFile(socket_handle),
210 true); 211 true);
211 if (foreign_socket_handle == IPC::InvalidPlatformFileForTransit()) { 212 if (foreign_socket_handle == IPC::InvalidPlatformFileForTransit()) {
212 result = PP_ERROR_FAILED; 213 result = PP_ERROR_FAILED;
213 // Assume the local handle was closed even if the foreign handle could 214 // Assume the local handle was closed even if the foreign handle could
214 // not be created. 215 // not be created.
215 } 216 }
(...skipping 10 matching lines...) Expand all
226 // The easiest way to clean it up is to just put it in an object 227 // The easiest way to clean it up is to just put it in an object
227 // and then close it. This failure case is not performance critical. 228 // and then close it. This failure case is not performance critical.
228 // The handle could still leak if Send succeeded but the IPC later failed. 229 // The handle could still leak if Send succeeded but the IPC later failed.
229 base::SyncSocket temp_socket( 230 base::SyncSocket temp_socket(
230 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); 231 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle));
231 } 232 }
232 } 233 }
233 234
234 } // namespace proxy 235 } // namespace proxy
235 } // namespace ppapi 236 } // namespace ppapi
OLDNEW
« no previous file with comments | « ipc/ipc_platform_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698