Chromium Code Reviews| Index: ppapi/proxy/raw_var_data.cc |
| diff --git a/ppapi/proxy/raw_var_data.cc b/ppapi/proxy/raw_var_data.cc |
| index 91bcfbfd1f0b0448126f2da92cc6081076cd1f14..4db48050f0b1eed6ffe1011aecacb8e6f83a242e 100644 |
| --- a/ppapi/proxy/raw_var_data.cc |
| +++ b/ppapi/proxy/raw_var_data.cc |
| @@ -9,7 +9,12 @@ |
| #include "base/containers/hash_tables.h" |
| #include "base/stl_util.h" |
| #include "ipc/ipc_message.h" |
| +#include "ppapi/proxy/file_system_resource.h" |
| +#include "ppapi/proxy/plugin_dispatcher.h" |
| +#include "ppapi/proxy/plugin_globals.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| #include "ppapi/proxy/ppapi_param_traits.h" |
| +#include "ppapi/proxy/resource_creation_proxy.h" |
| #include "ppapi/shared_impl/array_var.h" |
| #include "ppapi/shared_impl/dictionary_var.h" |
| #include "ppapi/shared_impl/ppapi_globals.h" |
| @@ -664,6 +669,80 @@ bool DictionaryRawVarData::Read(PP_VarType type, |
| return true; |
| } |
| +// ResourceDispatcher ---------------------------------------------------------- |
| +// Used by the plugin side to dispatch resource creation messages. |
| +// This allows messages from the host side with pending resources to be made |
| +// into actual plugin-side resources. |
| +// Must only be created on the plugin side. |
| +class ResourceDispatcher { |
|
raymes
2013/10/11 04:02:24
This class seems like a little overkill for what's
Matt Giuca
2013/10/15 00:25:16
The reason I needed a class (instead of just funct
raymes
2013/10/16 00:45:14
My suggestion is to not use IPC_BEGIN_MESSAGE_MAP
Matt Giuca
2013/10/21 05:20:03
OK DONE! You were right, this is much simpler. Loo
|
| + public: |
| + // The |pp_resource| argument will be written with the real resource ID once |
| + // one of the dispatch methods is called. |
| + ResourceDispatcher(PP_Instance instance, int pending_renderer_id, |
|
raymes
2013/10/11 04:02:24
nit: one line per argument
Matt Giuca
2013/10/15 00:25:16
Done.
|
| + int pending_browser_id, PP_Resource* pp_resource); |
| + |
| + // Execute an IPC message that creates a plugin-side resource. |
| + void ExecuteCreationMessage(const IPC::Message& creation_message); |
| + |
| + void OnMsgFileSystem_CreateFromPendingHost( |
| + PP_FileSystemType file_system_type); |
| + |
| + private: |
| + Connection GetConnection(); |
| + |
| + PP_Instance instance_; |
| + int pending_renderer_id_; |
| + int pending_browser_id_; |
| + PP_Resource* pp_resource_; |
| + PluginDispatcher* dispatcher_; |
| +}; |
| + |
| +ResourceDispatcher::ResourceDispatcher( |
| + PP_Instance instance, |
| + int pending_renderer_id, |
| + int pending_browser_id, |
| + PP_Resource* pp_resource) |
| + : instance_(instance), |
| + pending_renderer_id_(pending_renderer_id), |
| + pending_browser_id_(pending_browser_id), |
| + pp_resource_(pp_resource), |
| + dispatcher_(NULL) { |
| + // Check that this is on the plugin side. |
| + DCHECK(PpapiGlobals::Get()->IsPluginGlobals()); |
|
yzshen1
2013/10/11 17:45:45
Please see my comment on line 779.
|
| + dispatcher_ = PluginDispatcher::GetForInstance(instance); |
| +} |
| + |
| +void ResourceDispatcher::ExecuteCreationMessage( |
| + const IPC::Message& creation_message) { |
| + bool handled = true; |
| + bool msg_is_good = false; |
| + IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcher, creation_message, msg_is_good) |
| + IPC_MESSAGE_HANDLER( |
| + PpapiPluginMsg_FileSystem_CreateFromPendingHost, |
| + OnMsgFileSystem_CreateFromPendingHost); |
| + IPC_MESSAGE_UNHANDLED_ERROR() |
| + IPC_END_MESSAGE_MAP() |
| + DCHECK(handled); |
| + DCHECK(msg_is_good); |
| +} |
| + |
| +void ResourceDispatcher::OnMsgFileSystem_CreateFromPendingHost( |
| + PP_FileSystemType file_system_type) { |
| + DCHECK(pending_renderer_id_); |
| + DCHECK(pending_browser_id_); |
| + // Create a plugin-side resource and attach it to the host resource. |
| + ResourceCreationProxy proxy(dispatcher_); |
|
yzshen1
2013/10/11 17:45:45
Can we just EnterResourceCreationNoLock without ex
Matt Giuca
2013/10/17 09:17:58
It looks as though the ResourceCreationProxy is no
yzshen1
2013/10/23 18:29:23
ResourceCreationProxy is what we use for most reso
Matt Giuca
2013/10/24 03:15:26
OK, this seems like a complicated change (touching
|
| + *pp_resource_ = (new FileSystemResource(GetConnection(), |
| + instance_, |
| + pending_renderer_id_, |
| + pending_browser_id_, |
| + file_system_type))->GetReference(); |
| +} |
| + |
| +Connection ResourceDispatcher::GetConnection() { |
| + return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher_); |
| +} |
| + |
| // ResourceRawVarData ---------------------------------------------------------- |
| ResourceRawVarData::ResourceRawVarData() |
| : pp_resource_(0), |
| @@ -695,12 +774,20 @@ bool ResourceRawVarData::Init(const PP_Var& var, PP_Instance /*instance*/) { |
| } |
| PP_Var ResourceRawVarData::CreatePPVar(PP_Instance instance) { |
| - // If pp_resource_ is NULL, it could be because we are on the plugin side and |
| - // there is a pending resource host on the renderer. |
| - // TODO(mgiuca): Create a plugin-side resource in this case. |
| - // Currently, this should never occur. This will be needed when passing a |
| - // resource from the renderer to the plugin (http://crbug.com/177017). |
| - DCHECK(pp_resource_); |
| + // If the var is a pending resource host, and we are on the plugin side, |
| + // create a plugin-side resource. |
| + if (PpapiGlobals::Get()->IsPluginGlobals()) { |
|
yzshen1
2013/10/11 17:45:45
If a plugin is run "in-process", the plugin side o
Matt Giuca
2013/10/17 09:17:58
Hmm, I'm actually really confused about how this w
dmichael (off chromium)
2013/10/17 17:36:11
The Var proxies aren't "refactored" to use the in-
Matt Giuca
2013/10/18 00:00:53
So (I'm obviously going to have to run the in-proc
Matt Giuca
2013/10/18 07:09:30
OK I just wrote browser tests with the help of Ray
Matt Giuca
2013/10/21 05:20:03
Actually, ignore the previous comment. The in-proc
|
| + if (!pp_resource_) { |
| + // If this check fails, then it is a null resource (not pending). |
| + DCHECK(creation_message_); |
| + ResourceDispatcher dispatcher(instance, pending_renderer_host_id_, |
| + pending_browser_host_id_, &pp_resource_); |
| + dispatcher.ExecuteCreationMessage(*creation_message_); |
| + DCHECK(pp_resource_); |
| + } |
| + } else { |
| + DCHECK(pp_resource_); |
| + } |
|
raymes
2013/10/11 04:02:24
Have you considered whether all these DCHECKs shou
Matt Giuca
2013/10/17 09:17:58
I just realised that the recent changes we made to
Matt Giuca
2013/10/21 05:20:03
Done.
|
| return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(pp_resource_); |
| } |