Remove the RenderProcessHost observer and attach the WebContentsObserver earlier...
[chromium-blink-merge.git] / mojo / examples / pepper_container_app / mojo_ppapi_globals.cc
blobc9e7a2be2a33df1536e3755008aeefcde8dac0e8
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.
5 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/time.h"
11 #include "mojo/examples/pepper_container_app/plugin_instance.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/shared_impl/ppb_message_loop_shared.h"
15 namespace mojo {
16 namespace examples {
18 namespace {
20 const PP_Instance kInstanceId = 1;
22 } // namespace
24 // A non-abstract subclass of ppapi::MessageLoopShared that represents the
25 // message loop of the main thread.
26 // TODO(yzshen): Build a more general ppapi::MessageLoopShared subclass to fully
27 // support PPB_MessageLoop.
28 class MojoPpapiGlobals::MainThreadMessageLoopResource
29 : public ppapi::MessageLoopShared {
30 public:
31 explicit MainThreadMessageLoopResource(
32 base::MessageLoopProxy* main_thread_message_loop)
33 : MessageLoopShared(ForMainThread()),
34 main_thread_message_loop_(main_thread_message_loop) {}
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));
44 virtual base::MessageLoopProxy* GetMessageLoopProxy() override {
45 return main_thread_message_loop_.get();
48 virtual bool CurrentlyHandlingBlockingMessage() override {
49 return false;
52 // ppapi::thunk::PPB_MessageLoop_API implementation.
53 virtual int32_t AttachToCurrentThread() override {
54 NOTIMPLEMENTED();
55 return PP_ERROR_FAILED;
58 virtual int32_t Run() override {
59 NOTIMPLEMENTED();
60 return PP_ERROR_FAILED;
63 virtual int32_t PostWork(PP_CompletionCallback callback,
64 int64_t delay_ms) override {
65 NOTIMPLEMENTED();
66 return PP_ERROR_FAILED;
69 virtual int32_t PostQuit(PP_Bool should_destroy) override {
70 NOTIMPLEMENTED();
71 return PP_ERROR_FAILED;
74 private:
75 virtual ~MainThreadMessageLoopResource() {}
77 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_;
78 DISALLOW_COPY_AND_ASSIGN(MainThreadMessageLoopResource);
81 MojoPpapiGlobals::MojoPpapiGlobals(Delegate* delegate)
82 : delegate_(delegate),
83 plugin_instance_(NULL),
84 resource_tracker_(ppapi::ResourceTracker::THREAD_SAFE) {}
86 MojoPpapiGlobals::~MojoPpapiGlobals() {}
88 PP_Instance MojoPpapiGlobals::AddInstance(PluginInstance* instance) {
89 DCHECK(!plugin_instance_);
90 plugin_instance_ = instance;
91 resource_tracker_.DidCreateInstance(kInstanceId);
92 return kInstanceId;
95 void MojoPpapiGlobals::InstanceDeleted(PP_Instance instance) {
96 DCHECK_EQ(instance, kInstanceId);
97 DCHECK(plugin_instance_);
98 resource_tracker_.DidDeleteInstance(instance);
99 plugin_instance_ = NULL;
102 PluginInstance* MojoPpapiGlobals::GetInstance(PP_Instance instance) {
103 if (instance == kInstanceId)
104 return plugin_instance_;
105 return NULL;
108 ScopedMessagePipeHandle MojoPpapiGlobals::CreateGLES2Context() {
109 return delegate_->CreateGLES2Context();
112 ppapi::ResourceTracker* MojoPpapiGlobals::GetResourceTracker() {
113 return &resource_tracker_;
116 ppapi::VarTracker* MojoPpapiGlobals::GetVarTracker() {
117 NOTIMPLEMENTED();
118 return NULL;
121 ppapi::CallbackTracker* MojoPpapiGlobals::GetCallbackTrackerForInstance(
122 PP_Instance instance) {
123 if (instance == kInstanceId && plugin_instance_)
124 return plugin_instance_->plugin_module()->callback_tracker();
125 return NULL;
128 void MojoPpapiGlobals::LogWithSource(PP_Instance instance,
129 PP_LogLevel level,
130 const std::string& source,
131 const std::string& value) {
132 NOTIMPLEMENTED();
135 void MojoPpapiGlobals::BroadcastLogWithSource(PP_Module module,
136 PP_LogLevel level,
137 const std::string& source,
138 const std::string& value) {
139 NOTIMPLEMENTED();
142 ppapi::thunk::PPB_Instance_API* MojoPpapiGlobals::GetInstanceAPI(
143 PP_Instance instance) {
144 if (instance == kInstanceId && plugin_instance_)
145 return plugin_instance_;
146 return NULL;
149 ppapi::thunk::ResourceCreationAPI* MojoPpapiGlobals::GetResourceCreationAPI(
150 PP_Instance instance) {
151 if (instance == kInstanceId && plugin_instance_)
152 return plugin_instance_->resource_creation();
153 return NULL;
156 PP_Module MojoPpapiGlobals::GetModuleForInstance(PP_Instance instance) {
157 NOTIMPLEMENTED();
158 return 0;
161 ppapi::MessageLoopShared* MojoPpapiGlobals::GetCurrentMessageLoop() {
162 if (base::MessageLoopProxy::current().get() == GetMainThreadMessageLoop()) {
163 if (!main_thread_message_loop_resource_.get()) {
164 main_thread_message_loop_resource_ = new MainThreadMessageLoopResource(
165 GetMainThreadMessageLoop());
167 return main_thread_message_loop_resource_.get();
170 NOTIMPLEMENTED();
171 return NULL;
174 base::TaskRunner* MojoPpapiGlobals::GetFileTaskRunner() {
175 NOTIMPLEMENTED();
176 return NULL;
179 std::string MojoPpapiGlobals::GetCmdLine() {
180 NOTIMPLEMENTED();
181 return std::string();
184 void MojoPpapiGlobals::PreCacheFontForFlash(const void* logfontw) {
185 NOTIMPLEMENTED();
188 } // namespace examples
189 } // namespace mojo