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