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 namespace { |
| 18 |
| 19 const PP_Instance kInstanceId = 1; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 // A non-abstract subclass of ppapi::MessageLoopShared that represents the |
| 24 // message loop of the main thread. |
| 25 // TODO(yzshen): Build a more general ppapi::MessageLoopShared subclass to fully |
| 26 // support PPB_MessageLoop. |
| 27 class MojoPpapiGlobals::MainThreadMessageLoopResource |
| 28 : public ppapi::MessageLoopShared { |
| 29 public: |
| 30 explicit MainThreadMessageLoopResource( |
| 31 base::MessageLoopProxy* main_thread_message_loop) |
| 32 : MessageLoopShared(ForMainThread()), |
| 33 main_thread_message_loop_(main_thread_message_loop) {} |
| 34 virtual ~MainThreadMessageLoopResource() {} |
| 35 |
| 36 // ppapi::MessageLoopShared implementation. |
| 37 virtual void PostClosure(const tracked_objects::Location& from_here, |
| 38 const base::Closure& closure, |
| 39 int64 delay_ms) OVERRIDE { |
| 40 main_thread_message_loop_->PostDelayedTask( |
| 41 from_here, closure, base::TimeDelta::FromMilliseconds(delay_ms)); |
| 42 } |
| 43 |
| 44 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE { |
| 45 return main_thread_message_loop_.get(); |
| 46 } |
| 47 |
| 48 // ppapi::thunk::PPB_MessageLoop_API implementation. |
| 49 virtual int32_t AttachToCurrentThread() OVERRIDE { |
| 50 NOTIMPLEMENTED(); |
| 51 return PP_ERROR_FAILED; |
| 52 } |
| 53 |
| 54 virtual int32_t Run() OVERRIDE { |
| 55 NOTIMPLEMENTED(); |
| 56 return PP_ERROR_FAILED; |
| 57 } |
| 58 |
| 59 virtual int32_t PostWork(PP_CompletionCallback callback, |
| 60 int64_t delay_ms) OVERRIDE { |
| 61 NOTIMPLEMENTED(); |
| 62 return PP_ERROR_FAILED; |
| 63 } |
| 64 |
| 65 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE { |
| 66 NOTIMPLEMENTED(); |
| 67 return PP_ERROR_FAILED; |
| 68 } |
| 69 |
| 70 private: |
| 71 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_; |
| 72 DISALLOW_COPY_AND_ASSIGN(MainThreadMessageLoopResource); |
| 73 }; |
| 74 |
| 75 MojoPpapiGlobals::MojoPpapiGlobals(Delegate* delegate) |
| 76 : delegate_(delegate), |
| 77 plugin_instance_(NULL), |
| 78 resource_tracker_(ppapi::ResourceTracker::THREAD_SAFE) {} |
| 79 |
| 80 MojoPpapiGlobals::~MojoPpapiGlobals() {} |
| 81 |
| 82 PP_Instance MojoPpapiGlobals::AddInstance(PluginInstance* instance) { |
| 83 DCHECK(!plugin_instance_); |
| 84 plugin_instance_ = instance; |
| 85 resource_tracker_.DidCreateInstance(kInstanceId); |
| 86 return kInstanceId; |
| 87 } |
| 88 |
| 89 void MojoPpapiGlobals::InstanceDeleted(PP_Instance instance) { |
| 90 DCHECK_EQ(instance, kInstanceId); |
| 91 DCHECK(plugin_instance_); |
| 92 resource_tracker_.DidDeleteInstance(instance); |
| 93 plugin_instance_ = NULL; |
| 94 } |
| 95 |
| 96 PluginInstance* MojoPpapiGlobals::GetInstance(PP_Instance instance) { |
| 97 if (instance == kInstanceId) |
| 98 return plugin_instance_; |
| 99 return NULL; |
| 100 } |
| 101 |
| 102 ScopedMessagePipeHandle MojoPpapiGlobals::CreateGLES2Context() { |
| 103 return delegate_->CreateGLES2Context(); |
| 104 } |
| 105 |
| 106 ppapi::ResourceTracker* MojoPpapiGlobals::GetResourceTracker() { |
| 107 return &resource_tracker_; |
| 108 } |
| 109 |
| 110 ppapi::VarTracker* MojoPpapiGlobals::GetVarTracker() { |
| 111 NOTIMPLEMENTED(); |
| 112 return NULL; |
| 113 } |
| 114 |
| 115 ppapi::CallbackTracker* MojoPpapiGlobals::GetCallbackTrackerForInstance( |
| 116 PP_Instance instance) { |
| 117 if (instance == kInstanceId && plugin_instance_) |
| 118 return plugin_instance_->plugin_module()->callback_tracker(); |
| 119 return NULL; |
| 120 } |
| 121 |
| 122 void MojoPpapiGlobals::LogWithSource(PP_Instance instance, |
| 123 PP_LogLevel level, |
| 124 const std::string& source, |
| 125 const std::string& value) { |
| 126 NOTIMPLEMENTED(); |
| 127 } |
| 128 |
| 129 void MojoPpapiGlobals::BroadcastLogWithSource(PP_Module module, |
| 130 PP_LogLevel level, |
| 131 const std::string& source, |
| 132 const std::string& value) { |
| 133 NOTIMPLEMENTED(); |
| 134 } |
| 135 |
| 136 ppapi::thunk::PPB_Instance_API* MojoPpapiGlobals::GetInstanceAPI( |
| 137 PP_Instance instance) { |
| 138 if (instance == kInstanceId && plugin_instance_) |
| 139 return plugin_instance_; |
| 140 return NULL; |
| 141 } |
| 142 |
| 143 ppapi::thunk::ResourceCreationAPI* MojoPpapiGlobals::GetResourceCreationAPI( |
| 144 PP_Instance instance) { |
| 145 if (instance == kInstanceId && plugin_instance_) |
| 146 return plugin_instance_->resource_creation(); |
| 147 return NULL; |
| 148 } |
| 149 |
| 150 PP_Module MojoPpapiGlobals::GetModuleForInstance(PP_Instance instance) { |
| 151 NOTIMPLEMENTED(); |
| 152 return 0; |
| 153 } |
| 154 |
| 155 ppapi::MessageLoopShared* MojoPpapiGlobals::GetCurrentMessageLoop() { |
| 156 if (base::MessageLoopProxy::current().get() == GetMainThreadMessageLoop()) { |
| 157 if (!main_thread_message_loop_resource_) { |
| 158 main_thread_message_loop_resource_ = new MainThreadMessageLoopResource( |
| 159 GetMainThreadMessageLoop()); |
| 160 } |
| 161 return main_thread_message_loop_resource_.get(); |
| 162 } |
| 163 |
| 164 NOTIMPLEMENTED(); |
| 165 return NULL; |
| 166 } |
| 167 |
| 168 base::TaskRunner* MojoPpapiGlobals::GetFileTaskRunner() { |
| 169 NOTIMPLEMENTED(); |
| 170 return NULL; |
| 171 } |
| 172 |
| 173 std::string MojoPpapiGlobals::GetCmdLine() { |
| 174 NOTIMPLEMENTED(); |
| 175 return std::string(); |
| 176 } |
| 177 |
| 178 void MojoPpapiGlobals::PreCacheFontForFlash(const void* logfontw) { |
| 179 NOTIMPLEMENTED(); |
| 180 } |
| 181 |
| 182 } // namespace examples |
| 183 } // namespace mojo |
OLD | NEW |