Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_renderer_connection.cc |
| diff --git a/content/browser/renderer_host/pepper/pepper_renderer_connection.cc b/content/browser/renderer_host/pepper/pepper_renderer_connection.cc |
| index 8c76c697e5474da2f5b75d1f889748fa7639851b..7e36bd3fc60e5fe5e7a479ce1a8d7d1984f33bf5 100644 |
| --- a/content/browser/renderer_host/pepper/pepper_renderer_connection.cc |
| +++ b/content/browser/renderer_host/pepper/pepper_renderer_connection.cc |
| @@ -4,6 +4,8 @@ |
| #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" |
| +#include "base/bind.h" |
| +#include "base/memory/ref_counted.h" |
| #include "content/browser/browser_child_process_host_impl.h" |
| #include "content/browser/ppapi_plugin_process_host.h" |
| #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" |
| @@ -22,6 +24,68 @@ |
| namespace content { |
| +namespace { |
| + |
| +// Responsible for creating the pending resource hosts, holding their IDs until |
| +// all of them have been created for a single message, and sending the reply to |
| +// say that the hosts have been created. |
| +class PendingHostCreator |
| + : public base::RefCountedThreadSafe<PendingHostCreator> { |
|
yzshen1
2013/11/01 22:27:39
ThreadSafe is not needed. This code won't be run o
Matt Giuca
2013/11/01 23:19:47
It will be passed to another thread, then passed b
yzshen1
2013/11/02 00:25:07
If the ref needs to be manipulated by multiple thr
Matt Giuca
2013/11/02 00:51:45
I agree. RefCounted seems fine.
|
| + public: |
| + PendingHostCreator(int routing_id, |
| + int sequence_id, |
| + BrowserPpapiHostImpl* host, |
| + int nested_msgs_size, |
|
yzshen1
2013/11/01 22:27:39
size_t, please.
nit, optional: maybe it is better
Matt Giuca
2013/11/01 23:19:47
Done. I agree.
|
| + BrowserMessageFilter* connection); |
| + |
| + // Adds the given resource host as a pending one. The host is remembered as |
| + // host number |index|, and will ultimately be sent to the plugin to be |
| + // attached to a real resource. |
| + void AddPendingResourceHost( |
| + size_t index, |
| + scoped_ptr<ppapi::host::ResourceHost> resource_host); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PendingHostCreator>; |
| + |
| + // When the last reference to this class is released, all of the resource |
| + // hosts would have been added. This destructor sends the message to the |
| + // plugin to tell it to attach real hosts to all of the pending hosts that |
| + // have been added by this object. |
| + ~PendingHostCreator(); |
| + |
| + int routing_id_; |
| + int sequence_id_; |
| + BrowserPpapiHostImpl* host_; |
| + std::vector<int> pending_resource_host_ids_; |
| + BrowserMessageFilter* connection_; |
| +}; |
| + |
| +PendingHostCreator::PendingHostCreator(int routing_id, |
| + int sequence_id, |
| + BrowserPpapiHostImpl* host, |
| + int nested_msgs_size, |
| + BrowserMessageFilter* connection) |
| + : routing_id_(routing_id), |
| + sequence_id_(sequence_id), |
| + host_(host), |
| + pending_resource_host_ids_(nested_msgs_size, 0), |
| + connection_(connection) {} |
| + |
| +void PendingHostCreator::AddPendingResourceHost( |
| + size_t index, |
| + scoped_ptr<ppapi::host::ResourceHost> resource_host) { |
| + pending_resource_host_ids_[index] = |
| + host_->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass()); |
| +} |
| + |
| +PendingHostCreator::~PendingHostCreator() { |
| + connection_->Send(new PpapiHostMsg_CreateResourceHostsFromHostReply( |
|
yzshen1
2013/11/01 22:27:39
Is it possible that something has failed and we ha
Matt Giuca
2013/11/01 23:19:47
No more possible than it already was. (That is, I'
yzshen1
2013/11/02 00:25:07
I think it is possible: The FileSystem resource ho
Matt Giuca
2013/11/02 01:05:21
Had a chat with Yuzhu. I agree, there is a very ra
|
| + routing_id_, sequence_id_, pending_resource_host_ids_)); |
| +} |
| + |
| +} // namespace |
| + |
| PepperRendererConnection::PepperRendererConnection(int render_process_id) |
| : render_process_id_(render_process_id) { |
| // Only give the renderer permission for stable APIs. |
| @@ -93,8 +157,10 @@ void PepperRendererConnection::OnMsgCreateResourceHostsFromHost( |
| PP_Instance instance, |
| const std::vector<IPC::Message>& nested_msgs) { |
| BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id); |
| + scoped_refptr<PendingHostCreator> creator = |
| + new PendingHostCreator( |
| + routing_id, params.sequence(), host, nested_msgs.size(), this); |
| - std::vector<int> pending_resource_host_ids(nested_msgs.size(), 0); |
| if (!host) { |
| DLOG(ERROR) << "Invalid plugin process ID."; |
| } else { |
| @@ -120,12 +186,25 @@ void PepperRendererConnection::OnMsgCreateResourceHostsFromHost( |
| PP_FileSystemType file_system_type; |
| if (ppapi::UnpackMessage<PpapiHostMsg_FileSystem_CreateFromRenderer>( |
| nested_msg, &root_url, &file_system_type)) { |
| - resource_host.reset( |
| + PepperFileSystemBrowserHost* browser_host = |
| new PepperFileSystemBrowserHost(host, |
| instance, |
| params.pp_resource(), |
| - GURL(root_url), |
| - file_system_type)); |
| + file_system_type); |
| + resource_host.reset(browser_host); |
| + // Open the file system resource host. This is an asynchronous |
| + // operation, and we must only add the pending resource host and |
| + // send the message once it completes. |
| + browser_host->OpenExisting( |
| + GURL(root_url), |
| + base::Bind( |
| + &PendingHostCreator::AddPendingResourceHost, |
|
dmichael (off chromium)
2013/11/01 17:33:52
The idea of this being asynchronous is pretty scar
teravest
2013/11/01 19:57:24
Dave's right-- you should definitely call AddPendi
yzshen1
2013/11/01 21:23:12
(Not saying that it is incorrect, just try to unde
Matt Giuca
2013/11/01 21:41:54
Hey,
I'm not sure I understand how this is a prob
dmichael (off chromium)
2013/11/01 21:44:26
Yeah, I realize now that the sender of CreateFromR
|
| + creator, |
| + i, |
| + base::Passed(&resource_host))); |
| + // Do not fall through; the fall-through case adds the pending |
| + // resource host to the list. We must do this asynchronously. |
| + continue; |
|
dmichael (off chromium)
2013/11/01 17:33:52
I think it might be better to structure this diffe
Matt Giuca
2013/11/01 23:19:47
That's messy. The case currently at the bottom is
|
| } |
| } |
| } |
| @@ -135,15 +214,15 @@ void PepperRendererConnection::OnMsgCreateResourceHostsFromHost( |
| params, instance, nested_msg); |
| } |
| - if (resource_host.get()) { |
| - pending_resource_host_ids[i] = |
| - host->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass()); |
| - } |
| + if (resource_host.get()) |
| + creator->AddPendingResourceHost(i, resource_host.Pass()); |
| } |
| } |
| - Send(new PpapiHostMsg_CreateResourceHostsFromHostReply( |
| - routing_id, params.sequence(), pending_resource_host_ids)); |
| + // Note: All of the pending host IDs that were added as part of this |
| + // operation will automatically be send to the plugin when |creator| is |
|
dmichael (off chromium)
2013/11/01 17:33:52
nit: s/send/sent
Matt Giuca
2013/11/01 23:19:47
Done.
|
| + // released. This may happen immediately, or (if there are asynchronous |
| + // requests to create resource hosts), once all of them complete. |
| } |
| void PepperRendererConnection::OnMsgDidCreateInProcessInstance( |