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

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