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

Side by Side Diff: ppapi/proxy/interface_list.cc

Issue 566243004: Revert of PPAPI: Fix GetBrowserInterface race conditions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « ppapi/proxy/interface_list.h ('k') | ppapi/proxy/plugin_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/proxy/interface_list.h" 5 #include "ppapi/proxy/interface_list.h"
6 6
7 #include "base/hash.h" 7 #include "base/hash.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "ppapi/c/dev/ppb_audio_input_dev.h" 10 #include "ppapi/c/dev/ppb_audio_input_dev.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 AddPPP(PPP_VIDEODECODER_DEV_INTERFACE, 312 AddPPP(PPP_VIDEODECODER_DEV_INTERFACE,
313 PPP_VideoDecoder_Proxy::GetProxyInterface()); 313 PPP_VideoDecoder_Proxy::GetProxyInterface());
314 #endif 314 #endif
315 } 315 }
316 316
317 InterfaceList::~InterfaceList() { 317 InterfaceList::~InterfaceList() {
318 } 318 }
319 319
320 // static 320 // static
321 InterfaceList* InterfaceList::GetInstance() { 321 InterfaceList* InterfaceList::GetInstance() {
322 // CAUTION: This function is called without the ProxyLock to avoid excessive
323 // excessive locking from C++ wrappers. (See also GetBrowserInterface.)
324 return Singleton<InterfaceList>::get(); 322 return Singleton<InterfaceList>::get();
325 } 323 }
326 324
327 // static 325 // static
328 void InterfaceList::SetProcessGlobalPermissions( 326 void InterfaceList::SetProcessGlobalPermissions(
329 const PpapiPermissions& permissions) { 327 const PpapiPermissions& permissions) {
330 g_process_global_permissions.Get() = permissions; 328 g_process_global_permissions.Get() = permissions;
331 } 329 }
332 330
333 InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const { 331 InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const {
334 int index = static_cast<int>(id); 332 int index = static_cast<int>(id);
335 COMPILE_ASSERT(API_ID_NONE == 0, none_must_be_zero); 333 COMPILE_ASSERT(API_ID_NONE == 0, none_must_be_zero);
336 if (id <= 0 || id >= API_ID_COUNT) 334 if (id <= 0 || id >= API_ID_COUNT)
337 return NULL; 335 return NULL;
338 return id_to_factory_[index]; 336 return id_to_factory_[index];
339 } 337 }
340 338
341 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) { 339 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) {
342 // CAUTION: This function is called without the ProxyLock to avoid excessive
343 // excessive locking from C++ wrappers. (See also GetBrowserInterface.)
344 NameToInterfaceInfoMap::iterator found = 340 NameToInterfaceInfoMap::iterator found =
345 name_to_browser_info_.find(name); 341 name_to_browser_info_.find(name);
346 if (found == name_to_browser_info_.end()) 342 if (found == name_to_browser_info_.end())
347 return NULL; 343 return NULL;
348 344
349 if (g_process_global_permissions.Get().HasPermission( 345 if (g_process_global_permissions.Get().HasPermission(
350 found->second->required_permission())) { 346 found->second.required_permission)) {
351 // Only log interface use once per plugin. 347 // Only log interface use once per plugin.
352 found->second->LogWithUmaOnce( 348 if (!found->second.interface_logged) {
353 PluginGlobals::Get()->GetBrowserSender(), name); 349 PluginGlobals::Get()->GetBrowserSender()->Send(
354 return found->second->iface(); 350 new PpapiHostMsg_LogInterfaceUsage(HashInterfaceName(name)));
351 found->second.interface_logged = true;
352 }
353 return found->second.iface;
355 } 354 }
356 return NULL; 355 return NULL;
357 } 356 }
358 357
359 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { 358 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const {
360 NameToInterfaceInfoMap::const_iterator found = 359 NameToInterfaceInfoMap::const_iterator found =
361 name_to_plugin_info_.find(name); 360 name_to_plugin_info_.find(name);
362 if (found == name_to_plugin_info_.end()) 361 if (found == name_to_plugin_info_.end())
363 return NULL; 362 return NULL;
364 return found->second->iface(); 363 return found->second.iface;
365 }
366
367 void InterfaceList::InterfaceInfo::LogWithUmaOnce(
368 IPC::Sender* sender, const std::string& name) {
369 {
370 base::AutoLock acquire(sent_to_uma_lock_);
371 if (sent_to_uma_)
372 return;
373 sent_to_uma_ = true;
374 }
375 int hash = InterfaceList::HashInterfaceName(name);
376 PluginGlobals::Get()->GetBrowserSender()->Send(
377 new PpapiHostMsg_LogInterfaceUsage(hash));
378 } 364 }
379 365
380 void InterfaceList::AddProxy(ApiID id, 366 void InterfaceList::AddProxy(ApiID id,
381 InterfaceProxy::Factory factory) { 367 InterfaceProxy::Factory factory) {
382 // For interfaces with no corresponding _Proxy objects, the macros will 368 // For interfaces with no corresponding _Proxy objects, the macros will
383 // generate calls to this function with API_ID_NONE. This means we 369 // generate calls to this function with API_ID_NONE. This means we
384 // should just skip adding a factory for these functions. 370 // should just skip adding a factory for these functions.
385 if (id == API_ID_NONE) 371 if (id == API_ID_NONE)
386 return; 372 return;
387 373
388 // The factory should be an exact dupe of the one we already have if it 374 // The factory should be an exact dupe of the one we already have if it
389 // has already been registered before. 375 // has already been registered before.
390 int index = static_cast<int>(id); 376 int index = static_cast<int>(id);
391 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); 377 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory);
392 378
393 id_to_factory_[index] = factory; 379 id_to_factory_[index] = factory;
394 } 380 }
395 381
396 void InterfaceList::AddPPB(const char* name, 382 void InterfaceList::AddPPB(const char* name,
397 const void* iface, 383 const void* iface,
398 Permission perm) { 384 Permission perm) {
399 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); 385 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end());
400 name_to_browser_info_.add( 386 name_to_browser_info_[name] = InterfaceInfo(iface, perm);
401 name, scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, perm)));
402 } 387 }
403 388
404 void InterfaceList::AddPPP(const char* name, 389 void InterfaceList::AddPPP(const char* name,
405 const void* iface) { 390 const void* iface) {
406 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); 391 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end());
407 name_to_plugin_info_.add( 392 name_to_plugin_info_[name] = InterfaceInfo(iface, PERMISSION_NONE);
408 name,
409 scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, PERMISSION_NONE)));
410 } 393 }
411 394
395 // static
412 int InterfaceList::HashInterfaceName(const std::string& name) { 396 int InterfaceList::HashInterfaceName(const std::string& name) {
413 uint32 data = base::Hash(name.c_str(), name.size()); 397 uint32 data = base::Hash(name.c_str(), name.size());
414 // Strip off the signed bit because UMA doesn't support negative values, 398 // Strip off the signed bit because UMA doesn't support negative values,
415 // but takes a signed int as input. 399 // but takes a signed int as input.
416 return static_cast<int>(data & 0x7fffffff); 400 return static_cast<int>(data & 0x7fffffff);
417 } 401 }
418 402
419 } // namespace proxy 403 } // namespace proxy
420 } // namespace ppapi 404 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/interface_list.h ('k') | ppapi/proxy/plugin_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698