OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "base/trace_event/memory_infra_background_whitelist.h" | |
6 | |
7 #include <ctype.h> | |
8 #include <string.h> | |
9 | |
10 #include <string> | |
11 | |
12 namespace base { | |
13 namespace trace_event { | |
14 namespace { | |
15 | |
16 // The names of dump providers whitelisted for background tracing. Dump | |
17 // providers can be added here only if the background mode dump has very | |
18 // less performance and memory overhead. | |
19 const char* const kDumpProviderWhitelist[] = { | |
20 // TODO(ssid): Fill this list with dump provider names which support | |
21 // background mode, crbug.com/613198. | |
22 nullptr // End of list marker. | |
23 }; | |
24 | |
25 // A list of string names that are allowed for the memory allocator dumps in | |
26 // background mode. | |
27 const char* const kAllocatorDumpNameWhitelist[] = { | |
28 // TODO(ssid): Fill this list with dump names, crbug.com/613198. | |
29 nullptr // End of list marker. | |
30 }; | |
31 | |
32 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist; | |
33 const char* const* g_allocator_dump_name_whitelist = | |
34 kAllocatorDumpNameWhitelist; | |
35 | |
36 } // namespace | |
37 | |
38 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) { | |
39 for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) { | |
40 if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0) | |
41 return true; | |
42 } | |
43 return false; | |
44 } | |
45 | |
46 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) { | |
47 // Remove special characters, numbers (including hexadecimal which are marked | |
48 // by '0x') from the given string. | |
49 const size_t length = name.size(); | |
50 std::string stripped_str; | |
51 stripped_str.reserve(length); | |
52 bool parsing_hex = false; | |
53 for (size_t i = 0; i < length; ++i) { | |
54 if (parsing_hex) { | |
55 if (isxdigit(name[i])) { | |
56 continue; | |
57 } else { | |
58 parsing_hex = false; | |
59 } | |
60 } | |
61 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { | |
62 parsing_hex = true; | |
63 ++i; | |
64 } else if (isalpha(name[i])) { | |
Primiano Tucci (use gerrit)
2016/06/03 16:24:36
sorry for the late comment, I realized later when
ssid
2016/06/04 00:26:58
I have only allowed '/'. See other comment. Lets f
| |
65 stripped_str.push_back(name[i]); | |
66 } | |
67 } | |
68 | |
69 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { | |
70 if (stripped_str == g_allocator_dump_name_whitelist[i]) { | |
71 return true; | |
72 } | |
73 } | |
74 return false; | |
75 } | |
76 | |
77 void SetDumpProviderWhitelistForTesting(const char* const* list) { | |
78 g_dump_provider_whitelist = list; | |
79 } | |
80 | |
81 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { | |
82 g_allocator_dump_name_whitelist = list; | |
83 } | |
84 | |
85 } // namespace trace_event | |
86 } // namespace base | |
OLD | NEW |