| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/tracing/tracing_ui.h" | 5 #include "content/browser/tracing/tracing_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 it != categorySet.end(); it++) { | 45 it != categorySet.end(); it++) { |
| 46 category_list.AppendString(*it); | 46 category_list.AppendString(*it); |
| 47 } | 47 } |
| 48 | 48 |
| 49 base::RefCountedString* res = new base::RefCountedString(); | 49 base::RefCountedString* res = new base::RefCountedString(); |
| 50 base::JSONWriter::Write(category_list, &res->data()); | 50 base::JSONWriter::Write(category_list, &res->data()); |
| 51 callback.Run(res); | 51 callback.Run(res); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool GetTracingOptions(const std::string& data64, | 54 bool GetTracingOptions(const std::string& data64, |
| 55 base::trace_event::CategoryFilter* category_filter, | 55 base::trace_event::TraceConfig* trace_config) { |
| 56 base::trace_event::TraceOptions* tracing_options) { | |
| 57 std::string data; | 56 std::string data; |
| 58 if (!base::Base64Decode(data64, &data)) { | 57 if (!base::Base64Decode(data64, &data)) { |
| 59 LOG(ERROR) << "Options were not base64 encoded."; | 58 LOG(ERROR) << "Options were not base64 encoded."; |
| 60 return false; | 59 return false; |
| 61 } | 60 } |
| 62 | 61 |
| 63 scoped_ptr<base::Value> optionsRaw = base::JSONReader::Read(data); | 62 scoped_ptr<base::Value> optionsRaw = base::JSONReader::Read(data); |
| 64 if (!optionsRaw) { | 63 if (!optionsRaw) { |
| 65 LOG(ERROR) << "Options were not valid JSON"; | 64 LOG(ERROR) << "Options were not valid JSON"; |
| 66 return false; | 65 return false; |
| 67 } | 66 } |
| 68 base::DictionaryValue* options; | 67 base::DictionaryValue* options; |
| 69 if (!optionsRaw->GetAsDictionary(&options)) { | 68 if (!optionsRaw->GetAsDictionary(&options)) { |
| 70 LOG(ERROR) << "Options must be dict"; | 69 LOG(ERROR) << "Options must be dict"; |
| 71 return false; | 70 return false; |
| 72 } | 71 } |
| 73 | 72 |
| 74 if (!category_filter) { | 73 if (!trace_config) { |
| 75 LOG(ERROR) << "category_filter can't be passed as NULL"; | 74 LOG(ERROR) << "trace_config can't be passed as NULL"; |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 if (!tracing_options) { | |
| 80 LOG(ERROR) << "tracing_options can't be passed as NULL"; | |
| 81 return false; | 75 return false; |
| 82 } | 76 } |
| 83 | 77 |
| 84 bool options_ok = true; | 78 bool options_ok = true; |
| 85 std::string category_filter_string; | 79 std::string category_filter_string; |
| 86 options_ok &= options->GetString("categoryFilter", &category_filter_string); | 80 options_ok &= options->GetString("categoryFilter", &category_filter_string); |
| 87 *category_filter = base::trace_event::CategoryFilter(category_filter_string); | |
| 88 | 81 |
| 89 std::string record_mode; | 82 std::string record_mode; |
| 90 options_ok &= | 83 options_ok &= options->GetString("tracingRecordMode", &record_mode); |
| 91 options->GetString("tracingRecordMode", &record_mode); | |
| 92 options_ok &= tracing_options->SetFromString(record_mode); | |
| 93 | 84 |
| 94 options_ok &= options->GetBoolean("useSystemTracing", | 85 *trace_config = base::trace_event::TraceConfig(category_filter_string, |
| 95 &tracing_options->enable_systrace); | 86 record_mode); |
| 96 options_ok &= | 87 |
| 97 options->GetBoolean("useSampling", &tracing_options->enable_sampling); | 88 bool enable_systrace; |
| 89 options_ok &= options->GetBoolean("useSystemTracing", &enable_systrace); |
| 90 if (enable_systrace) |
| 91 trace_config->EnableSystrace(); |
| 92 |
| 93 bool enable_sampling; |
| 94 options_ok &= options->GetBoolean("useSampling", &enable_sampling); |
| 95 if (enable_sampling) |
| 96 trace_config->EnableSampling(); |
| 98 | 97 |
| 99 if (!options_ok) { | 98 if (!options_ok) { |
| 100 LOG(ERROR) << "Malformed options"; | 99 LOG(ERROR) << "Malformed options"; |
| 101 return false; | 100 return false; |
| 102 } | 101 } |
| 103 return true; | 102 return true; |
| 104 } | 103 } |
| 105 | 104 |
| 106 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 105 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
| 107 | 106 |
| 108 bool BeginRecording(const std::string& data64, | 107 bool BeginRecording(const std::string& data64, |
| 109 const WebUIDataSource::GotDataCallback& callback) { | 108 const WebUIDataSource::GotDataCallback& callback) { |
| 110 base::trace_event::CategoryFilter category_filter(""); | 109 base::trace_event::TraceConfig trace_config("", ""); |
| 111 base::trace_event::TraceOptions tracing_options; | 110 if (!GetTracingOptions(data64, &trace_config)) |
| 112 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) | |
| 113 return false; | 111 return false; |
| 114 | 112 |
| 115 return TracingController::GetInstance()->EnableRecording( | 113 return TracingController::GetInstance()->EnableRecording( |
| 116 category_filter, | 114 trace_config, |
| 117 tracing_options, | |
| 118 base::Bind(&OnRecordingEnabledAck, callback)); | 115 base::Bind(&OnRecordingEnabledAck, callback)); |
| 119 } | 116 } |
| 120 | 117 |
| 121 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 118 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
| 122 base::RefCountedString* res = new base::RefCountedString(); | 119 base::RefCountedString* res = new base::RefCountedString(); |
| 123 callback.Run(res); | 120 callback.Run(res); |
| 124 } | 121 } |
| 125 | 122 |
| 126 void OnTraceBufferUsageResult(const WebUIDataSource::GotDataCallback& callback, | 123 void OnTraceBufferUsageResult(const WebUIDataSource::GotDataCallback& callback, |
| 127 float percent_full, | 124 float percent_full, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 142 | 139 |
| 143 base::RefCountedString* status_base64 = new base::RefCountedString(); | 140 base::RefCountedString* status_base64 = new base::RefCountedString(); |
| 144 base::Base64Encode(status_json, &status_base64->data()); | 141 base::Base64Encode(status_json, &status_base64->data()); |
| 145 callback.Run(status_base64); | 142 callback.Run(status_base64); |
| 146 } | 143 } |
| 147 | 144 |
| 148 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 145 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
| 149 | 146 |
| 150 bool EnableMonitoring(const std::string& data64, | 147 bool EnableMonitoring(const std::string& data64, |
| 151 const WebUIDataSource::GotDataCallback& callback) { | 148 const WebUIDataSource::GotDataCallback& callback) { |
| 152 base::trace_event::TraceOptions tracing_options; | 149 base::trace_event::TraceConfig trace_config("", ""); |
| 153 base::trace_event::CategoryFilter category_filter(""); | 150 if (!GetTracingOptions(data64, &trace_config)) |
| 154 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) | |
| 155 return false; | 151 return false; |
| 156 | 152 |
| 157 return TracingController::GetInstance()->EnableMonitoring( | 153 return TracingController::GetInstance()->EnableMonitoring( |
| 158 category_filter, | 154 trace_config, |
| 159 tracing_options, | |
| 160 base::Bind(OnMonitoringEnabledAck, callback)); | 155 base::Bind(OnMonitoringEnabledAck, callback)); |
| 161 } | 156 } |
| 162 | 157 |
| 163 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 158 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
| 164 base::RefCountedString* res = new base::RefCountedString(); | 159 base::RefCountedString* res = new base::RefCountedString(); |
| 165 callback.Run(res); | 160 callback.Run(res); |
| 166 } | 161 } |
| 167 | 162 |
| 168 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { | 163 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { |
| 169 base::RefCountedString* res = new base::RefCountedString(); | 164 base::RefCountedString* res = new base::RefCountedString(); |
| 170 callback.Run(res); | 165 callback.Run(res); |
| 171 } | 166 } |
| 172 | 167 |
| 173 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { | 168 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { |
| 174 bool is_monitoring; | 169 bool is_monitoring; |
| 175 base::trace_event::CategoryFilter category_filter(""); | 170 base::trace_event::TraceConfig config("", ""); |
| 176 base::trace_event::TraceOptions options; | |
| 177 TracingController::GetInstance()->GetMonitoringStatus( | 171 TracingController::GetInstance()->GetMonitoringStatus( |
| 178 &is_monitoring, &category_filter, &options); | 172 &is_monitoring, &config); |
| 179 | 173 |
| 180 base::DictionaryValue monitoring_options; | 174 base::DictionaryValue monitoring_options; |
| 181 monitoring_options.SetBoolean("isMonitoring", is_monitoring); | 175 monitoring_options.SetBoolean("isMonitoring", is_monitoring); |
| 182 monitoring_options.SetString("categoryFilter", category_filter.ToString()); | 176 monitoring_options.SetString("categoryFilter", |
| 183 monitoring_options.SetBoolean("useSystemTracing", options.enable_systrace); | 177 config.ToCategoryFilterString()); |
| 178 monitoring_options.SetBoolean("useSystemTracing", config.IsSystraceEnabled()); |
| 184 monitoring_options.SetBoolean( | 179 monitoring_options.SetBoolean( |
| 185 "useContinuousTracing", | 180 "useContinuousTracing", |
| 186 options.record_mode == base::trace_event::RECORD_CONTINUOUSLY); | 181 config.GetTraceRecordMode() == base::trace_event::RECORD_CONTINUOUSLY); |
| 187 monitoring_options.SetBoolean("useSampling", options.enable_sampling); | 182 monitoring_options.SetBoolean("useSampling", config.IsSamplingEnabled()); |
| 188 | 183 |
| 189 std::string monitoring_options_json; | 184 std::string monitoring_options_json; |
| 190 base::JSONWriter::Write(monitoring_options, &monitoring_options_json); | 185 base::JSONWriter::Write(monitoring_options, &monitoring_options_json); |
| 191 | 186 |
| 192 base::RefCountedString* monitoring_options_base64 = | 187 base::RefCountedString* monitoring_options_base64 = |
| 193 new base::RefCountedString(); | 188 new base::RefCountedString(); |
| 194 base::Base64Encode(monitoring_options_json, | 189 base::Base64Encode(monitoring_options_json, |
| 195 &monitoring_options_base64->data()); | 190 &monitoring_options_base64->data()); |
| 196 callback.Run(monitoring_options_base64); | 191 callback.Run(monitoring_options_base64); |
| 197 } | 192 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 web_ui()->CallJavascriptFunction("onUploadComplete", | 347 web_ui()->CallJavascriptFunction("onUploadComplete", |
| 353 base::StringValue(feedback)); | 348 base::StringValue(feedback)); |
| 354 } else { | 349 } else { |
| 355 web_ui()->CallJavascriptFunction("onUploadError", | 350 web_ui()->CallJavascriptFunction("onUploadError", |
| 356 base::StringValue(feedback)); | 351 base::StringValue(feedback)); |
| 357 } | 352 } |
| 358 trace_uploader_.reset(); | 353 trace_uploader_.reset(); |
| 359 } | 354 } |
| 360 | 355 |
| 361 } // namespace content | 356 } // namespace content |
| OLD | NEW |