Make castv2 performance test work.
[chromium-blink-merge.git] / ppapi / proxy / interface_list.h
blobdc109e5c5afd45ca1395ff1dec3d658684e12bbf
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_INTERFACE_LIST_H_
6 #define PPAPI_PROXY_INTERFACE_LIST_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/synchronization/lock.h"
14 #include "ppapi/proxy/interface_proxy.h"
15 #include "ppapi/proxy/ppapi_proxy_export.h"
16 #include "ppapi/shared_impl/ppapi_permissions.h"
18 namespace ppapi {
19 namespace proxy {
21 class PPAPI_PROXY_EXPORT InterfaceList {
22 public:
23 InterfaceList();
24 ~InterfaceList();
26 static InterfaceList* GetInstance();
28 // Sets the permissions that the interface list will use to compute
29 // whether an interface is available to the current process. By default,
30 // this will be "no permissions", which will give only access to public
31 // stable interfaces via GetInterface.
33 // IMPORTANT: This is not a security boundary. Malicious plugins can bypass
34 // this check since they run in the same address space as this code in the
35 // plugin process. A real security check is required for all IPC messages.
36 // This check just allows us to return NULL for interfaces you "shouldn't" be
37 // using to keep honest plugins honest.
38 static void SetProcessGlobalPermissions(const PpapiPermissions& permissions);
40 // Looks up the factory function for the given ID. Returns NULL if not
41 // supported.
42 InterfaceProxy::Factory GetFactoryForID(ApiID id) const;
44 // Returns the interface pointer for the given browser or plugin interface,
45 // or NULL if it's not supported.
46 const void* GetInterfaceForPPB(const std::string& name);
47 const void* GetInterfaceForPPP(const std::string& name) const;
49 private:
50 friend class InterfaceListTest;
52 class InterfaceInfo {
53 public:
54 InterfaceInfo(const void* in_interface, Permission in_perm)
55 : iface_(in_interface),
56 required_permission_(in_perm),
57 sent_to_uma_(false) {
60 const void* iface() { return iface_; }
62 // Permission required to return non-null for this interface. This will
63 // be checked with the value set via SetProcessGlobalPermissionBits when
64 // an interface is requested.
65 Permission required_permission() { return required_permission_; };
67 // Call this any time the interface is requested. It will log a UMA count
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);
74 const void* const iface_;
75 const Permission required_permission_;
77 bool sent_to_uma_;
78 base::Lock sent_to_uma_lock_;
80 // Give friendship for HashInterfaceName.
81 friend class InterfaceInfo;
83 typedef base::ScopedPtrHashMap<std::string, InterfaceInfo>
84 NameToInterfaceInfoMap;
86 void AddProxy(ApiID id, InterfaceProxy::Factory factory);
88 // Permissions is the type of permission required to access the corresponding
89 // interface. Currently this must be just one unique permission (rather than
90 // a bitfield).
91 void AddPPB(const char* name, const void* iface, Permission permission);
92 void AddPPP(const char* name, const void* iface);
94 // Hash the interface name for UMA logging.
95 static int HashInterfaceName(const std::string& name);
97 PpapiPermissions permissions_;
99 NameToInterfaceInfoMap name_to_browser_info_;
100 NameToInterfaceInfoMap name_to_plugin_info_;
102 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT];
104 DISALLOW_COPY_AND_ASSIGN(InterfaceList);
107 } // namespace proxy
108 } // namespace ppapi
110 #endif // PPAPI_PROXY_INTERFACE_LIST_H_