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

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

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/nacl_irt/plugin_main.cc ('k') | ppapi/proxy/interface_list.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 #ifndef PPAPI_PROXY_INTERFACE_LIST_H_ 5 #ifndef PPAPI_PROXY_INTERFACE_LIST_H_
6 #define PPAPI_PROXY_INTERFACE_LIST_H_ 6 #define PPAPI_PROXY_INTERFACE_LIST_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/synchronization/lock.h"
12 #include "ppapi/proxy/interface_proxy.h" 14 #include "ppapi/proxy/interface_proxy.h"
13 #include "ppapi/proxy/ppapi_proxy_export.h" 15 #include "ppapi/proxy/ppapi_proxy_export.h"
14 #include "ppapi/shared_impl/ppapi_permissions.h" 16 #include "ppapi/shared_impl/ppapi_permissions.h"
15 17
16 namespace ppapi { 18 namespace ppapi {
17 namespace proxy { 19 namespace proxy {
18 20
19 class PPAPI_PROXY_EXPORT InterfaceList { 21 class PPAPI_PROXY_EXPORT InterfaceList {
20 public: 22 public:
21 InterfaceList(); 23 InterfaceList();
(...skipping 18 matching lines...) Expand all
40 InterfaceProxy::Factory GetFactoryForID(ApiID id) const; 42 InterfaceProxy::Factory GetFactoryForID(ApiID id) const;
41 43
42 // Returns the interface pointer for the given browser or plugin interface, 44 // Returns the interface pointer for the given browser or plugin interface,
43 // or NULL if it's not supported. 45 // or NULL if it's not supported.
44 const void* GetInterfaceForPPB(const std::string& name); 46 const void* GetInterfaceForPPB(const std::string& name);
45 const void* GetInterfaceForPPP(const std::string& name) const; 47 const void* GetInterfaceForPPP(const std::string& name) const;
46 48
47 private: 49 private:
48 friend class InterfaceListTest; 50 friend class InterfaceListTest;
49 51
50 struct InterfaceInfo { 52 class InterfaceInfo {
51 InterfaceInfo() 53 public:
52 : iface(NULL),
53 required_permission(PERMISSION_NONE),
54 interface_logged(false) {
55 }
56 InterfaceInfo(const void* in_interface, Permission in_perm) 54 InterfaceInfo(const void* in_interface, Permission in_perm)
57 : iface(in_interface), 55 : iface_(in_interface),
58 required_permission(in_perm), 56 required_permission_(in_perm),
59 interface_logged(false) { 57 sent_to_uma_(false) {
60 } 58 }
61 59
62 const void* iface; 60 const void* iface() { return iface_; }
63 61
64 // Permission required to return non-null for this interface. This will 62 // Permission required to return non-null for this interface. This will
65 // be checked with the value set via SetProcessGlobalPermissionBits when 63 // be checked with the value set via SetProcessGlobalPermissionBits when
66 // an interface is requested. 64 // an interface is requested.
67 Permission required_permission; 65 Permission required_permission() { return required_permission_; };
68 66
69 // Interface usage is logged just once per-interface-per-plugin-process. 67 // Call this any time the interface is requested. It will log a UMA count
70 bool interface_logged; 68 // only the first time. This is safe to call from any thread, regardless of
69 // whether the proxy lock is held.
70 void LogWithUmaOnce(IPC::Sender* sender, const std::string& name);
71 private:
72 DISALLOW_COPY_AND_ASSIGN(InterfaceInfo);
73
74 const void* const iface_;
75 const Permission required_permission_;
76
77 bool sent_to_uma_;
78 base::Lock sent_to_uma_lock_;
71 }; 79 };
80 // Give friendship for HashInterfaceName.
81 friend class InterfaceInfo;
72 82
73 typedef std::map<std::string, InterfaceInfo> NameToInterfaceInfoMap; 83 typedef base::ScopedPtrHashMap<std::string, InterfaceInfo>
84 NameToInterfaceInfoMap;
74 85
75 void AddProxy(ApiID id, InterfaceProxy::Factory factory); 86 void AddProxy(ApiID id, InterfaceProxy::Factory factory);
76 87
77 // Permissions is the type of permission required to access the corresponding 88 // Permissions is the type of permission required to access the corresponding
78 // interface. Currently this must be just one unique permission (rather than 89 // interface. Currently this must be just one unique permission (rather than
79 // a bitfield). 90 // a bitfield).
80 void AddPPB(const char* name, const void* iface, Permission permission); 91 void AddPPB(const char* name, const void* iface, Permission permission);
81 void AddPPP(const char* name, const void* iface); 92 void AddPPP(const char* name, const void* iface);
82 93
83 // Hash the interface name for UMA logging. 94 // Hash the interface name for UMA logging.
84 static int HashInterfaceName(const std::string& name); 95 static int HashInterfaceName(const std::string& name);
85 96
86 PpapiPermissions permissions_; 97 PpapiPermissions permissions_;
87 98
88 NameToInterfaceInfoMap name_to_browser_info_; 99 NameToInterfaceInfoMap name_to_browser_info_;
89 NameToInterfaceInfoMap name_to_plugin_info_; 100 NameToInterfaceInfoMap name_to_plugin_info_;
90 101
91 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT]; 102 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT];
92 103
93 DISALLOW_COPY_AND_ASSIGN(InterfaceList); 104 DISALLOW_COPY_AND_ASSIGN(InterfaceList);
94 }; 105 };
95 106
96 } // namespace proxy 107 } // namespace proxy
97 } // namespace ppapi 108 } // namespace ppapi
98 109
99 #endif // PPAPI_PROXY_INTERFACE_LIST_H_ 110 #endif // PPAPI_PROXY_INTERFACE_LIST_H_
100 111
OLDNEW
« no previous file with comments | « ppapi/nacl_irt/plugin_main.cc ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698