| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 it != categorySet.end(); it++) { | 47 it != categorySet.end(); it++) { |
| 48 category_list->AppendString(*it); | 48 category_list->AppendString(*it); |
| 49 } | 49 } |
| 50 | 50 |
| 51 base::RefCountedString* res = new base::RefCountedString(); | 51 base::RefCountedString* res = new base::RefCountedString(); |
| 52 base::JSONWriter::Write(category_list.get(), &res->data()); | 52 base::JSONWriter::Write(category_list.get(), &res->data()); |
| 53 callback.Run(res); | 53 callback.Run(res); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool GetTracingOptions(const std::string& data64, | 56 bool GetTracingOptions(const std::string& data64, |
| 57 base::debug::CategoryFilter* category_filter, | 57 base::trace_event::CategoryFilter* category_filter, |
| 58 base::debug::TraceOptions* tracing_options) { | 58 base::trace_event::TraceOptions* tracing_options) { |
| 59 std::string data; | 59 std::string data; |
| 60 if (!base::Base64Decode(data64, &data)) { | 60 if (!base::Base64Decode(data64, &data)) { |
| 61 LOG(ERROR) << "Options were not base64 encoded."; | 61 LOG(ERROR) << "Options were not base64 encoded."; |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 | 64 |
| 65 scoped_ptr<base::Value> optionsRaw(base::JSONReader::Read(data)); | 65 scoped_ptr<base::Value> optionsRaw(base::JSONReader::Read(data)); |
| 66 if (!optionsRaw) { | 66 if (!optionsRaw) { |
| 67 LOG(ERROR) << "Options were not valid JSON"; | 67 LOG(ERROR) << "Options were not valid JSON"; |
| 68 return false; | 68 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 if (!tracing_options) { | 81 if (!tracing_options) { |
| 82 LOG(ERROR) << "tracing_options can't be passed as NULL"; | 82 LOG(ERROR) << "tracing_options can't be passed as NULL"; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool options_ok = true; | 86 bool options_ok = true; |
| 87 std::string category_filter_string; | 87 std::string category_filter_string; |
| 88 options_ok &= options->GetString("categoryFilter", &category_filter_string); | 88 options_ok &= options->GetString("categoryFilter", &category_filter_string); |
| 89 *category_filter = base::debug::CategoryFilter(category_filter_string); | 89 *category_filter = base::trace_event::CategoryFilter(category_filter_string); |
| 90 | 90 |
| 91 options_ok &= options->GetBoolean("useSystemTracing", | 91 options_ok &= options->GetBoolean("useSystemTracing", |
| 92 &tracing_options->enable_systrace); | 92 &tracing_options->enable_systrace); |
| 93 options_ok &= | 93 options_ok &= |
| 94 options->GetBoolean("useSampling", &tracing_options->enable_sampling); | 94 options->GetBoolean("useSampling", &tracing_options->enable_sampling); |
| 95 | 95 |
| 96 bool use_continuous_tracing; | 96 bool use_continuous_tracing; |
| 97 options_ok &= | 97 options_ok &= |
| 98 options->GetBoolean("useContinuousTracing", &use_continuous_tracing); | 98 options->GetBoolean("useContinuousTracing", &use_continuous_tracing); |
| 99 | 99 |
| 100 if (use_continuous_tracing) | 100 if (use_continuous_tracing) |
| 101 tracing_options->record_mode = base::debug::RECORD_CONTINUOUSLY; | 101 tracing_options->record_mode = base::trace_event::RECORD_CONTINUOUSLY; |
| 102 else | 102 else |
| 103 tracing_options->record_mode = base::debug::RECORD_UNTIL_FULL; | 103 tracing_options->record_mode = base::trace_event::RECORD_UNTIL_FULL; |
| 104 | 104 |
| 105 if (!options_ok) { | 105 if (!options_ok) { |
| 106 LOG(ERROR) << "Malformed options"; | 106 LOG(ERROR) << "Malformed options"; |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 112 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
| 113 | 113 |
| 114 bool BeginRecording(const std::string& data64, | 114 bool BeginRecording(const std::string& data64, |
| 115 const WebUIDataSource::GotDataCallback& callback) { | 115 const WebUIDataSource::GotDataCallback& callback) { |
| 116 base::debug::CategoryFilter category_filter(""); | 116 base::trace_event::CategoryFilter category_filter(""); |
| 117 base::debug::TraceOptions tracing_options; | 117 base::trace_event::TraceOptions tracing_options; |
| 118 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) | 118 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| 121 return TracingController::GetInstance()->EnableRecording( | 121 return TracingController::GetInstance()->EnableRecording( |
| 122 category_filter, | 122 category_filter, |
| 123 tracing_options, | 123 tracing_options, |
| 124 base::Bind(&OnRecordingEnabledAck, callback)); | 124 base::Bind(&OnRecordingEnabledAck, callback)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 127 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 148 | 148 |
| 149 base::RefCountedString* status_base64 = new base::RefCountedString(); | 149 base::RefCountedString* status_base64 = new base::RefCountedString(); |
| 150 base::Base64Encode(status_json, &status_base64->data()); | 150 base::Base64Encode(status_json, &status_base64->data()); |
| 151 callback.Run(status_base64); | 151 callback.Run(status_base64); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 154 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
| 155 | 155 |
| 156 bool EnableMonitoring(const std::string& data64, | 156 bool EnableMonitoring(const std::string& data64, |
| 157 const WebUIDataSource::GotDataCallback& callback) { | 157 const WebUIDataSource::GotDataCallback& callback) { |
| 158 base::debug::TraceOptions tracing_options; | 158 base::trace_event::TraceOptions tracing_options; |
| 159 base::debug::CategoryFilter category_filter(""); | 159 base::trace_event::CategoryFilter category_filter(""); |
| 160 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) | 160 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 return TracingController::GetInstance()->EnableMonitoring( | 163 return TracingController::GetInstance()->EnableMonitoring( |
| 164 category_filter, | 164 category_filter, |
| 165 tracing_options, | 165 tracing_options, |
| 166 base::Bind(OnMonitoringEnabledAck, callback)); | 166 base::Bind(OnMonitoringEnabledAck, callback)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 169 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
| 170 base::RefCountedString* res = new base::RefCountedString(); | 170 base::RefCountedString* res = new base::RefCountedString(); |
| 171 callback.Run(res); | 171 callback.Run(res); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { | 174 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { |
| 175 base::RefCountedString* res = new base::RefCountedString(); | 175 base::RefCountedString* res = new base::RefCountedString(); |
| 176 callback.Run(res); | 176 callback.Run(res); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { | 179 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { |
| 180 bool is_monitoring; | 180 bool is_monitoring; |
| 181 base::debug::CategoryFilter category_filter(""); | 181 base::trace_event::CategoryFilter category_filter(""); |
| 182 base::debug::TraceOptions options; | 182 base::trace_event::TraceOptions options; |
| 183 TracingController::GetInstance()->GetMonitoringStatus( | 183 TracingController::GetInstance()->GetMonitoringStatus( |
| 184 &is_monitoring, &category_filter, &options); | 184 &is_monitoring, &category_filter, &options); |
| 185 | 185 |
| 186 scoped_ptr<base::DictionaryValue> | 186 scoped_ptr<base::DictionaryValue> |
| 187 monitoring_options(new base::DictionaryValue()); | 187 monitoring_options(new base::DictionaryValue()); |
| 188 monitoring_options->SetBoolean("isMonitoring", is_monitoring); | 188 monitoring_options->SetBoolean("isMonitoring", is_monitoring); |
| 189 monitoring_options->SetString("categoryFilter", category_filter.ToString()); | 189 monitoring_options->SetString("categoryFilter", category_filter.ToString()); |
| 190 monitoring_options->SetBoolean("useSystemTracing", options.enable_systrace); | 190 monitoring_options->SetBoolean("useSystemTracing", options.enable_systrace); |
| 191 monitoring_options->SetBoolean( | 191 monitoring_options->SetBoolean( |
| 192 "useContinuousTracing", | 192 "useContinuousTracing", |
| 193 options.record_mode == base::debug::RECORD_CONTINUOUSLY); | 193 options.record_mode == base::trace_event::RECORD_CONTINUOUSLY); |
| 194 monitoring_options->SetBoolean("useSampling", options.enable_sampling); | 194 monitoring_options->SetBoolean("useSampling", options.enable_sampling); |
| 195 | 195 |
| 196 std::string monitoring_options_json; | 196 std::string monitoring_options_json; |
| 197 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json); | 197 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json); |
| 198 | 198 |
| 199 base::RefCountedString* monitoring_options_base64 = | 199 base::RefCountedString* monitoring_options_base64 = |
| 200 new base::RefCountedString(); | 200 new base::RefCountedString(); |
| 201 base::Base64Encode(monitoring_options_json, | 201 base::Base64Encode(monitoring_options_json, |
| 202 &monitoring_options_base64->data()); | 202 &monitoring_options_base64->data()); |
| 203 callback.Run(monitoring_options_base64); | 203 callback.Run(monitoring_options_base64); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 if (success) { | 397 if (success) { |
| 398 web_ui()->CallJavascriptFunction("onUploadComplete", | 398 web_ui()->CallJavascriptFunction("onUploadComplete", |
| 399 base::StringValue(report_id)); | 399 base::StringValue(report_id)); |
| 400 } else { | 400 } else { |
| 401 web_ui()->CallJavascriptFunction("onUploadError", | 401 web_ui()->CallJavascriptFunction("onUploadError", |
| 402 base::StringValue(error_message)); | 402 base::StringValue(error_message)); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 } // namespace content | 406 } // namespace content |
| OLD | NEW |