summaryrefslogtreecommitdiffstats
path: root/chrome/common/trace_event_args_whitelist.cc
blob: 77bb5ccec4ad136531281c661b2637c1572650e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/trace_event_args_whitelist.h"

#include "base/strings/pattern.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"

namespace {

const char* const kEventArgsWhitelist[][2] = {{"toplevel", "*"},
                                              {"__metadata", "thread_name"},
                                              {NULL, NULL}};

}  // namespace

bool IsTraceEventArgsWhitelisted(const char* category_group_name,
                                 const char* event_name) {
  base::CStringTokenizer category_group_tokens(
      category_group_name, category_group_name + strlen(category_group_name),
      ",");
  while (category_group_tokens.GetNext()) {
    const std::string& category_group_token = category_group_tokens.token();
    for (int i = 0; kEventArgsWhitelist[i][0] != NULL; ++i) {
      DCHECK(kEventArgsWhitelist[i][1]);

      if (base::MatchPattern(category_group_token.c_str(),
                             kEventArgsWhitelist[i][0]) &&
          base::MatchPattern(event_name, kEventArgsWhitelist[i][1])) {
        return true;
      }
    }
  }

  return false;
}