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 "content/renderer/pepper/pepper_broker.h" | 5 #include "content/renderer/pepper/pepper_broker.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "content/renderer/pepper/pepper_helper_impl.h" | |
9 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" | 8 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
10 #include "content/renderer/pepper/plugin_module.h" | 9 #include "content/renderer/pepper/plugin_module.h" |
11 #include "content/renderer/pepper/ppb_broker_impl.h" | 10 #include "content/renderer/pepper/ppb_broker_impl.h" |
12 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" | 11 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" |
13 #include "ipc/ipc_channel_handle.h" | 12 #include "ipc/ipc_channel_handle.h" |
14 #include "ppapi/proxy/broker_dispatcher.h" | 13 #include "ppapi/proxy/broker_dispatcher.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/shared_impl/platform_file.h" | 15 #include "ppapi/shared_impl/platform_file.h" |
17 | 16 |
18 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // and then close it. This failure case is not performance critical. | 99 // and then close it. This failure case is not performance critical. |
101 // The handle could still leak if Send succeeded but the IPC later failed. | 100 // The handle could still leak if Send succeeded but the IPC later failed. |
102 base::SyncSocket temp_socket( | 101 base::SyncSocket temp_socket( |
103 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); | 102 IPC::PlatformFileForTransitToPlatformFile(foreign_socket_handle)); |
104 return PP_ERROR_FAILED; | 103 return PP_ERROR_FAILED; |
105 } | 104 } |
106 | 105 |
107 return result; | 106 return result; |
108 } | 107 } |
109 | 108 |
110 PepperBroker::PepperBroker(PluginModule* plugin_module, | 109 PepperBroker::PepperBroker(PluginModule* plugin_module) |
111 PepperHelperImpl* helper) | 110 : plugin_module_(plugin_module) { |
112 : plugin_module_(plugin_module), | |
113 helper_(helper->AsWeakPtr()) { | |
114 DCHECK(plugin_module_); | 111 DCHECK(plugin_module_); |
115 DCHECK(helper_.get()); | |
116 | 112 |
117 plugin_module_->SetBroker(this); | 113 plugin_module_->SetBroker(this); |
118 } | 114 } |
119 | 115 |
120 PepperBroker::~PepperBroker() { | 116 PepperBroker::~PepperBroker() { |
121 ReportFailureToClients(PP_ERROR_ABORTED); | 117 ReportFailureToClients(PP_ERROR_ABORTED); |
122 plugin_module_->SetBroker(NULL); | 118 plugin_module_->SetBroker(NULL); |
123 plugin_module_ = NULL; | 119 plugin_module_ = NULL; |
124 } | 120 } |
125 | 121 |
(...skipping 14 matching lines...) Expand all Loading... |
140 pending_connects_[client].client = client->AsWeakPtr(); | 136 pending_connects_[client].client = client->AsWeakPtr(); |
141 } | 137 } |
142 | 138 |
143 void PepperBroker::Disconnect(PPB_Broker_Impl* client) { | 139 void PepperBroker::Disconnect(PPB_Broker_Impl* client) { |
144 // Remove the pending connect if one exists. This class will not call client's | 140 // Remove the pending connect if one exists. This class will not call client's |
145 // callback. | 141 // callback. |
146 pending_connects_.erase(client); | 142 pending_connects_.erase(client); |
147 | 143 |
148 // TODO(ddorwin): Send message disconnect message using dispatcher_. | 144 // TODO(ddorwin): Send message disconnect message using dispatcher_. |
149 | 145 |
150 if (pending_connects_.empty()) { | |
151 // There are no more clients of this broker. Ensure it will be deleted even | |
152 // if the IPC response never comes and OnPepperBrokerChannelCreated is not | |
153 // called to remove this object from pending_connect_broker_. | |
154 // Before the broker is connected, clients must either be in | |
155 // pending_connects_ or not yet associated with this object. Thus, if this | |
156 // object is in pending_connect_broker_, there can be no associated clients | |
157 // once pending_connects_ is empty and it is thus safe to remove this from | |
158 // pending_connect_broker_. Doing so will cause this object to be deleted, | |
159 // removing it from the PluginModule. Any new clients will create a new | |
160 // instance of this object. | |
161 // This doesn't solve all potential problems, but it helps with the ones | |
162 // we can influence. | |
163 if (helper_.get()) { | |
164 bool stopped = helper_->StopWaitingForBrokerConnection(this); | |
165 | |
166 // Verify the assumption that there are no references other than the one | |
167 // |client| holds, which will be released below. | |
168 DCHECK(!stopped || HasOneRef()); | |
169 } | |
170 } | |
171 | |
172 // Release the reference added in Connect(). | 146 // Release the reference added in Connect(). |
173 // This must be the last statement because it may delete this object. | 147 // This must be the last statement because it may delete this object. |
174 Release(); | 148 Release(); |
175 } | 149 } |
176 | 150 |
177 void PepperBroker::OnBrokerChannelConnected( | 151 void PepperBroker::OnBrokerChannelConnected( |
178 base::ProcessId broker_pid, | 152 base::ProcessId broker_pid, |
179 const IPC::ChannelHandle& channel_handle) { | 153 const IPC::ChannelHandle& channel_handle) { |
180 scoped_ptr<PepperBrokerDispatcherWrapper> dispatcher( | 154 scoped_ptr<PepperBrokerDispatcherWrapper> dispatcher( |
181 new PepperBrokerDispatcherWrapper); | 155 new PepperBrokerDispatcherWrapper); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 251 |
278 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing | 252 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing |
279 // client and plugin_socket.release(), then return. | 253 // client and plugin_socket.release(), then return. |
280 // That message handler will then call client->BrokerConnected() with the | 254 // That message handler will then call client->BrokerConnected() with the |
281 // saved pipe handle. | 255 // saved pipe handle. |
282 // Temporarily, just call back. | 256 // Temporarily, just call back. |
283 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); | 257 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); |
284 } | 258 } |
285 | 259 |
286 } // namespace content | 260 } // namespace content |
OLD | NEW |