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

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: lockless approach 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
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 approximately once per plugin. If the atomic
348 if (!found->second.interface_logged) { 352 // sequence number rolls over, we might log again, but that's OK.
353 if (found->second->interface_request_count_.GetNext() == 0) {
349 PluginGlobals::Get()->GetBrowserSender()->Send( 354 PluginGlobals::Get()->GetBrowserSender()->Send(
350 new PpapiHostMsg_LogInterfaceUsage(HashInterfaceName(name))); 355 new PpapiHostMsg_LogInterfaceUsage(HashInterfaceName(name)));
dmichael (off chromium) 2014/09/12 18:12:07 note that previously, even with the "interface_log
351 found->second.interface_logged = true;
352 } 356 }
353 return found->second.iface; 357 return found->second->iface;
354 } 358 }
355 return NULL; 359 return NULL;
356 } 360 }
357 361
358 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { 362 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const {
359 NameToInterfaceInfoMap::const_iterator found = 363 NameToInterfaceInfoMap::const_iterator found =
360 name_to_plugin_info_.find(name); 364 name_to_plugin_info_.find(name);
361 if (found == name_to_plugin_info_.end()) 365 if (found == name_to_plugin_info_.end())
362 return NULL; 366 return NULL;
363 return found->second.iface; 367 return found->second->iface;
364 } 368 }
365 369
366 void InterfaceList::AddProxy(ApiID id, 370 void InterfaceList::AddProxy(ApiID id,
367 InterfaceProxy::Factory factory) { 371 InterfaceProxy::Factory factory) {
368 // For interfaces with no corresponding _Proxy objects, the macros will 372 // For interfaces with no corresponding _Proxy objects, the macros will
369 // generate calls to this function with API_ID_NONE. This means we 373 // generate calls to this function with API_ID_NONE. This means we
370 // should just skip adding a factory for these functions. 374 // should just skip adding a factory for these functions.
371 if (id == API_ID_NONE) 375 if (id == API_ID_NONE)
372 return; 376 return;
373 377
374 // The factory should be an exact dupe of the one we already have if it 378 // The factory should be an exact dupe of the one we already have if it
375 // has already been registered before. 379 // has already been registered before.
376 int index = static_cast<int>(id); 380 int index = static_cast<int>(id);
377 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); 381 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory);
378 382
379 id_to_factory_[index] = factory; 383 id_to_factory_[index] = factory;
380 } 384 }
381 385
382 void InterfaceList::AddPPB(const char* name, 386 void InterfaceList::AddPPB(const char* name,
383 const void* iface, 387 const void* iface,
384 Permission perm) { 388 Permission perm) {
385 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); 389 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end());
386 name_to_browser_info_[name] = InterfaceInfo(iface, perm); 390 name_to_browser_info_.add(
391 name, scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, perm)));
387 } 392 }
388 393
389 void InterfaceList::AddPPP(const char* name, 394 void InterfaceList::AddPPP(const char* name,
390 const void* iface) { 395 const void* iface) {
391 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); 396 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end());
392 name_to_plugin_info_[name] = InterfaceInfo(iface, PERMISSION_NONE); 397 name_to_plugin_info_.add(
398 name,
399 scoped_ptr<InterfaceInfo>(new InterfaceInfo(iface, PERMISSION_NONE)));
393 } 400 }
394 401
395 // static
396 int InterfaceList::HashInterfaceName(const std::string& name) { 402 int InterfaceList::HashInterfaceName(const std::string& name) {
397 uint32 data = base::Hash(name.c_str(), name.size()); 403 uint32 data = base::Hash(name.c_str(), name.size());
398 // Strip off the signed bit because UMA doesn't support negative values, 404 // Strip off the signed bit because UMA doesn't support negative values,
399 // but takes a signed int as input. 405 // but takes a signed int as input.
400 return static_cast<int>(data & 0x7fffffff); 406 return static_cast<int>(data & 0x7fffffff);
401 } 407 }
402 408
403 } // namespace proxy 409 } // namespace proxy
404 } // namespace ppapi 410 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698