diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 15:34:21 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 15:34:21 +0000 |
commit | ea441832f9f20a18a465327ce7c727afc1ed5e8a (patch) | |
tree | 0c857b84708176f3e64bfdf93d611c99864dc5d6 /ppapi/proxy | |
parent | 1345f3b9e3c6ca1677aa2ffd0c915b63b040772b (diff) | |
download | chromium_src-ea441832f9f20a18a465327ce7c727afc1ed5e8a.zip chromium_src-ea441832f9f20a18a465327ce7c727afc1ed5e8a.tar.gz chromium_src-ea441832f9f20a18a465327ce7c727afc1ed5e8a.tar.bz2 |
Pepper: Log in UMA when an interface is used.
We'd like to know what versions of our interfaces are used by end users. This
change logs usage of PPB interfaces for out-of-process plugins the first time
that get_interface<>() is called for a given interface and version.
I tested this change by loading some plugin examples and checking the
about:histograms page.
BUG=111542
R=asvitkine@chromium.org, jschuh@chromium.org, yzshen@chromium.org
Review URL: https://codereview.chromium.org/141523010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/interface_list.cc | 24 | ||||
-rw-r--r-- | ppapi/proxy/interface_list.h | 14 | ||||
-rw-r--r-- | ppapi/proxy/interface_list_unittest.cc | 14 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 3 |
4 files changed, 49 insertions, 6 deletions
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 79789d7..9e33c72 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -4,6 +4,7 @@ #include "ppapi/proxy/interface_list.h" +#include "base/hash.h" #include "base/lazy_instance.h" #include "base/memory/singleton.h" #include "ppapi/c/dev/ppb_alarms_dev.h" @@ -104,6 +105,8 @@ #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/plugin_globals.h" +#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" @@ -315,15 +318,22 @@ InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const { return id_to_factory_[index]; } -const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { - NameToInterfaceInfoMap::const_iterator found = +const void* InterfaceList::GetInterfaceForPPB(const std::string& name) { + NameToInterfaceInfoMap::iterator found = name_to_browser_info_.find(name); if (found == name_to_browser_info_.end()) return NULL; if (g_process_global_permissions.Get().HasPermission( - found->second.required_permission)) + found->second.required_permission)) { + // Only log interface use once per plugin. + if (!found->second.interface_logged) { + PluginGlobals::Get()->GetBrowserSender()->Send( + new PpapiHostMsg_LogInterfaceUsage(HashInterfaceName(name))); + found->second.interface_logged = true; + } return found->second.iface; + } return NULL; } @@ -364,5 +374,13 @@ void InterfaceList::AddPPP(const char* name, name_to_plugin_info_[name] = InterfaceInfo(iface, PERMISSION_NONE); } +// static +int InterfaceList::HashInterfaceName(const std::string& name) { + uint32 data = base::Hash(name.c_str(), name.size()); + // Strip off the signed bit because UMA doesn't support negative values, + // but takes a signed int as input. + return static_cast<int>(data & 0x7fffffff); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/interface_list.h b/ppapi/proxy/interface_list.h index 85b7eb6..a2b4569c 100644 --- a/ppapi/proxy/interface_list.h +++ b/ppapi/proxy/interface_list.h @@ -41,7 +41,7 @@ class PPAPI_PROXY_EXPORT InterfaceList { // Returns the interface pointer for the given browser or plugin interface, // or NULL if it's not supported. - const void* GetInterfaceForPPB(const std::string& name) const; + const void* GetInterfaceForPPB(const std::string& name); const void* GetInterfaceForPPP(const std::string& name) const; private: @@ -50,11 +50,13 @@ class PPAPI_PROXY_EXPORT InterfaceList { struct InterfaceInfo { InterfaceInfo() : iface(NULL), - required_permission(PERMISSION_NONE) { + required_permission(PERMISSION_NONE), + interface_logged(false) { } InterfaceInfo(const void* in_interface, Permission in_perm) : iface(in_interface), - required_permission(in_perm) { + required_permission(in_perm), + interface_logged(false) { } const void* iface; @@ -63,6 +65,9 @@ class PPAPI_PROXY_EXPORT InterfaceList { // be checked with the value set via SetProcessGlobalPermissionBits when // an interface is requested. Permission required_permission; + + // Interface usage is logged just once per-interface-per-plugin-process. + bool interface_logged; }; typedef std::map<std::string, InterfaceInfo> NameToInterfaceInfoMap; @@ -75,6 +80,9 @@ class PPAPI_PROXY_EXPORT InterfaceList { void AddPPB(const char* name, const void* iface, Permission permission); void AddPPP(const char* name, const void* iface); + // Hash the interface name for UMA logging. + static int HashInterfaceName(const std::string& name); + PpapiPermissions permissions_; NameToInterfaceInfoMap name_to_browser_info_; diff --git a/ppapi/proxy/interface_list_unittest.cc b/ppapi/proxy/interface_list_unittest.cc index 17140f0..902a0a18 100644 --- a/ppapi/proxy/interface_list_unittest.cc +++ b/ppapi/proxy/interface_list_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/hash.h" #include "ppapi/c/ppb_core.h" #include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/ppapi_proxy_test.h" @@ -16,6 +17,12 @@ class InterfaceListTest : public PluginProxyTest { const char* iface_name, void* iface_addr, Permission perm) { list->AddPPB(iface_name, iface_addr, perm); } + + // Wrapper function so we can use the private + // InterfaceList::HashInterfaceName. + int HashInterfaceName(const std::string& name) { + return InterfaceList::HashInterfaceName(name); + } }; // Tests looking up a stable interface. @@ -62,5 +69,12 @@ TEST_F(InterfaceListTest, DevChannel) { ASSERT_TRUE(list.GetInterfaceForPPB(dev_iface_name) == dev_iface_addr); } +// Test that the hash function provided by base::Hash is unchanged. This is so +// that we will generate correct values when logging interface use to UMA. +TEST_F(InterfaceListTest, InterfaceHash) { + EXPECT_EQ(612625164, HashInterfaceName("PPB_InputEvent;1.0")); + EXPECT_EQ(79708274, HashInterfaceName("PPB_TCPSocket;1.1")); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index a6f8f2c..7e6543e 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -422,6 +422,9 @@ IPC_SYNC_MESSAGE_CONTROL1_1(PpapiMsg_SupportsInterface, std::string /* interface_name */, bool /* result */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_LogInterfaceUsage, + int /* interface_hash */) + #if !defined(OS_NACL) && !defined(NACL_WIN64) // Network state notification from the browser for implementing // PPP_NetworkState_Dev. |