Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 : trace_config_(trace_config) {} | 65 : trace_config_(trace_config) {} |
| 66 ~ConvertableTraceConfigToTraceFormat() override {} | 66 ~ConvertableTraceConfigToTraceFormat() override {} |
| 67 void AppendAsTraceFormat(std::string* out) const override { | 67 void AppendAsTraceFormat(std::string* out) const override { |
| 68 out->append(trace_config_.ToString()); | 68 out->append(trace_config_.ToString()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 const TraceConfig trace_config_; | 72 const TraceConfig trace_config_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Convert each uppercase character to separator + lowercase. | |
| 76 std::string convertStringStyle(const std::string& in_str, | |
|
Primiano Tucci (use gerrit)
2016/03/06 01:24:37
This function should not be in base, and once you
Primiano Tucci (use gerrit)
2016/03/06 01:24:37
nit: UpperCase function names:
https://google.gith
| |
| 77 const char& separator) { | |
|
caseq
2016/03/05 02:25:24
no need to pass a char by reference :)
| |
| 78 std::string out_str; | |
| 79 for (const char& c : in_str) { | |
| 80 if (isupper(c)) { | |
| 81 out_str.push_back(separator); | |
| 82 out_str.push_back(tolower(c)); | |
| 83 } else { | |
| 84 out_str.push_back(c); | |
| 85 } | |
| 86 } | |
| 87 return out_str; | |
| 88 } | |
| 89 | |
| 90 scoped_ptr<base::Value> convertDictKeyStyle(const base::Value& value) { | |
|
caseq
2016/03/05 02:25:24
style: s/convert/Convert/
| |
| 91 const base::DictionaryValue* dict = NULL; | |
|
caseq
2016/03/05 02:25:24
nit: nullptr
| |
| 92 const base::ListValue* list = NULL; | |
|
caseq
2016/03/05 02:25:24
ditto (and please move down to actual usage)
| |
| 93 | |
| 94 if (value.GetAsDictionary(&dict)) { | |
| 95 scoped_ptr<base::DictionaryValue> out_dict(new base::DictionaryValue()); | |
| 96 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); | |
| 97 it.Advance()) { | |
| 98 out_dict->Set(convertStringStyle(it.key(), '_'), | |
| 99 convertDictKeyStyle(it.value())); | |
| 100 } | |
| 101 return std::move(out_dict); | |
| 102 } else if (value.GetAsList(&list)) { | |
|
caseq
2016/03/05 02:25:24
style: no else after return
| |
| 103 scoped_ptr<base::ListValue> out_list(new base::ListValue()); | |
| 104 for (const auto& value : *list) { | |
| 105 out_list->Append(convertDictKeyStyle(*value)); | |
| 106 } | |
| 107 return std::move(out_list); | |
| 108 } else { | |
|
caseq
2016/03/05 02:25:24
ditto.
| |
| 109 return value.CreateDeepCopy(); | |
| 110 } | |
| 111 } | |
| 112 | |
| 75 } // namespace | 113 } // namespace |
| 76 | 114 |
| 115 // static | |
| 116 scoped_ptr<base::DictionaryValue> TraceConfig::DevToolsToTracingStyle( | |
| 117 const scoped_ptr<base::DictionaryValue>& devtools_style) { | |
| 118 scoped_ptr<base::Value> value = convertDictKeyStyle(*devtools_style); | |
| 119 | |
| 120 DCHECK(value->IsType(base::Value::TYPE_DICTIONARY)); | |
| 121 scoped_ptr<base::DictionaryValue> tracing_style( | |
| 122 static_cast<base::DictionaryValue*>(value.release())); | |
| 123 | |
| 124 std::string mode; | |
| 125 if (tracing_style->GetString(kRecordModeParam, &mode)) | |
| 126 tracing_style->SetString(kRecordModeParam, convertStringStyle(mode, '-')); | |
| 127 | |
| 128 return tracing_style; | |
| 129 } | |
| 130 | |
| 131 // static | |
| 132 std::string TraceConfig::DevToolsToTracingStyle( | |
| 133 const std::string& devtools_style) { | |
| 134 scoped_ptr<Value> value = base::JSONReader::Read(devtools_style); | |
| 135 DCHECK(value && value->IsType(base::Value::TYPE_DICTIONARY)); | |
| 136 | |
| 137 scoped_ptr<base::DictionaryValue> devtools_style_dict( | |
| 138 static_cast<base::DictionaryValue*>(value.release())); | |
| 139 scoped_ptr<base::DictionaryValue> tracing_style_dict = | |
| 140 DevToolsToTracingStyle(devtools_style_dict); | |
| 141 | |
| 142 std::string tracing_style; | |
| 143 base::JSONWriter::Write(*tracing_style_dict, &tracing_style); | |
| 144 return tracing_style; | |
| 145 } | |
| 146 | |
| 77 TraceConfig::TraceConfig() { | 147 TraceConfig::TraceConfig() { |
| 78 InitializeDefault(); | 148 InitializeDefault(); |
| 79 } | 149 } |
| 80 | 150 |
| 81 TraceConfig::TraceConfig(const std::string& category_filter_string, | 151 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| 82 const std::string& trace_options_string) { | 152 const std::string& trace_options_string) { |
| 83 InitializeFromStrings(category_filter_string, trace_options_string); | 153 InitializeFromStrings(category_filter_string, trace_options_string); |
| 84 } | 154 } |
| 85 | 155 |
| 86 TraceConfig::TraceConfig(const std::string& category_filter_string, | 156 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 str.at(0) == ' ' || | 730 str.at(0) == ' ' || |
| 661 str.at(str.length() - 1) == ' '; | 731 str.at(str.length() - 1) == ' '; |
| 662 } | 732 } |
| 663 | 733 |
| 664 bool TraceConfig::HasIncludedPatterns() const { | 734 bool TraceConfig::HasIncludedPatterns() const { |
| 665 return !included_categories_.empty(); | 735 return !included_categories_.empty(); |
| 666 } | 736 } |
| 667 | 737 |
| 668 } // namespace trace_event | 738 } // namespace trace_event |
| 669 } // namespace base | 739 } // namespace base |
| OLD | NEW |