OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 class Broker : public PPB_Broker_API, public Resource { | 27 class Broker : public PPB_Broker_API, public Resource { |
28 public: | 28 public: |
29 explicit Broker(const HostResource& resource); | 29 explicit Broker(const HostResource& resource); |
30 virtual ~Broker(); | 30 virtual ~Broker(); |
31 | 31 |
32 // Resource overrides. | 32 // Resource overrides. |
33 virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; | 33 virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; |
34 | 34 |
35 // PPB_Broker_API implementation. | 35 // PPB_Broker_API implementation. |
36 virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; | 36 virtual int32_t Connect(ApiCallbackType connect_callback) OVERRIDE; |
37 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; | 37 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; |
38 | 38 |
39 // Called by the proxy when the host side has completed the request. | 39 // Called by the proxy when the host side has completed the request. |
40 void ConnectComplete(IPC::PlatformFileForTransit socket_handle, | 40 void ConnectComplete(IPC::PlatformFileForTransit socket_handle, |
41 int32_t result); | 41 int32_t result); |
42 | 42 |
43 private: | 43 private: |
44 bool called_connect_; | 44 bool called_connect_; |
45 scoped_refptr<TrackedCallback> current_connect_callback_; | 45 scoped_refptr<TrackedCallback> current_connect_callback_; |
46 | 46 |
(...skipping 13 matching lines...) Expand all Loading... |
60 } | 60 } |
61 | 61 |
62 Broker::~Broker() { | 62 Broker::~Broker() { |
63 socket_handle_ = base::kInvalidPlatformFileValue; | 63 socket_handle_ = base::kInvalidPlatformFileValue; |
64 } | 64 } |
65 | 65 |
66 PPB_Broker_API* Broker::AsPPB_Broker_API() { | 66 PPB_Broker_API* Broker::AsPPB_Broker_API() { |
67 return this; | 67 return this; |
68 } | 68 } |
69 | 69 |
70 int32_t Broker::Connect(PP_CompletionCallback connect_callback) { | 70 int32_t Broker::Connect(ApiCallbackType connect_callback) { |
71 if (!connect_callback.func) { | |
72 // Synchronous calls are not supported. | |
73 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
74 } | |
75 | |
76 if (TrackedCallback::IsPending(current_connect_callback_)) | 71 if (TrackedCallback::IsPending(current_connect_callback_)) |
77 return PP_ERROR_INPROGRESS; | 72 return PP_ERROR_INPROGRESS; |
78 else if (called_connect_) | 73 else if (called_connect_) |
79 return PP_ERROR_FAILED; | 74 return PP_ERROR_FAILED; |
80 | 75 |
81 current_connect_callback_ = new TrackedCallback(this, connect_callback); | 76 current_connect_callback_ = connect_callback; |
82 called_connect_ = true; | 77 called_connect_ = true; |
83 | 78 |
84 bool success = PluginDispatcher::GetForResource(this)->Send( | 79 bool success = PluginDispatcher::GetForResource(this)->Send( |
85 new PpapiHostMsg_PPBBroker_Connect( | 80 new PpapiHostMsg_PPBBroker_Connect( |
86 API_ID_PPB_BROKER, host_resource())); | 81 API_ID_PPB_BROKER, host_resource())); |
87 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; | 82 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; |
88 } | 83 } |
89 | 84 |
90 int32_t Broker::GetHandle(int32_t* handle) { | 85 int32_t Broker::GetHandle(int32_t* handle) { |
91 if (socket_handle_ == base::kInvalidPlatformFileValue) | 86 if (socket_handle_ == base::kInvalidPlatformFileValue) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // The easiest way to clean it up is to just put it in an object | 221 // 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. | 222 // 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. | 223 // The handle could still leak if Send succeeded but the IPC later failed. |
229 base::SyncSocket temp_socket( | 224 base::SyncSocket temp_socket( |
230 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); | 225 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); |
231 } | 226 } |
232 } | 227 } |
233 | 228 |
234 } // namespace proxy | 229 } // namespace proxy |
235 } // namespace ppapi | 230 } // namespace ppapi |
OLD | NEW |