Chromium Code Reviews| Index: ppapi/proxy/ppb_instance_proxy.cc |
| diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc |
| index cb8389051226f958fd05363f56c29527a1849c14..3559aa682d859d91b167bb447923f07889d4ab7d 100644 |
| --- a/ppapi/proxy/ppb_instance_proxy.cc |
| +++ b/ppapi/proxy/ppb_instance_proxy.cc |
| @@ -4,6 +4,7 @@ |
| #include "ppapi/proxy/ppb_instance_proxy.h" |
| +#include "base/memory/ref_counted.h" |
| #include "build/build_config.h" |
| #include "ppapi/c/pp_errors.h" |
| #include "ppapi/c/pp_time.h" |
| @@ -331,67 +332,48 @@ thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { |
| return static_cast<PPB_Flash_Proxy*>(ip); |
| } |
| -// TODO(raymes): We can most likely cut down this boilerplate for grabbing |
| -// singleton resource APIs. |
| -thunk::PPB_Flash_Functions_API* PPB_Instance_Proxy::GetFlashFunctionsAPI( |
| - PP_Instance instance) { |
| -#if !defined(OS_NACL) && !defined(NACL_WIN64) |
| +Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance, |
| + SingletonResourceID id) { |
| InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| GetInstanceData(instance); |
| - if (!data) |
| - return NULL; |
| - if (!data->flash_resource.get()) { |
| - Connection connection( |
| - PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), |
| - dispatcher()); |
| - data->flash_resource = new FlashResource(connection, instance); |
| - } |
| - return data->flash_resource.get(); |
| -#else |
| - // Flash functions aren't implemented for nacl. |
| - NOTIMPLEMENTED(); |
| - return NULL; |
| -#endif // !defined(OS_NACL) && !defined(NACL_WIN64) |
| -} |
| + InstanceData::SingletonResourceMap::iterator it = |
| + data->singleton_resources.find(id); |
| + if (it != data->singleton_resources.end()) |
| + return it->second.get(); |
| -thunk::PPB_Flash_Clipboard_API* PPB_Instance_Proxy::GetFlashClipboardAPI( |
| - PP_Instance instance) { |
| -#if !defined(OS_NACL) && !defined(NACL_WIN64) |
| - InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| - GetInstanceData(instance); |
| - if (!data) |
| - return NULL; |
| + Resource* new_singleton(NULL); |
|
dmichael (off chromium)
2012/11/21 17:26:27
How about making this a scoped_refptr? Just so if
raymes
2012/11/21 20:59:10
Done.
|
| + Connection connection( |
| + PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), |
| + dispatcher()); |
| - if (!data->flash_clipboard_resource.get()) { |
| - Connection connection( |
| - PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), |
| - dispatcher()); |
| - data->flash_clipboard_resource = |
| - new FlashClipboardResource(connection, instance); |
| - } |
| - return data->flash_clipboard_resource.get(); |
| -#else |
| - // Flash functions aren't implemented for nacl. |
| - NOTIMPLEMENTED(); |
| - return NULL; |
| + switch (id) { |
| +// Flash resources aren't needed for NaCl. |
| +#if !defined(OS_NACL) && !defined(NACL_WIN64) |
| + case FLASH_SINGLETON_ID: |
| + new_singleton = new FlashResource(connection, instance); |
| + break; |
| + case FLASH_CLIPBOARD_SINGLETON_ID: |
| + new_singleton = new FlashClipboardResource(connection, instance); |
| + break; |
| #endif // !defined(OS_NACL) && !defined(NACL_WIN64) |
| -} |
| + case GAMEPAD_SINGLETON_ID: |
| + new_singleton = new GamepadResource(connection, instance); |
| + break; |
| + default: |
| + // Unfortunately the default case is needed because we ifdef out some of |
| + // the cases. |
|
dmichael (off chromium)
2012/11/21 17:26:27
What about moving the #ifdef to the end, and havin
raymes
2012/11/21 20:59:10
Done.
|
| + break; |
| + } |
| -thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI( |
| - PP_Instance instance) { |
| - InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
| - GetInstanceData(instance); |
| - if (!data) |
| + if (!new_singleton) { |
| + // Getting here implies that a constructor is missing in the above switch. |
| + NOTREACHED(); |
| return NULL; |
| - |
| - if (!data->gamepad_resource.get()) { |
| - Connection connection( |
| - PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), |
| - dispatcher()); |
| - data->gamepad_resource = new GamepadResource(connection, instance); |
| } |
| - return data->gamepad_resource.get(); |
| + |
| + data->singleton_resources[id] = scoped_refptr<Resource>(new_singleton); |
| + return new_singleton; |
| } |
| int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, |