OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "base/trace_event/trace_config.h" | 5 #include "base/trace_event/trace_config.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/strings/pattern.h" |
9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
10 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 namespace trace_event { | 16 namespace trace_event { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ","); | 141 ","); |
141 while (category_group_tokens.GetNext()) { | 142 while (category_group_tokens.GetNext()) { |
142 std::string category_group_token = category_group_tokens.token(); | 143 std::string category_group_token = category_group_tokens.token(); |
143 // Don't allow empty tokens, nor tokens with leading or trailing space. | 144 // Don't allow empty tokens, nor tokens with leading or trailing space. |
144 DCHECK(!TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 145 DCHECK(!TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
145 category_group_token)) | 146 category_group_token)) |
146 << "Disallowed category string"; | 147 << "Disallowed category string"; |
147 if (IsCategoryEnabled(category_group_token.c_str())) { | 148 if (IsCategoryEnabled(category_group_token.c_str())) { |
148 return true; | 149 return true; |
149 } | 150 } |
150 if (!MatchPattern(category_group_token.c_str(), | 151 if (!base::MatchPattern(category_group_token.c_str(), |
151 TRACE_DISABLED_BY_DEFAULT("*"))) | 152 TRACE_DISABLED_BY_DEFAULT("*"))) |
152 had_enabled_by_default = true; | 153 had_enabled_by_default = true; |
153 } | 154 } |
154 // Do a second pass to check for explicitly disabled categories | 155 // Do a second pass to check for explicitly disabled categories |
155 // (those explicitly enabled have priority due to first pass). | 156 // (those explicitly enabled have priority due to first pass). |
156 category_group_tokens.Reset(); | 157 category_group_tokens.Reset(); |
157 bool category_group_disabled = false; | 158 bool category_group_disabled = false; |
158 while (category_group_tokens.GetNext()) { | 159 while (category_group_tokens.GetNext()) { |
159 std::string category_group_token = category_group_tokens.token(); | 160 std::string category_group_token = category_group_tokens.token(); |
160 for (StringList::const_iterator ci = excluded_categories_.begin(); | 161 for (StringList::const_iterator ci = excluded_categories_.begin(); |
161 ci != excluded_categories_.end(); | 162 ci != excluded_categories_.end(); |
162 ++ci) { | 163 ++ci) { |
163 if (MatchPattern(category_group_token.c_str(), ci->c_str())) { | 164 if (base::MatchPattern(category_group_token.c_str(), ci->c_str())) { |
164 // Current token of category_group_name is present in excluded_list. | 165 // Current token of category_group_name is present in excluded_list. |
165 // Flag the exclusion and proceed further to check if any of the | 166 // Flag the exclusion and proceed further to check if any of the |
166 // remaining categories of category_group_name is not present in the | 167 // remaining categories of category_group_name is not present in the |
167 // excluded_ list. | 168 // excluded_ list. |
168 category_group_disabled = true; | 169 category_group_disabled = true; |
169 break; | 170 break; |
170 } | 171 } |
171 // One of the category of category_group_name is not present in | 172 // One of the category of category_group_name is not present in |
172 // excluded_ list. So, it has to be included_ list. Enable the | 173 // excluded_ list. So, it has to be included_ list. Enable the |
173 // category_group_name for recording. | 174 // category_group_name for recording. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 509 } |
509 | 510 |
510 bool TraceConfig::IsCategoryEnabled(const char* category_name) const { | 511 bool TraceConfig::IsCategoryEnabled(const char* category_name) const { |
511 StringList::const_iterator ci; | 512 StringList::const_iterator ci; |
512 | 513 |
513 // Check the disabled- filters and the disabled-* wildcard first so that a | 514 // Check the disabled- filters and the disabled-* wildcard first so that a |
514 // "*" filter does not include the disabled. | 515 // "*" filter does not include the disabled. |
515 for (ci = disabled_categories_.begin(); | 516 for (ci = disabled_categories_.begin(); |
516 ci != disabled_categories_.end(); | 517 ci != disabled_categories_.end(); |
517 ++ci) { | 518 ++ci) { |
518 if (MatchPattern(category_name, ci->c_str())) | 519 if (base::MatchPattern(category_name, ci->c_str())) |
519 return true; | 520 return true; |
520 } | 521 } |
521 | 522 |
522 if (MatchPattern(category_name, TRACE_DISABLED_BY_DEFAULT("*"))) | 523 if (base::MatchPattern(category_name, TRACE_DISABLED_BY_DEFAULT("*"))) |
523 return false; | 524 return false; |
524 | 525 |
525 for (ci = included_categories_.begin(); | 526 for (ci = included_categories_.begin(); |
526 ci != included_categories_.end(); | 527 ci != included_categories_.end(); |
527 ++ci) { | 528 ++ci) { |
528 if (MatchPattern(category_name, ci->c_str())) | 529 if (base::MatchPattern(category_name, ci->c_str())) |
529 return true; | 530 return true; |
530 } | 531 } |
531 | 532 |
532 return false; | 533 return false; |
533 } | 534 } |
534 | 535 |
535 bool TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 536 bool TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
536 const std::string& str) { | 537 const std::string& str) { |
537 return str.empty() || | 538 return str.empty() || |
538 str.at(0) == ' ' || | 539 str.at(0) == ' ' || |
539 str.at(str.length() - 1) == ' '; | 540 str.at(str.length() - 1) == ' '; |
540 } | 541 } |
541 | 542 |
542 bool TraceConfig::HasIncludedPatterns() const { | 543 bool TraceConfig::HasIncludedPatterns() const { |
543 return !included_categories_.empty(); | 544 return !included_categories_.empty(); |
544 } | 545 } |
545 | 546 |
546 } // namespace trace_event | 547 } // namespace trace_event |
547 } // namespace base | 548 } // namespace base |
OLD | NEW |