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

Side by Side Diff: chrome/renderer/pepper/pepper_uma_renderer_host.cc

Issue 61643022: Proxy private UMA pepper interface for out-of-process and NaCl plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add back browser impl for testing Created 7 years 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
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "chrome/renderer/pepper/pepper_uma_renderer_host.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/renderer/chrome_content_renderer_client.h"
12 #include "content/public/renderer/renderer_ppapi_host.h"
13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension.h"
15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/host/dispatch_host_message.h"
17 #include "ppapi/host/host_message_context.h"
18 #include "ppapi/host/ppapi_host.h"
19 #include "ppapi/proxy/ppapi_messages.h"
20
21 namespace {
22
23 const char* kPredefinedAllowedUMAOrigins[] = {
24 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/317833
25 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/317833
26 };
27
28 const char* kWhitelistedHistogramHashes[] = {
29 "F131550DAB7A7C6E6633EF81FB5998CC0482AC63", // see crbug.com/317833
30 "BFA80E7D71DE24D08B7363B108CD6DABFF24B9A0", // see crbug.com/317833
31 "13955AB4DAD798384DFB4304734FCF2A95F353CC", // see crbug.com/317833
32 "404E800582901F1B937B8E287235FC603A5DEDFB", // see crbug.com/317833
33 "D95DDB0F180CF797AD30E221D659A9E2B6404BC8" // see crbug.com/317833
34 };
35
36 std::string HashHistogram(const std::string& histogram) {
37 const std::string id_hash = base::SHA1HashString(histogram);
38 DCHECK_EQ(id_hash.length(), base::kSHA1Length);
39 return base::HexEncode(id_hash.c_str(), id_hash.length());
40 }
41
42 } // namespace
43
44 PepperUMARendererHost::PepperUMARendererHost(
45 content::RendererPpapiHost* host,
46 PP_Instance instance,
47 PP_Resource resource)
48 : ResourceHost(host->GetPpapiHost(), instance, resource),
49 document_url_(host->GetDocumentURL(instance)),
50 is_plugin_in_process_(host->IsRunningInProcess()) {
51 for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i)
52 allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]);
53 for (size_t i = 0; i < arraysize(kWhitelistedHistogramHashes); ++i)
54 allowed_histograms_.insert(kWhitelistedHistogramHashes[i]);
55 }
56
57 PepperUMARendererHost::~PepperUMARendererHost() {
58 }
59
60 int32_t PepperUMARendererHost::OnResourceMessageReceived(
61 const IPC::Message& msg,
62 ppapi::host::HostMessageContext* context) {
63 IPC_BEGIN_MESSAGE_MAP(PepperUMARendererHost, msg)
64 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes,
65 OnHistogramCustomTimes);
66 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts,
67 OnHistogramCustomCounts);
68 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration,
69 OnHistogramEnumeration);
70 IPC_END_MESSAGE_MAP()
71 return PP_ERROR_FAILED;
72 }
73
74 bool PepperUMARendererHost::IsHistogramAllowed(const std::string& histogram) {
75 return true;
76 bool is_whitelisted =
77 ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
78 document_url_, allowed_origins_);
79
80 const std::string nacl_prefix = "NaCl.";
81 if (is_plugin_in_process_ &&
82 histogram.substr(0, nacl_prefix.size()) == nacl_prefix) {
83 return true;
84 }
85
86 if (is_whitelisted && allowed_histograms_.count(HashHistogram(histogram)) > 0)
87 return true;
88
89 LOG(ERROR) << "Host " << document_url_.host() << " cannot use UMA API.";
90 return false;
91 }
92
93 int32_t PepperUMARendererHost::OnHistogramCustomTimes(
94 ppapi::host::HostMessageContext* context,
95 const std::string& name,
96 int64_t sample,
97 int64_t min,
98 int64_t max,
99 uint32_t bucket_count) {
100 if (!IsHistogramAllowed(name)) {
101 return PP_ERROR_NOACCESS;
102 }
103 base::HistogramBase* counter =
104 base::Histogram::FactoryTimeGet(
105 name,
106 base::TimeDelta::FromMilliseconds(min),
107 base::TimeDelta::FromMilliseconds(max),
108 bucket_count,
109 base::HistogramBase::kUmaTargetedHistogramFlag);
110 counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
111 return PP_OK;
112 }
113
114 int32_t PepperUMARendererHost::OnHistogramCustomCounts(
115 ppapi::host::HostMessageContext* context,
116 const std::string& name,
117 int32_t sample,
118 int32_t min,
119 int32_t max,
120 uint32_t bucket_count) {
121 if (!IsHistogramAllowed(name)) {
122 return PP_ERROR_NOACCESS;
123 }
124 base::HistogramBase* counter =
125 base::Histogram::FactoryGet(
126 name,
127 min,
128 max,
129 bucket_count,
130 base::HistogramBase::kUmaTargetedHistogramFlag);
131 counter->Add(sample);
132 return PP_OK;
133 }
134
135 int32_t PepperUMARendererHost::OnHistogramEnumeration(
136 ppapi::host::HostMessageContext* context,
137 const std::string& name,
138 int32_t sample,
139 int32_t boundary_value) {
140 if (!IsHistogramAllowed(name)) {
141 return PP_ERROR_NOACCESS;
142 }
143 base::HistogramBase* counter =
144 base::Histogram::FactoryGet(
145 name,
146 1,
147 boundary_value,
148 boundary_value + 1,
149 base::HistogramBase::kUmaTargetedHistogramFlag);
150 counter->Add(sample);
151 return PP_OK;
152 }
153
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698