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

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

Issue 187593009: Match Pepper UMA histograms by prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months 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
« no previous file with comments | « chrome/renderer/pepper/pepper_uma_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/pepper/pepper_uma_host.h" 5 #include "chrome/renderer/pepper/pepper_uma_host.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/renderer/chrome_content_renderer_client.h" 11 #include "chrome/renderer/chrome_content_renderer_client.h"
12 #include "content/public/renderer/renderer_ppapi_host.h" 12 #include "content/public/renderer/renderer_ppapi_host.h"
13 #include "extensions/common/constants.h" 13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
15 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/host/dispatch_host_message.h" 16 #include "ppapi/host/dispatch_host_message.h"
17 #include "ppapi/host/host_message_context.h" 17 #include "ppapi/host/host_message_context.h"
18 #include "ppapi/host/ppapi_host.h" 18 #include "ppapi/host/ppapi_host.h"
19 #include "ppapi/proxy/ppapi_messages.h" 19 #include "ppapi/proxy/ppapi_messages.h"
20 20
21 namespace { 21 namespace {
22 22
23 const char* kPredefinedAllowedUMAOrigins[] = { 23 const char* kPredefinedAllowedUMAOrigins[] = {
24 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/317833 24 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/317833
25 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/317833 25 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/317833
26 }; 26 };
27 27
28 const char* kWhitelistedHistogramHashes[] = { 28 // The first 12 characters must match one of the prefixes below.
29 "F131550DAB7A7C6E6633EF81FB5998CC0482AC63", // see crbug.com/317833 29 const int kWhitelistedHistogramPrefixLength = 12;
Ilya Sherman 2014/03/06 00:34:14 Hmm, maybe scan up to the first dot instead?
elijahtaylor1 2014/03/06 00:46:27 Great suggestion. Done.
30 "13955AB4DAD798384DFB4304734FCF2A95F353CC", // see crbug.com/317833 30
31 "404E800582901F1B937B8E287235FC603A5DEDFB" // see crbug.com/317833 31 const char* kWhitelistedHistogramPrefixes[] = {
Ilya Sherman 2014/03/06 00:34:14 nit: "const char* const"
elijahtaylor1 2014/03/06 00:46:27 Done.
32 "CD190EA2B764EDF0BB97552A638D32072F3CFD41", // see crbug.com/317833
Ilya Sherman 2014/03/06 00:34:14 nit: Links should start with "http://". Also, thi
elijahtaylor1 2014/03/06 00:46:27 Fixed "http://" Yeah, I agree that could be frust
32 }; 33 };
33 34
34 std::string HashHistogram(const std::string& histogram) { 35
35 const std::string id_hash = base::SHA1HashString(histogram); 36 std::string HashPrefix(const std::string& histogram) {
37 const std::string id_hash = base::SHA1HashString(
38 histogram.substr(0, kWhitelistedHistogramPrefixLength));
36 DCHECK_EQ(id_hash.length(), base::kSHA1Length); 39 DCHECK_EQ(id_hash.length(), base::kSHA1Length);
37 return base::HexEncode(id_hash.c_str(), id_hash.length()); 40 return base::HexEncode(id_hash.c_str(), id_hash.length());
38 } 41 }
39 42
40 } // namespace 43 } // namespace
41 44
42 PepperUMAHost::PepperUMAHost( 45 PepperUMAHost::PepperUMAHost(
43 content::RendererPpapiHost* host, 46 content::RendererPpapiHost* host,
44 PP_Instance instance, 47 PP_Instance instance,
45 PP_Resource resource) 48 PP_Resource resource)
46 : ResourceHost(host->GetPpapiHost(), instance, resource), 49 : ResourceHost(host->GetPpapiHost(), instance, resource),
47 document_url_(host->GetDocumentURL(instance)), 50 document_url_(host->GetDocumentURL(instance)),
48 is_plugin_in_process_(host->IsRunningInProcess()) { 51 is_plugin_in_process_(host->IsRunningInProcess()) {
49 for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i) 52 for (size_t i = 0; i < arraysize(kPredefinedAllowedUMAOrigins); ++i)
50 allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]); 53 allowed_origins_.insert(kPredefinedAllowedUMAOrigins[i]);
51 for (size_t i = 0; i < arraysize(kWhitelistedHistogramHashes); ++i) 54 for (size_t i = 0; i < arraysize(kWhitelistedHistogramPrefixes); ++i)
52 allowed_histograms_.insert(kWhitelistedHistogramHashes[i]); 55 allowed_histogram_prefixes_.insert(kWhitelistedHistogramPrefixes[i]);
53 } 56 }
54 57
55 PepperUMAHost::~PepperUMAHost() { 58 PepperUMAHost::~PepperUMAHost() {
56 } 59 }
57 60
58 int32_t PepperUMAHost::OnResourceMessageReceived( 61 int32_t PepperUMAHost::OnResourceMessageReceived(
59 const IPC::Message& msg, 62 const IPC::Message& msg,
60 ppapi::host::HostMessageContext* context) { 63 ppapi::host::HostMessageContext* context) {
61 IPC_BEGIN_MESSAGE_MAP(PepperUMAHost, msg) 64 IPC_BEGIN_MESSAGE_MAP(PepperUMAHost, msg)
62 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes, 65 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes,
63 OnHistogramCustomTimes); 66 OnHistogramCustomTimes);
64 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts, 67 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts,
65 OnHistogramCustomCounts); 68 OnHistogramCustomCounts);
66 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration, 69 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration,
67 OnHistogramEnumeration); 70 OnHistogramEnumeration);
68 IPC_END_MESSAGE_MAP() 71 IPC_END_MESSAGE_MAP()
69 return PP_ERROR_FAILED; 72 return PP_ERROR_FAILED;
70 } 73 }
71 74
72 bool PepperUMAHost::IsHistogramAllowed(const std::string& histogram) { 75 bool PepperUMAHost::IsHistogramAllowed(const std::string& histogram) {
73 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { 76 if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) {
74 return true; 77 return true;
75 } 78 }
76 79
77 bool is_whitelisted = 80 bool is_whitelisted =
78 ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted( 81 ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted(
79 document_url_, allowed_origins_); 82 document_url_, allowed_origins_);
80 if (is_whitelisted && 83 if (is_whitelisted &&
81 allowed_histograms_.find(HashHistogram(histogram)) != 84 allowed_histogram_prefixes_.find(HashPrefix(histogram)) !=
82 allowed_histograms_.end()) { 85 allowed_histogram_prefixes_.end()) {
83 return true; 86 return true;
84 } 87 }
85 88
86 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API."; 89 LOG(ERROR) << "Host or histogram name is not allowed to use the UMA API.";
87 return false; 90 return false;
88 } 91 }
89 92
90 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \ 93 #define RETURN_IF_BAD_ARGS(_min, _max, _buckets) \
91 do { \ 94 do { \
92 if (_min >= _max || _buckets <= 1) \ 95 if (_min >= _max || _buckets <= 1) \
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 base::LinearHistogram::FactoryGet( 156 base::LinearHistogram::FactoryGet(
154 name, 157 name,
155 1, 158 1,
156 boundary_value, 159 boundary_value,
157 boundary_value + 1, 160 boundary_value + 1,
158 base::HistogramBase::kUmaTargetedHistogramFlag); 161 base::HistogramBase::kUmaTargetedHistogramFlag);
159 counter->Add(sample); 162 counter->Add(sample);
160 return PP_OK; 163 return PP_OK;
161 } 164 }
162 165
OLDNEW
« no previous file with comments | « chrome/renderer/pepper/pepper_uma_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698