| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_core_proxy.h" | 5 #include "ppapi/proxy/ppb_core_proxy.h" |
| 6 | 6 |
| 7 #include <stdlib.h> // For malloc | 7 #include <stdlib.h> // For malloc |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 14 #include "base/time.h" | 12 #include "base/time.h" |
| 15 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
| 16 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
| 17 #include "ppapi/c/ppb_core.h" | 15 #include "ppapi/c/ppb_core.h" |
| 18 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
| 19 #include "ppapi/proxy/plugin_resource_tracker.h" | 17 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 20 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
| 21 #include "ppapi/shared_impl/ppapi_globals.h" | 19 #include "ppapi/shared_impl/ppapi_globals.h" |
| 22 #include "ppapi/shared_impl/proxy_lock.h" | 20 #include "ppapi/shared_impl/proxy_lock.h" |
| 23 #include "ppapi/shared_impl/time_conversion.h" | 21 #include "ppapi/shared_impl/time_conversion.h" |
| 24 | 22 |
| 25 namespace ppapi { | 23 namespace ppapi { |
| 26 namespace proxy { | 24 namespace proxy { |
| 27 | 25 |
| 28 namespace { | 26 namespace { |
| 29 | 27 |
| 30 base::MessageLoopProxy* GetMainThreadMessageLoop() { | |
| 31 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy, | |
| 32 (base::MessageLoopProxy::current())); | |
| 33 return proxy.get(); | |
| 34 } | |
| 35 | |
| 36 void AddRefResource(PP_Resource resource) { | 28 void AddRefResource(PP_Resource resource) { |
| 37 ppapi::ProxyAutoLock lock; | 29 ppapi::ProxyAutoLock lock; |
| 38 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); | 30 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); |
| 39 } | 31 } |
| 40 | 32 |
| 41 void ReleaseResource(PP_Resource resource) { | 33 void ReleaseResource(PP_Resource resource) { |
| 42 ppapi::ProxyAutoLock lock; | 34 ppapi::ProxyAutoLock lock; |
| 43 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); | 35 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); |
| 44 } | 36 } |
| 45 | 37 |
| 46 double GetTime() { | 38 double GetTime() { |
| 47 return TimeToPPTime(base::Time::Now()); | 39 return TimeToPPTime(base::Time::Now()); |
| 48 } | 40 } |
| 49 | 41 |
| 50 double GetTimeTicks() { | 42 double GetTimeTicks() { |
| 51 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 43 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
| 52 } | 44 } |
| 53 | 45 |
| 54 void CallbackWrapper(PP_CompletionCallback callback, int32_t result) { | 46 void CallbackWrapper(PP_CompletionCallback callback, int32_t result) { |
| 55 TRACE_EVENT2("ppapi proxy", "CallOnMainThread callback", | 47 TRACE_EVENT2("ppapi proxy", "CallOnMainThread callback", |
| 56 "Func", reinterpret_cast<void*>(callback.func), | 48 "Func", reinterpret_cast<void*>(callback.func), |
| 57 "UserData", callback.user_data); | 49 "UserData", callback.user_data); |
| 58 CallWhileUnlocked(PP_RunCompletionCallback, &callback, result); | 50 CallWhileUnlocked(PP_RunCompletionCallback, &callback, result); |
| 59 } | 51 } |
| 60 | 52 |
| 61 void CallOnMainThread(int delay_in_ms, | 53 void CallOnMainThread(int delay_in_ms, |
| 62 PP_CompletionCallback callback, | 54 PP_CompletionCallback callback, |
| 63 int32_t result) { | 55 int32_t result) { |
| 64 GetMainThreadMessageLoop()->PostDelayedTask( | 56 DCHECK(callback.func); |
| 57 if (!callback.func) |
| 58 return; |
| 59 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask( |
| 65 FROM_HERE, | 60 FROM_HERE, |
| 66 RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)), | 61 RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)), |
| 67 base::TimeDelta::FromMilliseconds(delay_in_ms)); | 62 base::TimeDelta::FromMilliseconds(delay_in_ms)); |
| 68 } | 63 } |
| 69 | 64 |
| 70 PP_Bool IsMainThread() { | 65 PP_Bool IsMainThread() { |
| 71 return PP_FromBool(GetMainThreadMessageLoop()->BelongsToCurrentThread()); | 66 return PP_FromBool(PpapiGlobals::Get()-> |
| 67 GetMainThreadMessageLoop()->BelongsToCurrentThread()); |
| 72 } | 68 } |
| 73 | 69 |
| 74 const PPB_Core core_interface = { | 70 const PPB_Core core_interface = { |
| 75 &AddRefResource, | 71 &AddRefResource, |
| 76 &ReleaseResource, | 72 &ReleaseResource, |
| 77 &GetTime, | 73 &GetTime, |
| 78 &GetTimeTicks, | 74 &GetTimeTicks, |
| 79 &CallOnMainThread, | 75 &CallOnMainThread, |
| 80 &IsMainThread | 76 &IsMainThread |
| 81 }; | 77 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void PPB_Core_Proxy::OnMsgAddRefResource(const HostResource& resource) { | 111 void PPB_Core_Proxy::OnMsgAddRefResource(const HostResource& resource) { |
| 116 ppb_core_impl_->AddRefResource(resource.host_resource()); | 112 ppb_core_impl_->AddRefResource(resource.host_resource()); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void PPB_Core_Proxy::OnMsgReleaseResource(const HostResource& resource) { | 115 void PPB_Core_Proxy::OnMsgReleaseResource(const HostResource& resource) { |
| 120 ppb_core_impl_->ReleaseResource(resource.host_resource()); | 116 ppb_core_impl_->ReleaseResource(resource.host_resource()); |
| 121 } | 117 } |
| 122 | 118 |
| 123 } // namespace proxy | 119 } // namespace proxy |
| 124 } // namespace ppapi | 120 } // namespace ppapi |
| OLD | NEW |