Introduce new SPDY Version UMA histogram.
[chromium-blink-merge.git] / mojo / examples / pepper_container_app / mojo_ppapi_globals.cc
blobaaf9b0a7ba1ca5083422777827126d6dc1f7592b
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/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"
14 namespace mojo {
15 namespace examples {
17 namespace {
19 const PP_Instance kInstanceId = 1;
21 } // namespace
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) {}
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));
43 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE {
44 return main_thread_message_loop_.get();
47 // ppapi::thunk::PPB_MessageLoop_API implementation.
48 virtual int32_t AttachToCurrentThread() OVERRIDE {
49 NOTIMPLEMENTED();
50 return PP_ERROR_FAILED;
53 virtual int32_t Run() OVERRIDE {
54 NOTIMPLEMENTED();
55 return PP_ERROR_FAILED;
58 virtual int32_t PostWork(PP_CompletionCallback callback,
59 int64_t delay_ms) OVERRIDE {
60 NOTIMPLEMENTED();
61 return PP_ERROR_FAILED;
64 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE {
65 NOTIMPLEMENTED();
66 return PP_ERROR_FAILED;
69 private:
70 virtual ~MainThreadMessageLoopResource() {}
72 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_;
73 DISALLOW_COPY_AND_ASSIGN(MainThreadMessageLoopResource);
76 MojoPpapiGlobals::MojoPpapiGlobals(Delegate* delegate)
77 : delegate_(delegate),
78 plugin_instance_(NULL),
79 resource_tracker_(ppapi::ResourceTracker::THREAD_SAFE) {}
81 MojoPpapiGlobals::~MojoPpapiGlobals() {}
83 PP_Instance MojoPpapiGlobals::AddInstance(PluginInstance* instance) {
84 DCHECK(!plugin_instance_);
85 plugin_instance_ = instance;
86 resource_tracker_.DidCreateInstance(kInstanceId);
87 return kInstanceId;
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;
97 PluginInstance* MojoPpapiGlobals::GetInstance(PP_Instance instance) {
98 if (instance == kInstanceId)
99 return plugin_instance_;
100 return NULL;
103 ScopedMessagePipeHandle MojoPpapiGlobals::CreateGLES2Context() {
104 return delegate_->CreateGLES2Context();
107 ppapi::ResourceTracker* MojoPpapiGlobals::GetResourceTracker() {
108 return &resource_tracker_;
111 ppapi::VarTracker* MojoPpapiGlobals::GetVarTracker() {
112 NOTIMPLEMENTED();
113 return NULL;
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;
123 void MojoPpapiGlobals::LogWithSource(PP_Instance instance,
124 PP_LogLevel level,
125 const std::string& source,
126 const std::string& value) {
127 NOTIMPLEMENTED();
130 void MojoPpapiGlobals::BroadcastLogWithSource(PP_Module module,
131 PP_LogLevel level,
132 const std::string& source,
133 const std::string& value) {
134 NOTIMPLEMENTED();
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;
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;
151 PP_Module MojoPpapiGlobals::GetModuleForInstance(PP_Instance instance) {
152 NOTIMPLEMENTED();
153 return 0;
156 ppapi::MessageLoopShared* MojoPpapiGlobals::GetCurrentMessageLoop() {
157 if (base::MessageLoopProxy::current().get() == GetMainThreadMessageLoop()) {
158 if (!main_thread_message_loop_resource_.get()) {
159 main_thread_message_loop_resource_ = new MainThreadMessageLoopResource(
160 GetMainThreadMessageLoop());
162 return main_thread_message_loop_resource_.get();
165 NOTIMPLEMENTED();
166 return NULL;
169 base::TaskRunner* MojoPpapiGlobals::GetFileTaskRunner() {
170 NOTIMPLEMENTED();
171 return NULL;
174 std::string MojoPpapiGlobals::GetCmdLine() {
175 NOTIMPLEMENTED();
176 return std::string();
179 void MojoPpapiGlobals::PreCacheFontForFlash(const void* logfontw) {
180 NOTIMPLEMENTED();
183 } // namespace examples
184 } // namespace mojo