OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/time/time.h" |
| 10 #include "mojo/examples/pepper_container_app/plugin_instance.h" |
| 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/shared_impl/ppb_message_loop_shared.h" |
| 13 |
| 14 namespace mojo { |
| 15 namespace examples { |
| 16 |
| 17 const PP_Instance MojoPpapiGlobals::kInstanceId = 1; |
| 18 |
| 19 class MojoPpapiGlobals::MainThreadMessageLoopResource |
| 20 : public ppapi::MessageLoopShared { |
| 21 public: |
| 22 explicit MainThreadMessageLoopResource( |
| 23 base::MessageLoopProxy* main_thread_message_loop) |
| 24 : MessageLoopShared(ForMainThread()), |
| 25 main_thread_message_loop_(main_thread_message_loop) {} |
| 26 virtual ~MainThreadMessageLoopResource() {} |
| 27 |
| 28 // ppapi::MessageLoopShared implementation. |
| 29 virtual void PostClosure(const tracked_objects::Location& from_here, |
| 30 const base::Closure& closure, |
| 31 int64 delay_ms) OVERRIDE { |
| 32 main_thread_message_loop_->PostDelayedTask( |
| 33 from_here, closure, base::TimeDelta::FromMilliseconds(delay_ms)); |
| 34 } |
| 35 |
| 36 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE { |
| 37 return main_thread_message_loop_.get(); |
| 38 } |
| 39 |
| 40 // ppapi::thunk::PPB_MessageLoop_API implementation. |
| 41 virtual int32_t AttachToCurrentThread() OVERRIDE { |
| 42 NOTIMPLEMENTED(); |
| 43 return PP_ERROR_FAILED; |
| 44 } |
| 45 |
| 46 virtual int32_t Run() OVERRIDE { |
| 47 NOTIMPLEMENTED(); |
| 48 return PP_ERROR_FAILED; |
| 49 } |
| 50 |
| 51 virtual int32_t PostWork(PP_CompletionCallback callback, |
| 52 int64_t delay_ms) OVERRIDE { |
| 53 NOTIMPLEMENTED(); |
| 54 return PP_ERROR_FAILED; |
| 55 } |
| 56 |
| 57 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE { |
| 58 NOTIMPLEMENTED(); |
| 59 return PP_ERROR_FAILED; |
| 60 } |
| 61 |
| 62 private: |
| 63 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_; |
| 64 DISALLOW_COPY_AND_ASSIGN(MainThreadMessageLoopResource); |
| 65 }; |
| 66 |
| 67 MojoPpapiGlobals::MojoPpapiGlobals(Delegate* delegate) |
| 68 : delegate_(delegate), |
| 69 plugin_instance_(NULL), |
| 70 resource_tracker_(ppapi::ResourceTracker::THREAD_SAFE) {} |
| 71 |
| 72 MojoPpapiGlobals::~MojoPpapiGlobals() {} |
| 73 |
| 74 PP_Instance MojoPpapiGlobals::AddInstance(PluginInstance* instance) { |
| 75 DCHECK(!plugin_instance_); |
| 76 plugin_instance_ = instance; |
| 77 resource_tracker_.DidCreateInstance(kInstanceId); |
| 78 return kInstanceId; |
| 79 } |
| 80 |
| 81 void MojoPpapiGlobals::InstanceDeleted(PP_Instance instance) { |
| 82 DCHECK_EQ(instance, kInstanceId); |
| 83 DCHECK(plugin_instance_); |
| 84 resource_tracker_.DidDeleteInstance(instance); |
| 85 plugin_instance_ = NULL; |
| 86 } |
| 87 |
| 88 PluginInstance* MojoPpapiGlobals::GetInstance(PP_Instance instance) { |
| 89 if (instance == kInstanceId) |
| 90 return plugin_instance_; |
| 91 |
| 92 return NULL; |
| 93 } |
| 94 |
| 95 ScopedMessagePipeHandle MojoPpapiGlobals::CreateGLES2Context() { |
| 96 return delegate_->CreateGLES2Context(); |
| 97 } |
| 98 |
| 99 ppapi::ResourceTracker* MojoPpapiGlobals::GetResourceTracker() { |
| 100 return &resource_tracker_; |
| 101 } |
| 102 |
| 103 ppapi::VarTracker* MojoPpapiGlobals::GetVarTracker() { |
| 104 NOTIMPLEMENTED(); |
| 105 return NULL; |
| 106 } |
| 107 |
| 108 ppapi::CallbackTracker* MojoPpapiGlobals::GetCallbackTrackerForInstance( |
| 109 PP_Instance instance) { |
| 110 if (instance == kInstanceId && plugin_instance_) |
| 111 return plugin_instance_->plugin_module()->callback_tracker(); |
| 112 return NULL; |
| 113 } |
| 114 |
| 115 void MojoPpapiGlobals::LogWithSource(PP_Instance instance, |
| 116 PP_LogLevel level, |
| 117 const std::string& source, |
| 118 const std::string& value) { |
| 119 NOTIMPLEMENTED(); |
| 120 } |
| 121 |
| 122 void MojoPpapiGlobals::BroadcastLogWithSource(PP_Module module, |
| 123 PP_LogLevel level, |
| 124 const std::string& source, |
| 125 const std::string& value) { |
| 126 NOTIMPLEMENTED(); |
| 127 } |
| 128 |
| 129 ppapi::thunk::PPB_Instance_API* MojoPpapiGlobals::GetInstanceAPI( |
| 130 PP_Instance instance) { |
| 131 if (instance == kInstanceId && plugin_instance_) |
| 132 return plugin_instance_; |
| 133 return NULL; |
| 134 } |
| 135 |
| 136 ppapi::thunk::ResourceCreationAPI* MojoPpapiGlobals::GetResourceCreationAPI( |
| 137 PP_Instance instance) { |
| 138 if (instance == kInstanceId && plugin_instance_) |
| 139 return plugin_instance_->resource_creation(); |
| 140 return NULL; |
| 141 } |
| 142 |
| 143 PP_Module MojoPpapiGlobals::GetModuleForInstance(PP_Instance instance) { |
| 144 NOTIMPLEMENTED(); |
| 145 return 0; |
| 146 } |
| 147 |
| 148 ppapi::MessageLoopShared* MojoPpapiGlobals::GetCurrentMessageLoop() { |
| 149 if (base::MessageLoopProxy::current().get() == GetMainThreadMessageLoop()) { |
| 150 if (!main_thread_message_loop_resource_) { |
| 151 main_thread_message_loop_resource_ = new MainThreadMessageLoopResource( |
| 152 GetMainThreadMessageLoop()); |
| 153 } |
| 154 return main_thread_message_loop_resource_.get(); |
| 155 } |
| 156 |
| 157 NOTIMPLEMENTED(); |
| 158 return NULL; |
| 159 } |
| 160 |
| 161 base::TaskRunner* MojoPpapiGlobals::GetFileTaskRunner() { |
| 162 NOTIMPLEMENTED(); |
| 163 return NULL; |
| 164 } |
| 165 |
| 166 std::string MojoPpapiGlobals::GetCmdLine() { |
| 167 NOTIMPLEMENTED(); |
| 168 return std::string(); |
| 169 } |
| 170 |
| 171 void MojoPpapiGlobals::PreCacheFontForFlash(const void* logfontw) { |
| 172 NOTIMPLEMENTED(); |
| 173 } |
| 174 |
| 175 } // namespace examples |
| 176 } // namespace mojo |
OLD | NEW |