diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 03:40:57 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 03:40:57 +0000 |
commit | 9164da3d0c42047557da22bbf9952c35dd956d03 (patch) | |
tree | 9c0b8be62f277e36249ef930ba0b1ff74974c368 /ppapi | |
parent | 0704cafcee4819cd7f7bcccc2803aef18dc949b6 (diff) | |
download | chromium_src-9164da3d0c42047557da22bbf9952c35dd956d03.zip chromium_src-9164da3d0c42047557da22bbf9952c35dd956d03.tar.gz chromium_src-9164da3d0c42047557da22bbf9952c35dd956d03.tar.bz2 |
PluginResource: Avoid having two sets of similar methods for talking with browser and renderer.
BUG=None
TEST=None
Review URL: https://chromiumcodereview.appspot.com/11106019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/file_chooser_resource.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/flash_device_id_resource.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/flash_font_file_resource.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/flash_resource.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/gamepad_resource.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/plugin_resource.cc | 47 | ||||
-rw-r--r-- | ppapi/proxy/plugin_resource.h | 61 | ||||
-rw-r--r-- | ppapi/proxy/printing_resource.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/websocket_resource.cc | 12 |
9 files changed, 57 insertions, 88 deletions
diff --git a/ppapi/proxy/file_chooser_resource.cc b/ppapi/proxy/file_chooser_resource.cc index f41ade5..5c11012 100644 --- a/ppapi/proxy/file_chooser_resource.cc +++ b/ppapi/proxy/file_chooser_resource.cc @@ -130,7 +130,7 @@ int32_t FileChooserResource::ShowInternal( return PP_ERROR_INPROGRESS; if (!sent_create_to_renderer()) - SendCreateToRenderer(PpapiHostMsg_FileChooser_Create()); + SendCreate(RENDERER, PpapiHostMsg_FileChooser_Create()); callback_ = callback; StringVar* sugg_str = StringVar::FromPPVar(suggested_file_name); @@ -140,7 +140,7 @@ int32_t FileChooserResource::ShowInternal( mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE, sugg_str ? sugg_str->value() : std::string(), accept_types_); - CallRenderer<PpapiPluginMsg_FileChooser_ShowReply>(msg, + Call<PpapiPluginMsg_FileChooser_ShowReply>(RENDERER, msg, base::Bind(&FileChooserResource::OnPluginMsgShowReply, this)); return PP_OK_COMPLETIONPENDING; } diff --git a/ppapi/proxy/flash_device_id_resource.cc b/ppapi/proxy/flash_device_id_resource.cc index 1698b49..d7174bd 100644 --- a/ppapi/proxy/flash_device_id_resource.cc +++ b/ppapi/proxy/flash_device_id_resource.cc @@ -17,7 +17,7 @@ FlashDeviceIDResource::FlashDeviceIDResource(Connection connection, PP_Instance instance) : PluginResource(connection, instance), dest_(NULL) { - SendCreateToBrowser(PpapiHostMsg_FlashDeviceID_Create()); + SendCreate(BROWSER, PpapiHostMsg_FlashDeviceID_Create()); } FlashDeviceIDResource::~FlashDeviceIDResource() { @@ -39,7 +39,8 @@ int32_t FlashDeviceIDResource::GetDeviceID( dest_ = id; callback_ = callback; - CallBrowser<PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply>( + Call<PpapiPluginMsg_FlashDeviceID_GetDeviceIDReply>( + BROWSER, PpapiHostMsg_FlashDeviceID_GetDeviceID(), base::Bind(&FlashDeviceIDResource::OnPluginMsgGetDeviceIDReply, this)); return PP_OK_COMPLETIONPENDING; diff --git a/ppapi/proxy/flash_font_file_resource.cc b/ppapi/proxy/flash_font_file_resource.cc index 9dec65e..e835ac1 100644 --- a/ppapi/proxy/flash_font_file_resource.cc +++ b/ppapi/proxy/flash_font_file_resource.cc @@ -38,8 +38,8 @@ PP_Bool FlashFontFileResource::GetFontTable(uint32_t table, return PP_FALSE; if (!sent_create_to_renderer()) { - SendCreateToRenderer( - PpapiHostMsg_FlashFontFile_Create(description_, charset_)); + SendCreate( + RENDERER, PpapiHostMsg_FlashFontFile_Create(description_, charset_)); } std::string* contents = GetFontTable(table); diff --git a/ppapi/proxy/flash_resource.cc b/ppapi/proxy/flash_resource.cc index 41bec16..9a20853 100644 --- a/ppapi/proxy/flash_resource.cc +++ b/ppapi/proxy/flash_resource.cc @@ -16,7 +16,7 @@ namespace proxy { FlashResource::FlashResource(Connection connection, PP_Instance instance) : PluginResource(connection, instance) { - SendCreateToRenderer(PpapiHostMsg_Flash_Create()); + SendCreate(RENDERER, PpapiHostMsg_Flash_Create()); } FlashResource::~FlashResource() { diff --git a/ppapi/proxy/gamepad_resource.cc b/ppapi/proxy/gamepad_resource.cc index fa028e4..3055513 100644 --- a/ppapi/proxy/gamepad_resource.cc +++ b/ppapi/proxy/gamepad_resource.cc @@ -48,8 +48,9 @@ GamepadResource::GamepadResource(Connection connection, PP_Instance instance) buffer_(NULL) { memset(&last_read_, 0, sizeof(last_read_)); - SendCreateToBrowser(PpapiHostMsg_Gamepad_Create()); - CallBrowser<PpapiPluginMsg_Gamepad_SendMemory>( + SendCreate(BROWSER, PpapiHostMsg_Gamepad_Create()); + Call<PpapiPluginMsg_Gamepad_SendMemory>( + BROWSER, PpapiHostMsg_Gamepad_RequestMemory(), base::Bind(&GamepadResource::OnPluginMsgSendMemory, this)); } diff --git a/ppapi/proxy/plugin_resource.cc b/ppapi/proxy/plugin_resource.cc index 99ade83..c568df5 100644 --- a/ppapi/proxy/plugin_resource.cc +++ b/ppapi/proxy/plugin_resource.cc @@ -5,7 +5,6 @@ #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/resource_message_params.h" namespace ppapi { namespace proxy { @@ -43,48 +42,36 @@ void PluginResource::OnReplyReceived( } } -void PluginResource::SendCreateToBrowser(const IPC::Message& msg) { - DCHECK(!sent_create_to_browser_); - sent_create_to_browser_ = true; - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); - connection_.browser_sender->Send( - new PpapiHostMsg_ResourceCreated(params, pp_instance(), msg)); -} - -void PluginResource::SendCreateToRenderer(const IPC::Message& msg) { - DCHECK(!sent_create_to_renderer_); - sent_create_to_renderer_ = true; - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); - connection_.renderer_sender->Send( +void PluginResource::SendCreate(Destination dest, const IPC::Message& msg) { + if (dest == RENDERER) { + DCHECK(!sent_create_to_renderer_); + sent_create_to_renderer_ = true; + } else { + DCHECK(!sent_create_to_browser_); + sent_create_to_browser_ = true; + } + ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); + GetSender(dest)->Send( new PpapiHostMsg_ResourceCreated(params, pp_instance(), msg)); } -void PluginResource::PostToBrowser(const IPC::Message& msg) { - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); - SendResourceCall(connection_.browser_sender, params, msg); -} - -void PluginResource::PostToRenderer(const IPC::Message& msg) { - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); - SendResourceCall(connection_.renderer_sender, params, msg); +void PluginResource::Post(Destination dest, const IPC::Message& msg) { + ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); + SendResourceCall(dest, params, msg); } bool PluginResource::SendResourceCall( - IPC::Sender* sender, + Destination dest, const ResourceMessageCallParams& call_params, const IPC::Message& nested_msg) { - return sender->Send(new PpapiHostMsg_ResourceCall(call_params, nested_msg)); + return GetSender(dest)->Send( + new PpapiHostMsg_ResourceCall(call_params, nested_msg)); } int32_t PluginResource::GenericSyncCall(Destination dest, const IPC::Message& msg, IPC::Message* reply) { - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); + ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); params.set_has_callback(); ResourceMessageReplyParams reply_params; bool success = GetSender(dest)->Send(new PpapiHostMsg_ResourceSyncCall( diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h index 727ff9e..b763d1a 100644 --- a/ppapi/proxy/plugin_resource.h +++ b/ppapi/proxy/plugin_resource.h @@ -16,6 +16,7 @@ #include "ppapi/proxy/plugin_resource_callback.h" #include "ppapi/proxy/ppapi_message_utils.h" #include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/proxy/resource_message_params.h" #include "ppapi/shared_impl/resource.h" namespace ppapi { @@ -51,20 +52,19 @@ class PPAPI_PROXY_EXPORT PluginResource : public Resource { } // Sends a create message to the browser or renderer for the current resource. - void SendCreateToBrowser(const IPC::Message& msg); - void SendCreateToRenderer(const IPC::Message& msg); + void SendCreate(Destination dest, const IPC::Message& msg); // Sends the given IPC message as a resource request to the host // corresponding to this resource object and does not expect a reply. - void PostToBrowser(const IPC::Message& msg); - void PostToRenderer(const IPC::Message& msg); + void Post(Destination dest, const IPC::Message& msg); - // Like PostToBrowser/Renderer but expects a response. |callback| is - // a |base::Callback| that will be run when a reply message with a sequence - // number matching that of the call is received. |ReplyMsgClass| is the type - // of the reply message that is expected. An example of usage: + // Like Post() but expects a response. |callback| is a |base::Callback| that + // will be run when a reply message with a sequence number matching that of + // the call is received. |ReplyMsgClass| is the type of the reply message that + // is expected. An example of usage: // - // CallBrowser<PpapiPluginMsg_MyResourceType_MyReplyMessage>( + // Call<PpapiPluginMsg_MyResourceType_MyReplyMessage>( + // BROWSER, // PpapiHostMsg_MyResourceType_MyRequestMessage(), // base::Bind(&MyPluginResource::ReplyHandler, this)); // @@ -77,9 +77,9 @@ class PPAPI_PROXY_EXPORT PluginResource : public Resource { // // Note that all integers (including 0 and -1) are valid request IDs. template<typename ReplyMsgClass, typename CallbackType> - int32_t CallBrowser(const IPC::Message& msg, const CallbackType& callback); - template<typename ReplyMsgClass, typename CallbackType> - int32_t CallRenderer(const IPC::Message& msg, const CallbackType& callback); + int32_t Call(Destination dest, + const IPC::Message& msg, + const CallbackType& callback); // Calls the browser/renderer with sync messages. Returns the pepper error // code from the call. @@ -109,18 +109,12 @@ class PPAPI_PROXY_EXPORT PluginResource : public Resource { Destination dest, const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e); private: - // Helper function to send a |PpapiHostMsg_ResourceCall| to the given sender - // with |nested_msg| and |call_params|. - bool SendResourceCall(IPC::Sender* sender, + // Helper function to send a |PpapiHostMsg_ResourceCall| to the given + // destination with |nested_msg| and |call_params|. + bool SendResourceCall(Destination dest, const ResourceMessageCallParams& call_params, const IPC::Message& nested_msg); - // Helper function to make a Resource Call to a host with a callback. - template<typename ReplyMsgClass, typename CallbackType> - int32_t CallHost(IPC::Sender* sender, - const IPC::Message& msg, - const CallbackType& callback); - int32_t GenericSyncCall(Destination dest, const IPC::Message& msg, IPC::Message* reply_msg); @@ -140,32 +134,17 @@ class PPAPI_PROXY_EXPORT PluginResource : public Resource { }; template<typename ReplyMsgClass, typename CallbackType> -int32_t PluginResource::CallBrowser(const IPC::Message& msg, - const CallbackType& callback) { - return CallHost<ReplyMsgClass, CallbackType>( - connection_.browser_sender, msg, callback); -} - -template<typename ReplyMsgClass, typename CallbackType> -int32_t PluginResource::CallRenderer(const IPC::Message& msg, - const CallbackType& callback) { - return CallHost<ReplyMsgClass, CallbackType>( - connection_.renderer_sender, msg, callback); -} - -template<typename ReplyMsgClass, typename CallbackType> -int32_t PluginResource::CallHost(IPC::Sender* sender, - const IPC::Message& msg, - const CallbackType& callback) { - ResourceMessageCallParams params(pp_resource(), - next_sequence_number_++); +int32_t PluginResource::Call(Destination dest, + const IPC::Message& msg, + const CallbackType& callback) { + ResourceMessageCallParams params(pp_resource(), next_sequence_number_++); // Stash the |callback| in |callbacks_| identified by the sequence number of // the call. scoped_refptr<PluginResourceCallbackBase> plugin_callback( new PluginResourceCallback<ReplyMsgClass, CallbackType>(callback)); callbacks_.insert(std::make_pair(params.sequence(), plugin_callback)); params.set_has_callback(); - SendResourceCall(sender, params, msg); + SendResourceCall(dest, params, msg); return params.sequence(); } diff --git a/ppapi/proxy/printing_resource.cc b/ppapi/proxy/printing_resource.cc index 22950c2..6c1ae17 100644 --- a/ppapi/proxy/printing_resource.cc +++ b/ppapi/proxy/printing_resource.cc @@ -31,9 +31,10 @@ int32_t PrintingResource::GetDefaultPrintSettings( return PP_ERROR_BADARGUMENT; if (!sent_create_to_browser()) - SendCreateToBrowser(PpapiHostMsg_Printing_Create()); + SendCreate(BROWSER, PpapiHostMsg_Printing_Create()); - CallBrowser<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>( + Call<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>( + BROWSER, PpapiHostMsg_Printing_GetDefaultPrintSettings(), base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply, this, print_settings, callback)); diff --git a/ppapi/proxy/websocket_resource.cc b/ppapi/proxy/websocket_resource.cc index de9ee2b..1f93c8b 100644 --- a/ppapi/proxy/websocket_resource.cc +++ b/ppapi/proxy/websocket_resource.cc @@ -116,9 +116,9 @@ int32_t WebSocketResource::Connect( // Create remote host in the renderer, then request to check the URL and // establish the connection. state_ = PP_WEBSOCKETREADYSTATE_CONNECTING; - SendCreateToRenderer(PpapiHostMsg_WebSocket_Create()); + SendCreate(RENDERER, PpapiHostMsg_WebSocket_Create()); PpapiHostMsg_WebSocket_Connect msg(url_->value(), protocol_strings); - CallRenderer<PpapiPluginMsg_WebSocket_ConnectReply>(msg, + Call<PpapiPluginMsg_WebSocket_ConnectReply>(RENDERER, msg, base::Bind(&WebSocketResource::OnPluginMsgConnectReply, this)); return PP_OK_COMPLETIONPENDING; @@ -178,7 +178,7 @@ int32_t WebSocketResource::Close(uint16_t code, // Need to do a "Post" to avoid reentering the plugin. connect_callback_->PostAbort(); connect_callback_ = NULL; - PostToRenderer(PpapiHostMsg_WebSocket_Fail( + Post(RENDERER, PpapiHostMsg_WebSocket_Fail( "WebSocket was closed before the connection was established.")); return PP_OK_COMPLETIONPENDING; } @@ -195,7 +195,7 @@ int32_t WebSocketResource::Close(uint16_t code, state_ = PP_WEBSOCKETREADYSTATE_CLOSING; PpapiHostMsg_WebSocket_Close msg(static_cast<int32_t>(event_code), reason_string); - CallRenderer<PpapiPluginMsg_WebSocket_CloseReply>(msg, + Call<PpapiPluginMsg_WebSocket_CloseReply>(RENDERER, msg, base::Bind(&WebSocketResource::OnPluginMsgCloseReply, this)); return PP_OK_COMPLETIONPENDING; } @@ -269,7 +269,7 @@ int32_t WebSocketResource::SendMessage(const PP_Var& message) { scoped_refptr<StringVar> message_string = StringVar::FromPPVar(message); if (!message_string) return PP_ERROR_BADARGUMENT; - PostToRenderer(PpapiHostMsg_WebSocket_SendText(message_string->value())); + Post(RENDERER, PpapiHostMsg_WebSocket_SendText(message_string->value())); } else if (message.type == PP_VARTYPE_ARRAY_BUFFER) { // Convert message to std::vector<uint8_t>, then send it. scoped_refptr<ArrayBufferVar> message_arraybuffer = @@ -280,7 +280,7 @@ int32_t WebSocketResource::SendMessage(const PP_Var& message) { uint32 message_length = message_arraybuffer->ByteLength(); std::vector<uint8_t> message_vector(message_data, message_data + message_length); - PostToRenderer(PpapiHostMsg_WebSocket_SendBinary(message_vector)); + Post(RENDERER, PpapiHostMsg_WebSocket_SendBinary(message_vector)); } else { // TODO(toyoshim): Support Blob. return PP_ERROR_NOTSUPPORTED; |