| 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..cdf1cffedfd1a8a1a89b5523b3a52c75989592b6 100644
|
| --- a/ppapi/proxy/ppb_instance_proxy.cc
|
| +++ b/ppapi/proxy/ppb_instance_proxy.cc
|
| @@ -331,67 +331,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);
|
| + 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.
|
| + 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] = linked_ptr<Resource>(new_singleton);
|
| + return new_singleton;
|
| }
|
|
|
| int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance,
|
|
|