Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: ppapi/proxy/ppb_instance_proxy.cc

Issue 11359063: Refactor the way singleton-style resources are exposed via PPB_Instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,

Powered by Google App Engine
This is Rietveld 408576698