Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: webkit/plugins/ppapi/plugin_module.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try again Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/plugin_module.h" 5 #include "webkit/plugins/ppapi/plugin_module.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 // Maintains all currently loaded plugin libs for validating PP_Module 147 // Maintains all currently loaded plugin libs for validating PP_Module
148 // identifiers. 148 // identifiers.
149 typedef std::set<PluginModule*> PluginModuleSet; 149 typedef std::set<PluginModule*> PluginModuleSet;
150 150
151 PluginModuleSet* GetLivePluginSet() { 151 PluginModuleSet* GetLivePluginSet() {
152 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); 152 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ());
153 return &live_plugin_libs; 153 return &live_plugin_libs;
154 } 154 }
155 155
156 base::MessageLoopProxy* GetMainThreadMessageLoop() {
157 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy,
158 (base::MessageLoopProxy::current()));
159 return proxy.get();
160 }
161
162 // PPB_Core -------------------------------------------------------------------- 156 // PPB_Core --------------------------------------------------------------------
163 157
164 void AddRefResource(PP_Resource resource) { 158 void AddRefResource(PP_Resource resource) {
165 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); 159 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource);
166 } 160 }
167 161
168 void ReleaseResource(PP_Resource resource) { 162 void ReleaseResource(PP_Resource resource) {
169 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); 163 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource);
170 } 164 }
171 165
172 PP_Time GetTime() { 166 PP_Time GetTime() {
173 return TimeToPPTime(base::Time::Now()); 167 return TimeToPPTime(base::Time::Now());
174 } 168 }
175 169
176 PP_TimeTicks GetTickTime() { 170 PP_TimeTicks GetTickTime() {
177 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); 171 return TimeTicksToPPTimeTicks(base::TimeTicks::Now());
178 } 172 }
179 173
180 void CallOnMainThread(int delay_in_msec, 174 void CallOnMainThread(int delay_in_msec,
181 PP_CompletionCallback callback, 175 PP_CompletionCallback callback,
182 int32_t result) { 176 int32_t result) {
183 if (callback.func) { 177 if (callback.func) {
184 GetMainThreadMessageLoop()->PostDelayedTask( 178 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
185 FROM_HERE, 179 FROM_HERE,
186 base::Bind(callback.func, callback.user_data, result), 180 base::Bind(callback.func, callback.user_data, result),
187 base::TimeDelta::FromMilliseconds(delay_in_msec)); 181 base::TimeDelta::FromMilliseconds(delay_in_msec));
188 } 182 }
189 } 183 }
190 184
191 PP_Bool IsMainThread() { 185 PP_Bool IsMainThread() {
192 return BoolToPPBool(GetMainThreadMessageLoop()->BelongsToCurrentThread()); 186 return BoolToPPBool(PpapiGlobals::Get()->
187 GetMainThreadMessageLoop()->BelongsToCurrentThread());
193 } 188 }
194 189
195 const PPB_Core core_interface = { 190 const PPB_Core core_interface = {
196 &AddRefResource, 191 &AddRefResource,
197 &ReleaseResource, 192 &ReleaseResource,
198 &GetTime, 193 &GetTime,
199 &GetTickTime, 194 &GetTickTime,
200 &CallOnMainThread, 195 &CallOnMainThread,
201 &IsMainThread 196 &IsMainThread
202 }; 197 };
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 library_(NULL), 413 library_(NULL),
419 name_(name), 414 name_(name),
420 path_(path), 415 path_(path),
421 reserve_instance_id_(NULL) { 416 reserve_instance_id_(NULL) {
422 // Ensure the globals object is created. 417 // Ensure the globals object is created.
423 if (!host_globals) 418 if (!host_globals)
424 host_globals = new HostGlobals; 419 host_globals = new HostGlobals;
425 420
426 memset(&entry_points_, 0, sizeof(entry_points_)); 421 memset(&entry_points_, 0, sizeof(entry_points_));
427 pp_module_ = HostGlobals::Get()->AddModule(this); 422 pp_module_ = HostGlobals::Get()->AddModule(this);
428 GetMainThreadMessageLoop(); // Initialize the main thread message loop. 423 // Initialize the main thread message loop.
424 PpapiGlobals::Get()->GetMainThreadMessageLoop();
429 GetLivePluginSet()->insert(this); 425 GetLivePluginSet()->insert(this);
430 } 426 }
431 427
432 PluginModule::~PluginModule() { 428 PluginModule::~PluginModule() {
433 // In the past there have been crashes reentering the plugin module 429 // In the past there have been crashes reentering the plugin module
434 // destructor. Catch if that happens again earlier. 430 // destructor. Catch if that happens again earlier.
435 CHECK(!is_in_destructor_); 431 CHECK(!is_in_destructor_);
436 is_in_destructor_ = true; 432 is_in_destructor_ = true;
437 433
438 // When the module is being deleted, there should be no more instances still 434 // When the module is being deleted, there should be no more instances still
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 int retval = entry_points.initialize_module(pp_module(), &GetInterface); 589 int retval = entry_points.initialize_module(pp_module(), &GetInterface);
594 if (retval != 0) { 590 if (retval != 0) {
595 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; 591 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval;
596 return false; 592 return false;
597 } 593 }
598 return true; 594 return true;
599 } 595 }
600 596
601 } // namespace ppapi 597 } // namespace ppapi
602 } // namespace webkit 598 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698