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

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

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 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
OLDNEW
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 "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/trusted/ppb_broker_trusted.h" 8 #include "ppapi/c/trusted/ppb_broker_trusted.h"
9 #include "ppapi/proxy/enter_proxy.h" 9 #include "ppapi/proxy/enter_proxy.h"
10 #include "ppapi/proxy/plugin_dispatcher.h" 10 #include "ppapi/proxy/plugin_dispatcher.h"
11 #include "ppapi/proxy/plugin_resource.h"
12 #include "ppapi/proxy/ppapi_messages.h" 11 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/thunk/ppb_broker_api.h" 12 #include "ppapi/thunk/ppb_broker_api.h"
14 #include "ppapi/thunk/enter.h" 13 #include "ppapi/thunk/enter.h"
15 #include "ppapi/thunk/thunk.h" 14 #include "ppapi/thunk/thunk.h"
16 15
17 using ppapi::HostResource; 16 using ppapi::HostResource;
17 using ppapi::Resource;
18 using ppapi::thunk::PPB_Broker_API; 18 using ppapi::thunk::PPB_Broker_API;
19 19
20 namespace pp { 20 namespace pp {
21 namespace proxy { 21 namespace proxy {
22 22
23 namespace { 23 namespace {
24 24
25 base::PlatformFile IntToPlatformFile(int32_t handle) { 25 base::PlatformFile IntToPlatformFile(int32_t handle) {
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); 27 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
(...skipping 14 matching lines...) Expand all
42 #endif 42 #endif
43 } 43 }
44 44
45 InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher, 45 InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher,
46 const void* target_interface) { 46 const void* target_interface) {
47 return new PPB_Broker_Proxy(dispatcher, target_interface); 47 return new PPB_Broker_Proxy(dispatcher, target_interface);
48 } 48 }
49 49
50 } // namespace 50 } // namespace
51 51
52 class Broker : public PPB_Broker_API, public PluginResource { 52 class Broker : public PPB_Broker_API, public Resource {
53 public: 53 public:
54 explicit Broker(const HostResource& resource); 54 explicit Broker(const HostResource& resource);
55 virtual ~Broker(); 55 virtual ~Broker();
56 56
57 // ResourceObjectBase overries. 57 // Resource overries.
58 virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; 58 virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;
59 59
60 // PPB_Broker_API implementation. 60 // PPB_Broker_API implementation.
61 virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; 61 virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE;
62 virtual int32_t GetHandle(int32_t* handle) OVERRIDE; 62 virtual int32_t GetHandle(int32_t* handle) OVERRIDE;
63 63
64 // Called by the proxy when the host side has completed the request. 64 // Called by the proxy when the host side has completed the request.
65 void ConnectComplete(IPC::PlatformFileForTransit socket_handle, 65 void ConnectComplete(IPC::PlatformFileForTransit socket_handle,
66 int32_t result); 66 int32_t result);
67 67
68 private: 68 private:
69 bool called_connect_; 69 bool called_connect_;
70 PP_CompletionCallback current_connect_callback_; 70 PP_CompletionCallback current_connect_callback_;
71 71
72 // The plugin module owns the handle. 72 // The plugin module owns the handle.
73 // The host side transfers ownership of the handle to the plugin side when it 73 // The host side transfers ownership of the handle to the plugin side when it
74 // sends the IPC. This member holds the handle value for the plugin module 74 // sends the IPC. This member holds the handle value for the plugin module
75 // to read, but the plugin side of the proxy never takes ownership. 75 // to read, but the plugin side of the proxy never takes ownership.
76 base::SyncSocket::Handle socket_handle_; 76 base::SyncSocket::Handle socket_handle_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(Broker); 78 DISALLOW_COPY_AND_ASSIGN(Broker);
79 }; 79 };
80 80
81 Broker::Broker(const HostResource& resource) 81 Broker::Broker(const HostResource& resource) : Resource(resource),
82 : PluginResource(resource),
83 called_connect_(false), 82 called_connect_(false),
84 current_connect_callback_(PP_MakeCompletionCallback(NULL, NULL)), 83 current_connect_callback_(PP_MakeCompletionCallback(NULL, NULL)),
85 socket_handle_(base::kInvalidPlatformFileValue) { 84 socket_handle_(base::kInvalidPlatformFileValue) {
86 } 85 }
87 86
88 Broker::~Broker() { 87 Broker::~Broker() {
89 // Ensure the callback is always fired. 88 // Ensure the callback is always fired.
90 if (current_connect_callback_.func) { 89 if (current_connect_callback_.func) {
91 // TODO(brettw) the callbacks at this level should be refactored with a 90 // TODO(brettw) the callbacks at this level should be refactored with a
92 // more automatic tracking system like we have in the renderer. 91 // more automatic tracking system like we have in the renderer.
(...skipping 16 matching lines...) Expand all
109 } 108 }
110 109
111 if (current_connect_callback_.func) 110 if (current_connect_callback_.func)
112 return PP_ERROR_INPROGRESS; 111 return PP_ERROR_INPROGRESS;
113 else if (called_connect_) 112 else if (called_connect_)
114 return PP_ERROR_FAILED; 113 return PP_ERROR_FAILED;
115 114
116 current_connect_callback_ = connect_callback; 115 current_connect_callback_ = connect_callback;
117 called_connect_ = true; 116 called_connect_ = true;
118 117
119 bool success = GetDispatcher()->Send(new PpapiHostMsg_PPBBroker_Connect( 118 bool success = PluginDispatcher::GetForResource(this)->Send(
120 INTERFACE_ID_PPB_BROKER, host_resource())); 119 new PpapiHostMsg_PPBBroker_Connect(
120 INTERFACE_ID_PPB_BROKER, host_resource()));
121 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; 121 return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED;
122 } 122 }
123 123
124 int32_t Broker::GetHandle(int32_t* handle) { 124 int32_t Broker::GetHandle(int32_t* handle) {
125 if (socket_handle_ == base::kInvalidPlatformFileValue) 125 if (socket_handle_ == base::kInvalidPlatformFileValue)
126 return PP_ERROR_FAILED; 126 return PP_ERROR_FAILED;
127 *handle = PlatformFileToInt(socket_handle_); 127 *handle = PlatformFileToInt(socket_handle_);
128 return PP_OK; 128 return PP_OK;
129 } 129 }
130 130
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { 174 PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) {
175 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 175 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
176 if (!dispatcher) 176 if (!dispatcher)
177 return 0; 177 return 0;
178 178
179 HostResource result; 179 HostResource result;
180 dispatcher->Send(new PpapiHostMsg_PPBBroker_Create( 180 dispatcher->Send(new PpapiHostMsg_PPBBroker_Create(
181 INTERFACE_ID_PPB_BROKER, instance, &result)); 181 INTERFACE_ID_PPB_BROKER, instance, &result));
182 if (result.is_null()) 182 if (result.is_null())
183 return 0; 183 return 0;
184 184 return (new Broker(result))->GetReference();
185 return PluginResourceTracker::GetInstance()->AddResource(new Broker(result));
186 } 185 }
187 186
188 bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { 187 bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) {
189 bool handled = true; 188 bool handled = true;
190 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Proxy, msg) 189 IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Proxy, msg)
191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Create, OnMsgCreate) 190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Create, OnMsgCreate)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Connect, OnMsgConnect) 191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBroker_Connect, OnMsgConnect)
193 IPC_MESSAGE_HANDLER(PpapiMsg_PPBBroker_ConnectComplete, 192 IPC_MESSAGE_HANDLER(PpapiMsg_PPBBroker_ConnectComplete,
194 OnMsgConnectComplete) 193 OnMsgConnectComplete)
195 IPC_MESSAGE_UNHANDLED(handled = false) 194 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // The easiest way to clean it up is to just put it in an object 269 // The easiest way to clean it up is to just put it in an object
271 // and then close it. This failure case is not performance critical. 270 // and then close it. This failure case is not performance critical.
272 // The handle could still leak if Send succeeded but the IPC later failed. 271 // The handle could still leak if Send succeeded but the IPC later failed.
273 base::SyncSocket temp_socket( 272 base::SyncSocket temp_socket(
274 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); 273 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle));
275 } 274 }
276 } 275 }
277 276
278 } // namespace proxy 277 } // namespace proxy
279 } // namespace pp 278 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698