| 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_impl.h" | 5 #include "content/renderer/pepper/pepper_broker_impl.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "content/public/renderer/renderer_restrict_dispatch_group.h" | 8 #include "content/public/renderer/renderer_restrict_dispatch_group.h" |
| 9 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 9 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 10 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" | 10 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 return result; | 107 return result; |
| 108 } | 108 } |
| 109 | 109 |
| 110 PepperBrokerImpl::PepperBrokerImpl(webkit::ppapi::PluginModule* plugin_module, | 110 PepperBrokerImpl::PepperBrokerImpl(webkit::ppapi::PluginModule* plugin_module, |
| 111 PepperPluginDelegateImpl* delegate) | 111 PepperPluginDelegateImpl* delegate) |
| 112 : plugin_module_(plugin_module), | 112 : plugin_module_(plugin_module), |
| 113 delegate_(delegate->AsWeakPtr()) { | 113 delegate_(delegate->AsWeakPtr()) { |
| 114 DCHECK(plugin_module_); | 114 DCHECK(plugin_module_); |
| 115 DCHECK(delegate_); | 115 DCHECK(delegate_.get()); |
| 116 | 116 |
| 117 plugin_module_->SetBroker(this); | 117 plugin_module_->SetBroker(this); |
| 118 } | 118 } |
| 119 | 119 |
| 120 PepperBrokerImpl::~PepperBrokerImpl() { | 120 PepperBrokerImpl::~PepperBrokerImpl() { |
| 121 ReportFailureToClients(PP_ERROR_ABORTED); | 121 ReportFailureToClients(PP_ERROR_ABORTED); |
| 122 plugin_module_->SetBroker(NULL); | 122 plugin_module_->SetBroker(NULL); |
| 123 plugin_module_ = NULL; | 123 plugin_module_ = NULL; |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 154 // called to remove this object from pending_connect_broker_. | 154 // called to remove this object from pending_connect_broker_. |
| 155 // Before the broker is connected, clients must either be in | 155 // Before the broker is connected, clients must either be in |
| 156 // pending_connects_ or not yet associated with this object. Thus, if this | 156 // pending_connects_ or not yet associated with this object. Thus, if this |
| 157 // object is in pending_connect_broker_, there can be no associated clients | 157 // object is in pending_connect_broker_, there can be no associated clients |
| 158 // once pending_connects_ is empty and it is thus safe to remove this from | 158 // once pending_connects_ is empty and it is thus safe to remove this from |
| 159 // pending_connect_broker_. Doing so will cause this object to be deleted, | 159 // pending_connect_broker_. Doing so will cause this object to be deleted, |
| 160 // removing it from the PluginModule. Any new clients will create a new | 160 // removing it from the PluginModule. Any new clients will create a new |
| 161 // instance of this object. | 161 // instance of this object. |
| 162 // This doesn't solve all potential problems, but it helps with the ones | 162 // This doesn't solve all potential problems, but it helps with the ones |
| 163 // we can influence. | 163 // we can influence. |
| 164 if (delegate_) { | 164 if (delegate_.get()) { |
| 165 bool stopped = delegate_->StopWaitingForBrokerConnection(this); | 165 bool stopped = delegate_->StopWaitingForBrokerConnection(this); |
| 166 | 166 |
| 167 // Verify the assumption that there are no references other than the one | 167 // Verify the assumption that there are no references other than the one |
| 168 // |client| holds, which will be released below. | 168 // |client| holds, which will be released below. |
| 169 DCHECK(!stopped || HasOneRef()); | 169 DCHECK(!stopped || HasOneRef()); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Release the reference added in Connect(). | 173 // Release the reference added in Connect(). |
| 174 // This must be the last statement because it may delete this object. | 174 // This must be the last statement because it may delete this object. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 190 // Process all pending channel requests from the plugins. | 190 // Process all pending channel requests from the plugins. |
| 191 for (ClientMap::iterator i = pending_connects_.begin(); | 191 for (ClientMap::iterator i = pending_connects_.begin(); |
| 192 i != pending_connects_.end();) { | 192 i != pending_connects_.end();) { |
| 193 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = | 193 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = |
| 194 i->second.client; | 194 i->second.client; |
| 195 if (!i->second.is_authorized) { | 195 if (!i->second.is_authorized) { |
| 196 ++i; | 196 ++i; |
| 197 continue; | 197 continue; |
| 198 } | 198 } |
| 199 | 199 |
| 200 if (weak_ptr) | 200 if (weak_ptr.get()) |
| 201 ConnectPluginToBroker(weak_ptr); | 201 ConnectPluginToBroker(weak_ptr.get()); |
| 202 | 202 |
| 203 pending_connects_.erase(i++); | 203 pending_connects_.erase(i++); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void PepperBrokerImpl::OnBrokerPermissionResult( | 207 void PepperBrokerImpl::OnBrokerPermissionResult( |
| 208 webkit::ppapi::PPB_Broker_Impl* client, | 208 webkit::ppapi::PPB_Broker_Impl* client, |
| 209 bool result) { | 209 bool result) { |
| 210 ClientMap::iterator entry = pending_connects_.find(client); | 210 ClientMap::iterator entry = pending_connects_.find(client); |
| 211 if (entry == pending_connects_.end()) | 211 if (entry == pending_connects_.end()) |
| 212 return; | 212 return; |
| 213 | 213 |
| 214 if (!entry->second.client) { | 214 if (!entry->second.client.get()) { |
| 215 // Client has gone away. | 215 // Client has gone away. |
| 216 pending_connects_.erase(entry); | 216 pending_connects_.erase(entry); |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 if (!result) { | 220 if (!result) { |
| 221 // Report failure. | 221 // Report failure. |
| 222 client->BrokerConnected( | 222 client->BrokerConnected( |
| 223 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), | 223 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| 224 PP_ERROR_NOACCESS); | 224 PP_ERROR_NOACCESS); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 244 | 244 |
| 245 PepperBrokerImpl::PendingConnection::~PendingConnection() { | 245 PepperBrokerImpl::PendingConnection::~PendingConnection() { |
| 246 } | 246 } |
| 247 | 247 |
| 248 void PepperBrokerImpl::ReportFailureToClients(int error_code) { | 248 void PepperBrokerImpl::ReportFailureToClients(int error_code) { |
| 249 DCHECK_NE(PP_OK, error_code); | 249 DCHECK_NE(PP_OK, error_code); |
| 250 for (ClientMap::iterator i = pending_connects_.begin(); | 250 for (ClientMap::iterator i = pending_connects_.begin(); |
| 251 i != pending_connects_.end(); ++i) { | 251 i != pending_connects_.end(); ++i) { |
| 252 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = | 252 base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = |
| 253 i->second.client; | 253 i->second.client; |
| 254 if (weak_ptr) { | 254 if (weak_ptr.get()) { |
| 255 weak_ptr->BrokerConnected( | 255 weak_ptr->BrokerConnected( |
| 256 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), | 256 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| 257 error_code); | 257 error_code); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 pending_connects_.clear(); | 260 pending_connects_.clear(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void PepperBrokerImpl::ConnectPluginToBroker( | 263 void PepperBrokerImpl::ConnectPluginToBroker( |
| 264 webkit::ppapi::PPB_Broker_Impl* client) { | 264 webkit::ppapi::PPB_Broker_Impl* client) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 283 | 283 |
| 284 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing | 284 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing |
| 285 // client and plugin_socket.release(), then return. | 285 // client and plugin_socket.release(), then return. |
| 286 // That message handler will then call client->BrokerConnected() with the | 286 // That message handler will then call client->BrokerConnected() with the |
| 287 // saved pipe handle. | 287 // saved pipe handle. |
| 288 // Temporarily, just call back. | 288 // Temporarily, just call back. |
| 289 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); | 289 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace content | 292 } // namespace content |
| OLD | NEW |