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 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/debug/trace_event.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
17 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
18 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/values.h" | 25 #include "base/values.h" |
(...skipping 22 matching lines...) Expand all Loading... |
47 it != categorySet.end(); it++) { | 48 it != categorySet.end(); it++) { |
48 category_list->AppendString(*it); | 49 category_list->AppendString(*it); |
49 } | 50 } |
50 | 51 |
51 base::RefCountedString* res = new base::RefCountedString(); | 52 base::RefCountedString* res = new base::RefCountedString(); |
52 base::JSONWriter::Write(category_list.get(), &res->data()); | 53 base::JSONWriter::Write(category_list.get(), &res->data()); |
53 callback.Run(res); | 54 callback.Run(res); |
54 } | 55 } |
55 | 56 |
56 bool GetTracingOptions(const std::string& data64, | 57 bool GetTracingOptions(const std::string& data64, |
57 std::string* category_filter_string, | 58 base::debug::CategoryFilter* category_filter, |
58 int* tracing_options) { | 59 base::debug::TraceOptions* tracing_options) { |
59 std::string data; | 60 std::string data; |
60 if (!base::Base64Decode(data64, &data)) { | 61 if (!base::Base64Decode(data64, &data)) { |
61 LOG(ERROR) << "Options were not base64 encoded."; | 62 LOG(ERROR) << "Options were not base64 encoded."; |
62 return false; | 63 return false; |
63 } | 64 } |
64 | 65 |
65 scoped_ptr<base::Value> optionsRaw(base::JSONReader::Read(data)); | 66 scoped_ptr<base::Value> optionsRaw(base::JSONReader::Read(data)); |
66 if (!optionsRaw) { | 67 if (!optionsRaw) { |
67 LOG(ERROR) << "Options were not valid JSON"; | 68 LOG(ERROR) << "Options were not valid JSON"; |
68 return false; | 69 return false; |
69 } | 70 } |
70 base::DictionaryValue* options; | 71 base::DictionaryValue* options; |
71 if (!optionsRaw->GetAsDictionary(&options)) { | 72 if (!optionsRaw->GetAsDictionary(&options)) { |
72 LOG(ERROR) << "Options must be dict"; | 73 LOG(ERROR) << "Options must be dict"; |
73 return false; | 74 return false; |
74 } | 75 } |
75 | 76 |
76 bool use_system_tracing; | 77 if (!category_filter) { |
77 bool use_continuous_tracing; | 78 LOG(ERROR) << "category_filter can't be passed as NULL"; |
78 bool use_sampling; | 79 return false; |
| 80 } |
| 81 |
| 82 if (!tracing_options) { |
| 83 LOG(ERROR) << "tracing_options can't be passed as NULL"; |
| 84 return false; |
| 85 } |
79 | 86 |
80 bool options_ok = true; | 87 bool options_ok = true; |
81 options_ok &= options->GetString("categoryFilter", category_filter_string); | 88 std::string category_filter_string; |
82 options_ok &= options->GetBoolean("useSystemTracing", &use_system_tracing); | 89 options_ok &= options->GetString("categoryFilter", &category_filter_string); |
83 options_ok &= options->GetBoolean("useContinuousTracing", | 90 *category_filter = base::debug::CategoryFilter(category_filter_string); |
84 &use_continuous_tracing); | 91 |
85 options_ok &= options->GetBoolean("useSampling", &use_sampling); | 92 options_ok &= options->GetBoolean("useSystemTracing", |
| 93 &tracing_options->enable_systrace); |
| 94 options_ok &= |
| 95 options->GetBoolean("useSampling", &tracing_options->enable_sampling); |
| 96 |
| 97 bool use_continuous_tracing; |
| 98 options_ok &= |
| 99 options->GetBoolean("useContinuousTracing", &use_continuous_tracing); |
| 100 |
| 101 if (use_continuous_tracing) |
| 102 tracing_options->record_mode = base::debug::RECORD_CONTINUOUSLY; |
| 103 else |
| 104 tracing_options->record_mode = base::debug::RECORD_UNTIL_FULL; |
| 105 |
86 if (!options_ok) { | 106 if (!options_ok) { |
87 LOG(ERROR) << "Malformed options"; | 107 LOG(ERROR) << "Malformed options"; |
88 return false; | 108 return false; |
89 } | 109 } |
90 | |
91 *tracing_options = 0; | |
92 if (use_system_tracing) | |
93 *tracing_options |= TracingController::ENABLE_SYSTRACE; | |
94 if (use_sampling) | |
95 *tracing_options |= TracingController::ENABLE_SAMPLING; | |
96 if (use_continuous_tracing) | |
97 *tracing_options |= TracingController::RECORD_CONTINUOUSLY; | |
98 return true; | 110 return true; |
99 } | 111 } |
100 | 112 |
101 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 113 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
102 | 114 |
103 bool BeginRecording(const std::string& data64, | 115 bool BeginRecording(const std::string& data64, |
104 const WebUIDataSource::GotDataCallback& callback) { | 116 const WebUIDataSource::GotDataCallback& callback) { |
105 std::string category_filter_string; | 117 base::debug::CategoryFilter category_filter(""); |
106 int tracing_options = 0; | 118 base::debug::TraceOptions tracing_options; |
107 if (!GetTracingOptions(data64, &category_filter_string, &tracing_options)) | 119 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) |
108 return false; | 120 return false; |
109 | 121 |
110 return TracingController::GetInstance()->EnableRecording( | 122 return TracingController::GetInstance()->EnableRecording( |
111 category_filter_string, | 123 category_filter, |
112 static_cast<TracingController::Options>(tracing_options), | 124 tracing_options, |
113 base::Bind(&OnRecordingEnabledAck, callback)); | 125 base::Bind(&OnRecordingEnabledAck, callback)); |
114 } | 126 } |
115 | 127 |
116 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 128 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
117 base::RefCountedString* res = new base::RefCountedString(); | 129 base::RefCountedString* res = new base::RefCountedString(); |
118 callback.Run(res); | 130 callback.Run(res); |
119 } | 131 } |
120 | 132 |
121 void OnTraceBufferPercentFullResult( | 133 void OnTraceBufferPercentFullResult( |
122 const WebUIDataSource::GotDataCallback& callback, float result) { | 134 const WebUIDataSource::GotDataCallback& callback, float result) { |
(...skipping 15 matching lines...) Expand all Loading... |
138 const base::FilePath& path) { | 150 const base::FilePath& path) { |
139 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
140 BrowserThread::FILE, FROM_HERE, | 152 BrowserThread::FILE, FROM_HERE, |
141 base::Bind(ReadRecordingResult, callback, path)); | 153 base::Bind(ReadRecordingResult, callback, path)); |
142 } | 154 } |
143 | 155 |
144 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 156 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
145 | 157 |
146 bool EnableMonitoring(const std::string& data64, | 158 bool EnableMonitoring(const std::string& data64, |
147 const WebUIDataSource::GotDataCallback& callback) { | 159 const WebUIDataSource::GotDataCallback& callback) { |
148 std::string category_filter_string; | 160 base::debug::TraceOptions tracing_options; |
149 int tracing_options = 0; | 161 base::debug::CategoryFilter category_filter(""); |
150 if (!GetTracingOptions(data64, &category_filter_string, &tracing_options)) | 162 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) |
151 return false; | 163 return false; |
152 | 164 |
153 return TracingController::GetInstance()->EnableMonitoring( | 165 return TracingController::GetInstance()->EnableMonitoring( |
154 category_filter_string, | 166 category_filter, |
155 static_cast<TracingController::Options>(tracing_options), | 167 tracing_options, |
156 base::Bind(OnMonitoringEnabledAck, callback)); | 168 base::Bind(OnMonitoringEnabledAck, callback)); |
157 } | 169 } |
158 | 170 |
159 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 171 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
160 base::RefCountedString* res = new base::RefCountedString(); | 172 base::RefCountedString* res = new base::RefCountedString(); |
161 callback.Run(res); | 173 callback.Run(res); |
162 } | 174 } |
163 | 175 |
164 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { | 176 void OnMonitoringDisabled(const WebUIDataSource::GotDataCallback& callback) { |
165 base::RefCountedString* res = new base::RefCountedString(); | 177 base::RefCountedString* res = new base::RefCountedString(); |
166 callback.Run(res); | 178 callback.Run(res); |
167 } | 179 } |
168 | 180 |
169 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { | 181 void GetMonitoringStatus(const WebUIDataSource::GotDataCallback& callback) { |
170 bool is_monitoring; | 182 bool is_monitoring; |
171 std::string category_filter; | 183 base::debug::CategoryFilter category_filter(""); |
172 TracingController::Options options; | 184 base::debug::TraceOptions options; |
173 TracingController::GetInstance()->GetMonitoringStatus( | 185 TracingController::GetInstance()->GetMonitoringStatus( |
174 &is_monitoring, &category_filter, &options); | 186 &is_monitoring, &category_filter, &options); |
175 | 187 |
176 scoped_ptr<base::DictionaryValue> | 188 scoped_ptr<base::DictionaryValue> |
177 monitoring_options(new base::DictionaryValue()); | 189 monitoring_options(new base::DictionaryValue()); |
178 monitoring_options->SetBoolean("isMonitoring", is_monitoring); | 190 monitoring_options->SetBoolean("isMonitoring", is_monitoring); |
179 monitoring_options->SetString("categoryFilter", category_filter); | 191 monitoring_options->SetString("categoryFilter", category_filter.ToString()); |
180 monitoring_options->SetBoolean("useSystemTracing", | 192 monitoring_options->SetBoolean("useSystemTracing", options.enable_systrace); |
181 (options & TracingController::ENABLE_SYSTRACE) != 0); | 193 monitoring_options->SetBoolean( |
182 monitoring_options->SetBoolean("useContinuousTracing", | 194 "useContinuousTracing", |
183 (options & TracingController::RECORD_CONTINUOUSLY) != 0); | 195 options.record_mode == base::debug::RECORD_CONTINUOUSLY); |
184 monitoring_options->SetBoolean("useSampling", | 196 monitoring_options->SetBoolean("useSampling", options.enable_sampling); |
185 (options & TracingController::ENABLE_SAMPLING) != 0); | |
186 | 197 |
187 std::string monitoring_options_json; | 198 std::string monitoring_options_json; |
188 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json); | 199 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json); |
189 | 200 |
190 base::RefCountedString* monitoring_options_base64 = | 201 base::RefCountedString* monitoring_options_base64 = |
191 new base::RefCountedString(); | 202 new base::RefCountedString(); |
192 base::Base64Encode(monitoring_options_json, | 203 base::Base64Encode(monitoring_options_json, |
193 &monitoring_options_base64->data()); | 204 &monitoring_options_base64->data()); |
194 callback.Run(monitoring_options_base64); | 205 callback.Run(monitoring_options_base64); |
195 } | 206 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (success) { | 404 if (success) { |
394 web_ui()->CallJavascriptFunction("onUploadComplete", | 405 web_ui()->CallJavascriptFunction("onUploadComplete", |
395 base::StringValue(report_id)); | 406 base::StringValue(report_id)); |
396 } else { | 407 } else { |
397 web_ui()->CallJavascriptFunction("onUploadError", | 408 web_ui()->CallJavascriptFunction("onUploadError", |
398 base::StringValue(error_message)); | 409 base::StringValue(error_message)); |
399 } | 410 } |
400 } | 411 } |
401 | 412 |
402 } // namespace content | 413 } // namespace content |
OLD | NEW |