| Index: chrome/browser/renderer_host/pepper/pepper_uma_message_filter.cc
|
| diff --git a/chrome/browser/renderer_host/pepper/pepper_uma_message_filter.cc b/chrome/browser/renderer_host/pepper/pepper_uma_message_filter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5b11cc4027cc5e5c7d817dda86b9d03164867ab3
|
| --- /dev/null
|
| +++ b/chrome/browser/renderer_host/pepper/pepper_uma_message_filter.cc
|
| @@ -0,0 +1,196 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/renderer_host/pepper/pepper_uma_message_filter.h"
|
| +
|
| +#include "base/metrics/histogram.h"
|
| +#include "base/sha1.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/extensions/extension_system.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/common/pepper_permission_util.h"
|
| +#include "content/public/browser/browser_ppapi_host.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/child_process_security_policy.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "extensions/common/constants.h"
|
| +#include "extensions/common/extension.h"
|
| +#include "ppapi/c/pp_errors.h"
|
| +#include "ppapi/host/dispatch_host_message.h"
|
| +#include "ppapi/host/host_message_context.h"
|
| +#include "ppapi/host/ppapi_host.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "webkit/browser/fileapi/isolated_context.h"
|
| +
|
| +namespace chrome {
|
| +
|
| +namespace {
|
| +
|
| +const char* kPredefinedAllowedUMAOrigins[] = {
|
| + "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/317833
|
| + "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/317833
|
| +};
|
| +
|
| +const char* kWhitelistedHistogramHashes[] = {
|
| + "F131550DAB7A7C6E6633EF81FB5998CC0482AC63", // see crbug.com/317833
|
| + "BFA80E7D71DE24D08B7363B108CD6DABFF24B9A0", // see crbug.com/317833
|
| + "13955AB4DAD798384DFB4304734FCF2A95F353CC", // see crbug.com/317833
|
| + "404E800582901F1B937B8E287235FC603A5DEDFB", // see crbug.com/317833
|
| + "D95DDB0F180CF797AD30E221D659A9E2B6404BC8" // see crbug.com/317833
|
| +};
|
| +
|
| +std::string HashHistogram(const std::string& histogram) {
|
| + const std::string id_hash = base::SHA1HashString(histogram);
|
| + DCHECK_EQ(id_hash.length(), base::kSHA1Length);
|
| + return base::HexEncode(id_hash.c_str(), id_hash.length());
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +PepperUMAMessageFilter* PepperUMAMessageFilter::Create(
|
| + PP_Instance instance, content::BrowserPpapiHost* host) {
|
| + return new PepperUMAMessageFilter(
|
| + host->GetProfileDataDirectory(),
|
| + host->GetDocumentURLForInstance(instance),
|
| + host->IsInProcess());
|
| +}
|
| +
|
| +PepperUMAMessageFilter::PepperUMAMessageFilter(
|
| + const base::FilePath& profile_directory,
|
| + const GURL& document_url,
|
| + bool is_plugin_in_process)
|
| + : profile_directory_(profile_directory),
|
| + document_url_(document_url),
|
| + is_plugin_in_process_(is_plugin_in_process) {
|
| + for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i)
|
| + allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]);
|
| + for (size_t i = 0; i < arraysize(kWhitelistedHistogramHashes); ++i)
|
| + allowed_histograms_.insert(kWhitelistedHistogramHashes[i]);
|
| +}
|
| +
|
| +PepperUMAMessageFilter::~PepperUMAMessageFilter() {
|
| +}
|
| +
|
| +scoped_refptr<base::TaskRunner>
|
| +PepperUMAMessageFilter::OverrideTaskRunnerForMessage(
|
| + const IPC::Message& msg) {
|
| + // In order to reach ExtensionSystem, we need to get ProfileManager first.
|
| + // ProfileManager lives in UI thread, so we need to do this in UI thread.
|
| + return content::BrowserThread::GetMessageLoopProxyForThread(
|
| + content::BrowserThread::UI);
|
| +}
|
| +
|
| +int32_t PepperUMAMessageFilter::OnResourceMessageReceived(
|
| + const IPC::Message& msg,
|
| + ppapi::host::HostMessageContext* context) {
|
| + IPC_BEGIN_MESSAGE_MAP(PepperUMAMessageFilter, msg)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes,
|
| + OnHistogramCustomTimes);
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts,
|
| + OnHistogramCustomCounts);
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration,
|
| + OnHistogramEnumeration);
|
| + IPC_END_MESSAGE_MAP()
|
| + return PP_ERROR_FAILED;
|
| +}
|
| +
|
| +Profile* PepperUMAMessageFilter::GetProfile() {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + return profile_manager->GetProfile(profile_directory_);
|
| +}
|
| +
|
| +bool PepperUMAMessageFilter::IsHistogramAllowed(const std::string& histogram) {
|
| + Profile* profile = GetProfile();
|
| + const ExtensionSet* extension_set = NULL;
|
| + if (profile) {
|
| + extension_set = extensions::ExtensionSystem::Get(profile)->
|
| + extension_service()->extensions();
|
| + }
|
| + if (!IsExtensionOrSharedModuleWhitelisted(
|
| + document_url_, extension_set, allowed_origins_) &&
|
| + !is_plugin_in_process_) {
|
| + LOG(ERROR) << "Host " << document_url_.host() << " cannot use UMA API.";
|
| + return false;
|
| + }
|
| +
|
| + const std::string nacl_prefix = "NaCl.";
|
| + if (is_plugin_in_process_ &&
|
| + histogram.substr(0, nacl_prefix.size()) == nacl_prefix) {
|
| + return true;
|
| + }
|
| +
|
| + if (allowed_histograms_.count(HashHistogram(histogram)) > 0)
|
| + return true;
|
| +
|
| + return false;
|
| +}
|
| +
|
| +int32_t PepperUMAMessageFilter::OnHistogramCustomTimes(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::string& name,
|
| + int64_t sample,
|
| + int64_t min,
|
| + int64_t max,
|
| + uint32_t bucket_count) {
|
| + if (!IsHistogramAllowed(name)) {
|
| + return PP_ERROR_NOACCESS;
|
| + }
|
| + base::HistogramBase* counter =
|
| + base::Histogram::FactoryTimeGet(
|
| + name,
|
| + base::TimeDelta::FromMilliseconds(min),
|
| + base::TimeDelta::FromMilliseconds(max),
|
| + bucket_count,
|
| + base::HistogramBase::kUmaTargetedHistogramFlag);
|
| + counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t PepperUMAMessageFilter::OnHistogramCustomCounts(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::string& name,
|
| + int32_t sample,
|
| + int32_t min,
|
| + int32_t max,
|
| + uint32_t bucket_count) {
|
| + if (!IsHistogramAllowed(name)) {
|
| + return PP_ERROR_NOACCESS;
|
| + }
|
| + base::HistogramBase* counter =
|
| + base::Histogram::FactoryGet(
|
| + name,
|
| + min,
|
| + max,
|
| + bucket_count,
|
| + base::HistogramBase::kUmaTargetedHistogramFlag);
|
| + counter->Add(sample);
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t PepperUMAMessageFilter::OnHistogramEnumeration(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::string& name,
|
| + int32_t sample,
|
| + int32_t boundary_value) {
|
| + if (!IsHistogramAllowed(name)) {
|
| + return PP_ERROR_NOACCESS;
|
| + }
|
| + base::HistogramBase* counter =
|
| + base::Histogram::FactoryGet(
|
| + name,
|
| + 1,
|
| + boundary_value,
|
| + boundary_value + 1,
|
| + base::HistogramBase::kUmaTargetedHistogramFlag);
|
| + counter->Add(sample);
|
| + return PP_OK;
|
| +}
|
| +
|
| +} // namespace chrome
|
|
|