aw_trace_event_args_allowlist.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2018 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. #include "android_webview/browser/tracing/aw_trace_event_args_allowlist.h"
  5. #include "base/bind.h"
  6. #include "base/strings/pattern.h"
  7. #include "base/strings/string_tokenizer.h"
  8. #include "base/strings/string_util.h"
  9. #include "base/trace_event/trace_event.h"
  10. namespace {
  11. struct AllowlistEntry {
  12. const char* category_name;
  13. const char* event_name;
  14. const char* const* arg_name_filter;
  15. };
  16. const char* const kMemoryDumpAllowedArgs[] = {"dumps", nullptr};
  17. const AllowlistEntry kEventArgsAllowlist[] = {
  18. {"__metadata", "thread_name", nullptr},
  19. {"__metadata", "process_name", nullptr},
  20. {"__metadata", "process_uptime_seconds", nullptr},
  21. {"__metadata", "stackFrames", nullptr},
  22. {"__metadata", "typeNames", nullptr},
  23. // Redefined the string since MemoryDumpManager::kTraceCategory causes
  24. // static initialization of this struct.
  25. {TRACE_DISABLED_BY_DEFAULT("memory-infra"), "*", kMemoryDumpAllowedArgs},
  26. {nullptr, nullptr, nullptr}};
  27. } // namespace
  28. namespace android_webview {
  29. // TODO(timvolodine): refactor this into base/ to avoid code duplication
  30. // with chrome/common/trace_event_args_allowlist.cc, see crbug.com/805045.
  31. bool IsTraceArgumentNameAllowlisted(const char* const* granular_filter,
  32. const char* arg_name) {
  33. for (int i = 0; granular_filter[i] != nullptr; ++i) {
  34. if (base::MatchPattern(arg_name, granular_filter[i]))
  35. return true;
  36. }
  37. return false;
  38. }
  39. bool IsTraceEventArgsAllowlisted(
  40. const char* category_group_name,
  41. const char* event_name,
  42. base::trace_event::ArgumentNameFilterPredicate* arg_name_filter) {
  43. DCHECK(arg_name_filter);
  44. base::CStringTokenizer category_group_tokens(
  45. category_group_name, category_group_name + strlen(category_group_name),
  46. ",");
  47. while (category_group_tokens.GetNext()) {
  48. const std::string& category_group_token = category_group_tokens.token();
  49. for (int i = 0; kEventArgsAllowlist[i].category_name != nullptr; ++i) {
  50. const AllowlistEntry& allowlist_entry = kEventArgsAllowlist[i];
  51. DCHECK(allowlist_entry.event_name);
  52. if (base::MatchPattern(category_group_token,
  53. allowlist_entry.category_name) &&
  54. base::MatchPattern(event_name, allowlist_entry.event_name)) {
  55. if (allowlist_entry.arg_name_filter) {
  56. *arg_name_filter = base::BindRepeating(
  57. &IsTraceArgumentNameAllowlisted, allowlist_entry.arg_name_filter);
  58. }
  59. return true;
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. bool IsTraceMetadataAllowlisted(const std::string& name) {
  66. return false;
  67. }
  68. } // namespace android_webview