Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Unified Diff: base/trace_event/trace_config.cc

Issue 1765153002: Update DevTools Tracing.Start to accept trace config as a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
}

Powered by Google App Engine
This is Rietveld 408576698