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

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

Issue 568793002: PPAPI: Fix GetBrowserInterface race conditions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix misspelling 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.)
322 return Singleton<InterfaceList>::get(); 324 return Singleton<InterfaceList>::get();
323 } 325 }
324 326
325 // static 327 // static
326 void InterfaceList::SetProcessGlobalPermissions( 328 void InterfaceList::SetProcessGlobalPermissions(
327 const PpapiPermissions& permissions) { 329 const PpapiPermissions& permissions) {
328 g_process_global_permissions.Get() = permissions; 330 g_process_global_permissions.Get() = permissions;
329 } 331 }
330 332
331 InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const { 333 InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const {
332 int index = static_cast<int>(id); 334 int index = static_cast<int>(id);
333 COMPILE_ASSERT(API_ID_NONE == 0, none_must_be_zero); 335 COMPILE_ASSERT(API_ID_NONE == 0, none_must_be_zero);
334 if (id <= 0 || id >= API_ID_COUNT) 336 if (id <= 0 || id >= API_ID_COUNT)
335 return NULL; 337 return NULL;
336 return id_to_factory_[index]; 338 return id_to_factory_[index];
337 } 339 }
338 340
339 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) { 341 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.)
340 NameToInterfaceInfoMap::iterator found = 344 NameToInterfaceInfoMap::iterator found =
341 name_to_browser_info_.find(name); 345 name_to_browser_info_.find(name);
342 if (found == name_to_browser_info_.end()) 346 if (found == name_to_browser_info_.end())
343 return NULL; 347 return NULL;
344 348
345 if (g_process_global_permissions.Get().HasPermission( 349 if (g_process_global_permissions.Get().HasPermission(
346 found->second.required_permission)) { 350 found->second->required_permission())) {
347 // Only log interface use once per plugin. 351 // Only log interface use once per plugin.
348 if (!found->second.interface_logged) { 352 found->second->LogWithUmaOnce(
349 PluginGlobals::Get()->GetBrowserSender()->Send( 353 PluginGlobals::Get()->GetBrowserSender(), name);
350 new PpapiHostMsg_LogInterfaceUsage(HashInterfaceName(name))); 354 return found->second->iface();
351 found->second.interface_logged = true;
352 }
353 return found->second.iface;
354 } 355 }
355 return NULL; 356 return NULL;
356 } 357 }
357 358
358 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { 359 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const {
359 NameToInterfaceInfoMap::const_iterator found = 360 NameToInterfaceInfoMap::const_iterator found =
360 name_to_plugin_info_.find(name); 361 name_to_plugin_info_.find(name);
361 if (found == name_to_plugin_info_.end()) 362 if (found == name_to_plugin_info_.end())
362 return NULL; 363 return NULL;
363 return found->second.iface; 364 return found->second->iface();
365 }
366
367 void InterfaceList::InterfaceInfo::LogWithUmaOnce(
368 IPC::Sender* sender, const std::string& name) {
369 base::AutoLock acquire(sent_to_uma_lock_);
370 if (!sent_to_uma_) {
teravest 2014/09/12 21:00:17 nit: I believe you could reduce the critical secti
dmichael (off chromium) 2014/09/12 22:21:19 Good point. Probably has no practical performance
371 int hash = InterfaceList::HashInterfaceName(name);
372 PluginGlobals::Get()->GetBrowserSender()->Send(
373 new PpapiHostMsg_LogInterfaceUsage(hash));
374 sent_to_uma_ = true;
375 }
364 } 376 }
365 377
366 void InterfaceList::AddProxy(ApiID id, 378 void InterfaceList::AddProxy(ApiID id,
367 InterfaceProxy::Factory factory) { 379 InterfaceProxy::Factory factory) {
368 // For interfaces with no corresponding _Proxy objects, the macros will 380 // For interfaces with no corresponding _Proxy objects, the macros will
369 // generate calls to this function with API_ID_NONE. This means we 381 // generate calls to this function with API_ID_NONE. This means we
370 // should just skip adding a factory for these functions. 382 // should just skip adding a factory for these functions.
371 if (id == API_ID_NONE) 383 if (id == API_ID_NONE)
372 return; 384 return;
373 385
374 // The factory should be an exact dupe of the one we already have if it 386 // The factory should be an exact dupe of the one we already have if it
375 // has already been registered before. 387 // has already been registered before.
376 int index = static_cast<int>(id); 388 int index = static_cast<int>(id);
377 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); 389 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory);
378 390
379 id_to_factory_[index] = factory; 391 id_to_factory_[index] = factory;
380 } 392 }
381 393
382 void InterfaceList::AddPPB(const char* name, 394 void InterfaceList::AddPPB(const char* name,
383 const void* iface, 395 const void* iface,
384 Permission perm) { 396 Permission perm) {
385 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); 397 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end());
386 name_to_browser_info_[name] = InterfaceInfo(iface, perm); 398 name_to_browser_info_.add(
399 name, scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, perm)));
387 } 400 }
388 401
389 void InterfaceList::AddPPP(const char* name, 402 void InterfaceList::AddPPP(const char* name,
390 const void* iface) { 403 const void* iface) {
391 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); 404 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end());
392 name_to_plugin_info_[name] = InterfaceInfo(iface, PERMISSION_NONE); 405 name_to_plugin_info_.add(
406 name,
407 scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, PERMISSION_NONE)));
393 } 408 }
394 409
395 // static
396 int InterfaceList::HashInterfaceName(const std::string& name) { 410 int InterfaceList::HashInterfaceName(const std::string& name) {
397 uint32 data = base::Hash(name.c_str(), name.size()); 411 uint32 data = base::Hash(name.c_str(), name.size());
398 // Strip off the signed bit because UMA doesn't support negative values, 412 // Strip off the signed bit because UMA doesn't support negative values,
399 // but takes a signed int as input. 413 // but takes a signed int as input.
400 return static_cast<int>(data & 0x7fffffff); 414 return static_cast<int>(data & 0x7fffffff);
401 } 415 }
402 416
403 } // namespace proxy 417 } // namespace proxy
404 } // namespace ppapi 418 } // 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