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( |
| 37 scoped_refptr<TrackedCallback> connect_callback) OVERRIDE; |
37 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; | 38 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; |
38 | 39 |
39 // Called by the proxy when the host side has completed the request. | 40 // Called by the proxy when the host side has completed the request. |
40 void ConnectComplete(IPC::PlatformFileForTransit socket_handle, | 41 void ConnectComplete(IPC::PlatformFileForTransit socket_handle, |
41 int32_t result); | 42 int32_t result); |
42 | 43 |
43 private: | 44 private: |
44 bool called_connect_; | 45 bool called_connect_; |
45 scoped_refptr<TrackedCallback> current_connect_callback_; | 46 scoped_refptr<TrackedCallback> current_connect_callback_; |
46 | 47 |
(...skipping 13 matching lines...) Expand all Loading... |
60 } | 61 } |
61 | 62 |
62 Broker::~Broker() { | 63 Broker::~Broker() { |
63 socket_handle_ = base::kInvalidPlatformFileValue; | 64 socket_handle_ = base::kInvalidPlatformFileValue; |
64 } | 65 } |
65 | 66 |
66 PPB_Broker_API* Broker::AsPPB_Broker_API() { | 67 PPB_Broker_API* Broker::AsPPB_Broker_API() { |
67 return this; | 68 return this; |
68 } | 69 } |
69 | 70 |
70 int32_t Broker::Connect(PP_CompletionCallback connect_callback) { | 71 int32_t Broker::Connect(scoped_refptr<TrackedCallback> 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_)) | 72 if (TrackedCallback::IsPending(current_connect_callback_)) |
77 return PP_ERROR_INPROGRESS; | 73 return PP_ERROR_INPROGRESS; |
78 else if (called_connect_) | 74 else if (called_connect_) |
79 return PP_ERROR_FAILED; | 75 return PP_ERROR_FAILED; |
80 | 76 |
81 current_connect_callback_ = new TrackedCallback(this, connect_callback); | 77 current_connect_callback_ = connect_callback; |
82 called_connect_ = true; | 78 called_connect_ = true; |
83 | 79 |
84 bool success = PluginDispatcher::GetForResource(this)->Send( | 80 bool success = PluginDispatcher::GetForResource(this)->Send( |
85 new PpapiHostMsg_PPBBroker_Connect( | 81 new PpapiHostMsg_PPBBroker_Connect( |
86 API_ID_PPB_BROKER, host_resource())); | 82 API_ID_PPB_BROKER, host_resource())); |
87 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; | 83 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; |
88 } | 84 } |
89 | 85 |
90 int32_t Broker::GetHandle(int32_t* handle) { | 86 int32_t Broker::GetHandle(int32_t* handle) { |
91 if (socket_handle_ == base::kInvalidPlatformFileValue) | 87 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 | 222 // 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. | 223 // 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. | 224 // The handle could still leak if Send succeeded but the IPC later failed. |
229 base::SyncSocket temp_socket( | 225 base::SyncSocket temp_socket( |
230 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); | 226 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); |
231 } | 227 } |
232 } | 228 } |
233 | 229 |
234 } // namespace proxy | 230 } // namespace proxy |
235 } // namespace ppapi | 231 } // namespace ppapi |
OLD | NEW |