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

Unified Diff: ppapi/proxy/ppb_core_proxy.cc

Issue 4345003: Add proxies for core and class (for calling from WebKit to the plugin). These... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « ppapi/proxy/ppb_core_proxy.h ('k') | ppapi/proxy/ppp_class_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/ppb_core_proxy.cc
===================================================================
--- ppapi/proxy/ppb_core_proxy.cc (revision 0)
+++ ppapi/proxy/ppb_core_proxy.cc (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (c) 2010 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_core_proxy.h"
+
+#include <stdlib.h> // For malloc
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/time.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+base::MessageLoopProxy* GetMainThreadMessageLoop() {
+ static scoped_refptr<base::MessageLoopProxy> proxy(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ return proxy.get();
+}
+
+void AddRefResource(PP_Resource resource) {
+ PluginDispatcher::Get()->plugin_resource_tracker()->AddRefResource(resource);
+}
+
+void ReleaseResource(PP_Resource resource) {
+ PluginDispatcher::Get()->plugin_resource_tracker()->ReleaseResource(resource);
+}
+
+void* MemAlloc(size_t num_bytes) {
+ return malloc(num_bytes);
+}
+
+void MemFree(void* ptr) {
+ free(ptr);
+}
+
+double GetTime() {
+ return base::Time::Now().ToDoubleT();
+}
+
+double GetTimeTicks() {
+ // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448
+ // This should be a tick timer rather than wall clock time, but needs to
+ // match message times, which also currently use wall clock time.
+ return GetTime();
+}
+
+void CallOnMainThread(int delay_in_ms,
+ PP_CompletionCallback callback,
+ int32_t result) {
+ GetMainThreadMessageLoop()->PostDelayedTask(
+ FROM_HERE,
+ NewRunnableFunction(callback.func, callback.user_data, result),
+ delay_in_ms);
+}
+
+bool IsMainThread() {
+ return GetMainThreadMessageLoop()->BelongsToCurrentThread();
+}
+
+const PPB_Core core_interface = {
+ &AddRefResource,
+ &ReleaseResource,
+ &MemAlloc,
+ &MemFree,
+ &GetTime,
+ &GetTimeTicks,
+ &CallOnMainThread,
+ &IsMainThread
+};
+
+} // namespace
+
+PPB_Core_Proxy::PPB_Core_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Core_Proxy::~PPB_Core_Proxy() {
+}
+
+const void* PPB_Core_Proxy::GetSourceInterface() const {
+ return &core_interface;
+}
+
+InterfaceID PPB_Core_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_CORE;
+}
+
+void PPB_Core_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Core_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCore_AddRefResource,
+ OnMsgAddRefResource)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCore_ReleaseResource,
+ OnMsgReleaseResource)
+ IPC_END_MESSAGE_MAP()
+ // TODO(brettw) handle bad messages!
+}
+
+void PPB_Core_Proxy::OnMsgAddRefResource(PP_Resource resource) {
+ ppb_core_target()->AddRefResource(resource);
+}
+
+void PPB_Core_Proxy::OnMsgReleaseResource(PP_Resource resource) {
+ ppb_core_target()->ReleaseResource(resource);
+}
+
+} // namespace proxy
+} // namespace pp
Property changes on: ppapi/proxy/ppb_core_proxy.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « ppapi/proxy/ppb_core_proxy.h ('k') | ppapi/proxy/ppp_class_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698