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

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: Updated TestURLLoader to test blocking callbacks. Created 8 years, 8 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 // Maintains all currently loaded plugin libs for validating PP_Module 149 // Maintains all currently loaded plugin libs for validating PP_Module
150 // identifiers. 150 // identifiers.
151 typedef std::set<PluginModule*> PluginModuleSet; 151 typedef std::set<PluginModule*> PluginModuleSet;
152 152
153 PluginModuleSet* GetLivePluginSet() { 153 PluginModuleSet* GetLivePluginSet() {
154 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ()); 154 CR_DEFINE_STATIC_LOCAL(PluginModuleSet, live_plugin_libs, ());
155 return &live_plugin_libs; 155 return &live_plugin_libs;
156 } 156 }
157 157
158 base::MessageLoopProxy* GetMainThreadMessageLoop() {
159 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy,
160 (base::MessageLoopProxy::current()));
161 return proxy.get();
162 }
163
164 // PPB_Core -------------------------------------------------------------------- 158 // PPB_Core --------------------------------------------------------------------
165 159
166 void AddRefResource(PP_Resource resource) { 160 void AddRefResource(PP_Resource resource) {
167 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource); 161 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource);
168 } 162 }
169 163
170 void ReleaseResource(PP_Resource resource) { 164 void ReleaseResource(PP_Resource resource) {
171 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource); 165 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resource);
172 } 166 }
173 167
174 PP_Time GetTime() { 168 PP_Time GetTime() {
175 return TimeToPPTime(base::Time::Now()); 169 return TimeToPPTime(base::Time::Now());
176 } 170 }
177 171
178 PP_TimeTicks GetTickTime() { 172 PP_TimeTicks GetTickTime() {
179 return TimeTicksToPPTimeTicks(base::TimeTicks::Now()); 173 return TimeTicksToPPTimeTicks(base::TimeTicks::Now());
180 } 174 }
181 175
182 void CallOnMainThread(int delay_in_msec, 176 void CallOnMainThread(int delay_in_msec,
183 PP_CompletionCallback callback, 177 PP_CompletionCallback callback,
184 int32_t result) { 178 int32_t result) {
185 if (callback.func) { 179 if (callback.func) {
186 GetMainThreadMessageLoop()->PostDelayedTask( 180 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
187 FROM_HERE, 181 FROM_HERE,
188 base::Bind(callback.func, callback.user_data, result), 182 base::Bind(callback.func, callback.user_data, result),
189 base::TimeDelta::FromMilliseconds(delay_in_msec)); 183 base::TimeDelta::FromMilliseconds(delay_in_msec));
190 } 184 }
191 } 185 }
192 186
193 PP_Bool IsMainThread() { 187 PP_Bool IsMainThread() {
194 return BoolToPPBool(GetMainThreadMessageLoop()->BelongsToCurrentThread()); 188 return BoolToPPBool(PpapiGlobals::Get()->
189 GetMainThreadMessageLoop()->BelongsToCurrentThread());
195 } 190 }
196 191
197 const PPB_Core core_interface = { 192 const PPB_Core core_interface = {
198 &AddRefResource, 193 &AddRefResource,
199 &ReleaseResource, 194 &ReleaseResource,
200 &GetTime, 195 &GetTime,
201 &GetTickTime, 196 &GetTickTime,
202 &CallOnMainThread, 197 &CallOnMainThread,
203 &IsMainThread 198 &IsMainThread
204 }; 199 };
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 library_(NULL), 436 library_(NULL),
442 name_(name), 437 name_(name),
443 path_(path), 438 path_(path),
444 reserve_instance_id_(NULL) { 439 reserve_instance_id_(NULL) {
445 // Ensure the globals object is created. 440 // Ensure the globals object is created.
446 if (!host_globals) 441 if (!host_globals)
447 host_globals = new HostGlobals; 442 host_globals = new HostGlobals;
448 443
449 memset(&entry_points_, 0, sizeof(entry_points_)); 444 memset(&entry_points_, 0, sizeof(entry_points_));
450 pp_module_ = HostGlobals::Get()->AddModule(this); 445 pp_module_ = HostGlobals::Get()->AddModule(this);
451 GetMainThreadMessageLoop(); // Initialize the main thread message loop. 446 // Initialize the main thread message loop.
447 PpapiGlobals::Get()->GetMainThreadMessageLoop();
452 GetLivePluginSet()->insert(this); 448 GetLivePluginSet()->insert(this);
453 } 449 }
454 450
455 PluginModule::~PluginModule() { 451 PluginModule::~PluginModule() {
456 // In the past there have been crashes reentering the plugin module 452 // In the past there have been crashes reentering the plugin module
457 // destructor. Catch if that happens again earlier. 453 // destructor. Catch if that happens again earlier.
458 CHECK(!is_in_destructor_); 454 CHECK(!is_in_destructor_);
459 is_in_destructor_ = true; 455 is_in_destructor_ = true;
460 456
461 // When the module is being deleted, there should be no more instances still 457 // 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
616 int retval = entry_points.initialize_module(pp_module(), &GetInterface); 612 int retval = entry_points.initialize_module(pp_module(), &GetInterface);
617 if (retval != 0) { 613 if (retval != 0) {
618 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; 614 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval;
619 return false; 615 return false;
620 } 616 }
621 return true; 617 return true;
622 } 618 }
623 619
624 } // namespace ppapi 620 } // namespace ppapi
625 } // namespace webkit 621 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698