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

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: remove errant file, fix comment typo 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 bool is_whitelisted =
yzshen1 2013/12/04 19:32:51 please move this to be right above where it is use
elijahtaylor1 2013/12/21 02:26:21 Done.
76 ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
77 document_url_, allowed_origins_);
78
79 const std::string nacl_prefix = "NaCl.";
80 if (is_plugin_in_process_ &&
81 histogram.substr(0, nacl_prefix.size()) == nacl_prefix) {
bbudge 2013/12/04 21:08:30 You could avoid some string creation by using find
elijahtaylor1 2013/12/21 02:26:21 Done.
82 return true;
83 }
84
85 if (is_whitelisted && allowed_histograms_.count(HashHistogram(histogram)) > 0)
bbudge 2013/12/04 21:08:30 allowed_histograms_.find is clearer and potentiall
elijahtaylor1 2013/12/21 02:26:21 Done.
86 return true;
87
88 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API.";
89 return false;
90 }
91
92 int32_t PepperUMARendererHost::OnHistogramCustomTimes(
93 ppapi::host::HostMessageContext* context,
94 const std::string& name,
95 int64_t sample,
yzshen1 2013/12/04 19:32:51 Do you need to validate the inputs? (>0; min <= ma
elijahtaylor1 2013/12/21 02:26:21 Brought over a similar macro that was in the in-pr
96 int64_t min,
97 int64_t max,
98 uint32_t bucket_count) {
99 if (!IsHistogramAllowed(name)) {
100 return PP_ERROR_NOACCESS;
101 }
102 base::HistogramBase* counter =
103 base::Histogram::FactoryTimeGet(
104 name,
105 base::TimeDelta::FromMilliseconds(min),
106 base::TimeDelta::FromMilliseconds(max),
107 bucket_count,
108 base::HistogramBase::kUmaTargetedHistogramFlag);
109 counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
110 return PP_OK;
111 }
112
113 int32_t PepperUMARendererHost::OnHistogramCustomCounts(
114 ppapi::host::HostMessageContext* context,
115 const std::string& name,
116 int32_t sample,
117 int32_t min,
118 int32_t max,
119 uint32_t bucket_count) {
120 if (!IsHistogramAllowed(name)) {
121 return PP_ERROR_NOACCESS;
122 }
123 base::HistogramBase* counter =
124 base::Histogram::FactoryGet(
125 name,
126 min,
127 max,
128 bucket_count,
129 base::HistogramBase::kUmaTargetedHistogramFlag);
130 counter->Add(sample);
131 return PP_OK;
132 }
133
134 int32_t PepperUMARendererHost::OnHistogramEnumeration(
135 ppapi::host::HostMessageContext* context,
136 const std::string& name,
137 int32_t sample,
138 int32_t boundary_value) {
139 if (!IsHistogramAllowed(name)) {
140 return PP_ERROR_NOACCESS;
141 }
142 base::HistogramBase* counter =
143 base::Histogram::FactoryGet(
144 name,
145 1,
146 boundary_value,
147 boundary_value + 1,
148 base::HistogramBase::kUmaTargetedHistogramFlag);
149 counter->Add(sample);
150 return PP_OK;
151 }
152
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698