Index: ppapi/proxy/ppb_flash_message_loop_proxy.cc |
diff --git a/ppapi/proxy/ppb_flash_message_loop_proxy.cc b/ppapi/proxy/ppb_flash_message_loop_proxy.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cbb4c1ee5eafa3f474bbd6ad1e6bd3eb28e88911 |
--- /dev/null |
+++ b/ppapi/proxy/ppb_flash_message_loop_proxy.cc |
@@ -0,0 +1,178 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ppapi/proxy/ppb_flash_message_loop_proxy.h" |
+ |
+#include "ppapi/c/pp_completion_callback.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/c/private/ppb_flash_message_loop.h" |
+#include "ppapi/proxy/enter_proxy.h" |
+#include "ppapi/proxy/plugin_dispatcher.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/shared_impl/resource.h" |
+#include "ppapi/thunk/enter.h" |
+#include "ppapi/thunk/ppb_flash_message_loop_api.h" |
+#include "ppapi/thunk/resource_creation_api.h" |
+ |
+namespace { |
+ |
+struct CallbackContext { |
+ // Take ownership of |in_reply_message|. |
+ CallbackContext( |
+ const base::WeakPtr<ppapi::proxy::PPB_Flash_MessageLoop_Proxy>& in_sender, |
+ IPC::Message* in_reply_message) |
+ : sender(in_sender), |
+ reply_message(in_reply_message) { |
+ } |
+ |
+ base::WeakPtr<ppapi::proxy::PPB_Flash_MessageLoop_Proxy> sender; |
+ scoped_ptr<IPC::Message> reply_message; |
+}; |
+ |
+} // namespace |
+ |
+using ppapi::thunk::PPB_Flash_MessageLoop_API; |
+ |
+namespace ppapi { |
+namespace proxy { |
+namespace { |
+ |
+class FlashMessageLoop : public PPB_Flash_MessageLoop_API, public Resource { |
+ public: |
+ explicit FlashMessageLoop(const HostResource& resource); |
+ virtual ~FlashMessageLoop(); |
+ |
+ // Resource overrides. |
+ virtual PPB_Flash_MessageLoop_API* AsPPB_Flash_MessageLoop_API() OVERRIDE; |
+ |
+ // PPB_Flash_MesssageLoop_API implementation. |
+ virtual int32_t Run() OVERRIDE; |
+ virtual void Quit() OVERRIDE; |
+ virtual void RunFromHostProxy(PP_CompletionCallback callback) OVERRIDE; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(FlashMessageLoop); |
+}; |
+ |
+FlashMessageLoop::FlashMessageLoop(const HostResource& resource) |
+ : Resource(resource) { |
+} |
+ |
+FlashMessageLoop::~FlashMessageLoop() { |
+} |
+ |
+PPB_Flash_MessageLoop_API* FlashMessageLoop::AsPPB_Flash_MessageLoop_API() { |
+ return this; |
+} |
+ |
+int32_t FlashMessageLoop::Run() { |
+ int32_t result = PP_ERROR_FAILED; |
+ IPC::SyncMessage* msg = new PpapiHostMsg_PPBFlashMessageLoop_Run( |
+ API_ID_PPB_FLASH_MESSAGELOOP, host_resource(), &result); |
+ msg->EnableMessagePumping(); |
+ PluginDispatcher::GetForResource(this)->Send(msg); |
+ return result; |
+} |
+ |
+void FlashMessageLoop::Quit() { |
+ PluginDispatcher::GetForResource(this)->Send( |
+ new PpapiHostMsg_PPBFlashMessageLoop_Quit( |
+ API_ID_PPB_FLASH_MESSAGELOOP, host_resource())); |
+} |
+ |
+void FlashMessageLoop::RunFromHostProxy(PP_CompletionCallback callback) { |
+ // This should never be called on the plugin side. |
+ NOTREACHED(); |
+} |
+ |
+} // namespace |
+ |
+PPB_Flash_MessageLoop_Proxy::PPB_Flash_MessageLoop_Proxy(Dispatcher* dispatcher) |
+ : InterfaceProxy(dispatcher), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
+} |
+ |
+PPB_Flash_MessageLoop_Proxy::~PPB_Flash_MessageLoop_Proxy() { |
+} |
+ |
+// static |
+PP_Resource PPB_Flash_MessageLoop_Proxy::CreateProxyResource( |
+ PP_Instance instance) { |
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
+ if (!dispatcher) |
+ return 0; |
+ |
+ HostResource result; |
+ dispatcher->Send(new PpapiHostMsg_PPBFlashMessageLoop_Create( |
+ API_ID_PPB_FLASH_MESSAGELOOP, instance, &result)); |
+ if (result.is_null()) |
+ return 0; |
+ return (new FlashMessageLoop(result))->GetReference(); |
+} |
+ |
+bool PPB_Flash_MessageLoop_Proxy::OnMessageReceived(const IPC::Message& msg) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(PPB_Flash_MessageLoop_Proxy, msg) |
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMessageLoop_Create, |
+ OnMsgCreate) |
+ // We cannot use IPC_MESSAGE_HANDLER here. Because it tries to send the sync |
+ // message reply after the handler returns. However, in this case, the |
+ // PPB_Flash_MessageLoop_Proxy object may be destroyed before the handler |
+ // returns. |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_PPBFlashMessageLoop_Run, |
+ OnMsgRun) |
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMessageLoop_Quit, |
+ OnMsgQuit) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void PPB_Flash_MessageLoop_Proxy::OnMsgCreate(PP_Instance instance, |
+ HostResource* result) { |
+ thunk::EnterResourceCreation enter(instance); |
+ if (enter.succeeded()) { |
+ result->SetHostResource( |
+ instance, enter.functions()->CreateFlashMessageLoop(instance)); |
+ } |
+} |
+ |
+void PPB_Flash_MessageLoop_Proxy::OnMsgRun( |
+ const HostResource& flash_message_loop, |
+ IPC::Message* reply) { |
+ PP_CompletionCallback callback = PP_MakeCompletionCallback( |
+ PPB_Flash_MessageLoop_Proxy::WillQuitSoon, |
+ new CallbackContext(weak_ptr_factory_.GetWeakPtr(), reply)); |
+ |
+ EnterHostFromHostResource<PPB_Flash_MessageLoop_API> |
+ enter(flash_message_loop); |
+ if (enter.succeeded()) |
+ enter.object()->RunFromHostProxy(callback); |
+ else |
+ PP_RunCompletionCallback(&callback, PP_ERROR_BADRESOURCE); |
+} |
+ |
+void PPB_Flash_MessageLoop_Proxy::OnMsgQuit( |
+ const ppapi::HostResource& flash_message_loop) { |
+ EnterHostFromHostResource<PPB_Flash_MessageLoop_API> |
+ enter(flash_message_loop); |
+ if (enter.succeeded()) |
+ enter.object()->Quit(); |
+} |
+ |
+// static |
+void PPB_Flash_MessageLoop_Proxy::WillQuitSoon(void* user_data, |
+ int32_t result) { |
+ scoped_ptr<CallbackContext> context( |
+ reinterpret_cast<CallbackContext*>(user_data)); |
viettrungluu
2012/01/17 21:26:06
static_cast
yzshen1
2012/01/18 07:43:35
Done.
|
+ |
+ if (context->sender.get()) { |
+ PpapiHostMsg_PPBFlashMessageLoop_Run::WriteReplyParams( |
+ context->reply_message.get(), result); |
+ context->sender->Send(context->reply_message.release()); |
+ } |
+} |
+ |
+} // namespace proxy |
+} // namespace ppapi |