Index: base/trace_event/trace_config.cc |
diff --git a/base/trace_event/trace_config.cc b/base/trace_event/trace_config.cc |
index d60c08124d29be4e5e65395eabec108da00cade8..91b6df19faa88960f62b2464ef0873b39f6b8af9 100644 |
--- a/base/trace_event/trace_config.cc |
+++ b/base/trace_event/trace_config.cc |
@@ -72,8 +72,78 @@ class ConvertableTraceConfigToTraceFormat |
const TraceConfig trace_config_; |
}; |
+// Convert each uppercase character to separator + lowercase. |
+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
|
+ const char& separator) { |
caseq
2016/03/05 02:25:24
no need to pass a char by reference :)
|
+ std::string out_str; |
+ for (const char& c : in_str) { |
+ if (isupper(c)) { |
+ out_str.push_back(separator); |
+ out_str.push_back(tolower(c)); |
+ } else { |
+ out_str.push_back(c); |
+ } |
+ } |
+ return out_str; |
+} |
+ |
+scoped_ptr<base::Value> convertDictKeyStyle(const base::Value& value) { |
caseq
2016/03/05 02:25:24
style: s/convert/Convert/
|
+ const base::DictionaryValue* dict = NULL; |
caseq
2016/03/05 02:25:24
nit: nullptr
|
+ const base::ListValue* list = NULL; |
caseq
2016/03/05 02:25:24
ditto (and please move down to actual usage)
|
+ |
+ if (value.GetAsDictionary(&dict)) { |
+ scoped_ptr<base::DictionaryValue> out_dict(new base::DictionaryValue()); |
+ for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
+ it.Advance()) { |
+ out_dict->Set(convertStringStyle(it.key(), '_'), |
+ convertDictKeyStyle(it.value())); |
+ } |
+ return std::move(out_dict); |
+ } else if (value.GetAsList(&list)) { |
caseq
2016/03/05 02:25:24
style: no else after return
|
+ scoped_ptr<base::ListValue> out_list(new base::ListValue()); |
+ for (const auto& value : *list) { |
+ out_list->Append(convertDictKeyStyle(*value)); |
+ } |
+ return std::move(out_list); |
+ } else { |
caseq
2016/03/05 02:25:24
ditto.
|
+ return value.CreateDeepCopy(); |
+ } |
+} |
+ |
} // namespace |
+// static |
+scoped_ptr<base::DictionaryValue> TraceConfig::DevToolsToTracingStyle( |
+ const scoped_ptr<base::DictionaryValue>& devtools_style) { |
+ scoped_ptr<base::Value> value = convertDictKeyStyle(*devtools_style); |
+ |
+ DCHECK(value->IsType(base::Value::TYPE_DICTIONARY)); |
+ scoped_ptr<base::DictionaryValue> tracing_style( |
+ static_cast<base::DictionaryValue*>(value.release())); |
+ |
+ std::string mode; |
+ if (tracing_style->GetString(kRecordModeParam, &mode)) |
+ tracing_style->SetString(kRecordModeParam, convertStringStyle(mode, '-')); |
+ |
+ return tracing_style; |
+} |
+ |
+// static |
+std::string TraceConfig::DevToolsToTracingStyle( |
+ const std::string& devtools_style) { |
+ scoped_ptr<Value> value = base::JSONReader::Read(devtools_style); |
+ DCHECK(value && value->IsType(base::Value::TYPE_DICTIONARY)); |
+ |
+ scoped_ptr<base::DictionaryValue> devtools_style_dict( |
+ static_cast<base::DictionaryValue*>(value.release())); |
+ scoped_ptr<base::DictionaryValue> tracing_style_dict = |
+ DevToolsToTracingStyle(devtools_style_dict); |
+ |
+ std::string tracing_style; |
+ base::JSONWriter::Write(*tracing_style_dict, &tracing_style); |
+ return tracing_style; |
+} |
+ |
TraceConfig::TraceConfig() { |
InitializeDefault(); |
} |