Chromium Code Reviews| Index: content/renderer/pepper/pepper_broker_impl.cc |
| diff --git a/content/renderer/pepper/pepper_broker_impl.cc b/content/renderer/pepper/pepper_broker_impl.cc |
| index 67fdd84d80a10d79fb2ecd3524ebb1df273d7282..fe8a154eb6a8016cc34ec9c08535dcd2aebf927d 100644 |
| --- a/content/renderer/pepper/pepper_broker_impl.cc |
| +++ b/content/renderer/pepper/pepper_broker_impl.cc |
| @@ -116,18 +116,7 @@ PepperBrokerImpl::PepperBrokerImpl(webkit::ppapi::PluginModule* plugin_module, |
| } |
| PepperBrokerImpl::~PepperBrokerImpl() { |
| - // Report failure to all clients that had pending operations. |
| - for (ClientMap::iterator i = pending_connects_.begin(); |
| - i != pending_connects_.end(); ++i) { |
| - base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second; |
| - if (weak_ptr) { |
| - weak_ptr->BrokerConnected( |
| - ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| - PP_ERROR_ABORTED); |
| - } |
| - } |
| - pending_connects_.clear(); |
| - |
| + ReportFailureToClients(); |
| plugin_module_->SetBroker(NULL); |
| plugin_module_ = NULL; |
| } |
| @@ -146,13 +135,7 @@ void PepperBrokerImpl::Connect(webkit::ppapi::PPB_Broker_Impl* client) { |
| // longer using it. |
| AddRef(); |
| - if (!dispatcher_.get()) { |
| - pending_connects_[client] = client->AsWeakPtr(); |
| - return; |
| - } |
| - DCHECK(pending_connects_.empty()); |
| - |
| - ConnectPluginToBroker(client); |
| + pending_connects_[client].client = client->AsWeakPtr(); |
| } |
| void PepperBrokerImpl::Disconnect(webkit::ppapi::PPB_Broker_Impl* client) { |
| @@ -179,7 +162,7 @@ void PepperBrokerImpl::Disconnect(webkit::ppapi::PPB_Broker_Impl* client) { |
| bool stopped = delegate_->StopWaitingForBrokerConnection(this); |
| // Verify the assumption that there are no references other than the one |
| - // client holds, which will be released below. |
| + // |client| holds, which will be released below. |
| DCHECK(!stopped || HasOneRef()); |
| } |
| } |
| @@ -193,26 +176,80 @@ void PepperBrokerImpl::OnBrokerChannelConnected( |
| const IPC::ChannelHandle& channel_handle) { |
| scoped_ptr<PepperBrokerDispatcherWrapper> dispatcher( |
| new PepperBrokerDispatcherWrapper); |
| - if (dispatcher->Init(channel_handle)) { |
| - dispatcher_.reset(dispatcher.release()); |
| - |
| - // Process all pending channel requests from the plugins. |
| - for (ClientMap::iterator i = pending_connects_.begin(); |
| - i != pending_connects_.end(); ++i) { |
| - base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second; |
| - if (weak_ptr) |
| - ConnectPluginToBroker(weak_ptr); |
| + if (!dispatcher->Init(channel_handle)) { |
| + ReportFailureToClients(); |
| + return; |
| + } |
| + |
| + dispatcher_.reset(dispatcher.release()); |
| + |
| + // Process all pending channel requests from the plugins. |
| + for (ClientMap::iterator i = pending_connects_.begin(); |
| + i != pending_connects_.end();) { |
| + base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = |
| + i->second.client; |
| + if (!i->second.is_authorized) { |
| + ++i; |
| + continue; |
| } |
| - } else { |
| - // Report failure to all clients. |
| - for (ClientMap::iterator i = pending_connects_.begin(); |
| - i != pending_connects_.end(); ++i) { |
| - base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = i->second; |
| - if (weak_ptr) { |
| - weak_ptr->BrokerConnected( |
| - ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| - PP_ERROR_FAILED); |
| - } |
| + |
| + if (weak_ptr) |
| + ConnectPluginToBroker(weak_ptr); |
| + |
| + pending_connects_.erase(i++); |
| + } |
| +} |
| + |
| +void PepperBrokerImpl::OnBrokerPermissionResult( |
| + webkit::ppapi::PPB_Broker_Impl* client, |
| + bool result) { |
| + ClientMap::iterator entry = pending_connects_.find(client); |
| + if (entry == pending_connects_.end()) |
| + return; |
| + |
| + if (!entry->second.client) { |
| + // Client has gone away. |
| + pending_connects_.erase(entry); |
| + return; |
| + } |
| + |
| + if (!result) { |
| + // Report failure. |
| + client->BrokerConnected( |
| + ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| + PP_ERROR_NOACCESS); |
| + pending_connects_.erase(entry); |
| + return; |
| + } |
| + |
| + if (dispatcher_.get()) { |
| + ConnectPluginToBroker(client); |
| + pending_connects_.erase(entry); |
| + return; |
| + } |
| + |
| + // Mark the request as authorized, continue waiting for the broker |
| + // connection. |
| + DCHECK(!entry->second.is_authorized); |
| + entry->second.is_authorized = true; |
| +} |
| + |
| +PepperBrokerImpl::PendingConnection::PendingConnection() |
| + : is_authorized(false) { |
| +} |
| + |
| +PepperBrokerImpl::PendingConnection::~PendingConnection() { |
| +} |
| + |
| +void PepperBrokerImpl::ReportFailureToClients() { |
| + for (ClientMap::iterator i = pending_connects_.begin(); |
| + i != pending_connects_.end(); ++i) { |
| + base::WeakPtr<webkit::ppapi::PPB_Broker_Impl>& weak_ptr = |
| + i->second.client; |
| + if (weak_ptr) { |
| + weak_ptr->BrokerConnected( |
| + ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), |
| + PP_ERROR_ABORTED); |
|
ddorwin
2012/08/13 22:27:04
The code this function replaces had two different
Bernhard Bauer
2012/08/13 22:42:14
Done.
|
| } |
| } |
| pending_connects_.clear(); |