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

Side by Side Diff: content/browser/tracing/tracing_ui.cc

Issue 2948033004: Add a second format to the tracing json/begin_recording endpoint. (Closed)
Patch Set: remove unnecessary flag. Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 for (std::set<std::string>::const_iterator it = categorySet.begin(); 48 for (std::set<std::string>::const_iterator it = categorySet.begin();
49 it != categorySet.end(); it++) { 49 it != categorySet.end(); it++) {
50 category_list.AppendString(*it); 50 category_list.AppendString(*it);
51 } 51 }
52 52
53 scoped_refptr<base::RefCountedString> res(new base::RefCountedString()); 53 scoped_refptr<base::RefCountedString> res(new base::RefCountedString());
54 base::JSONWriter::Write(category_list, &res->data()); 54 base::JSONWriter::Write(category_list, &res->data());
55 callback.Run(res); 55 callback.Run(res);
56 } 56 }
57 57
58 bool GetTracingOptions(const std::string& data64,
59 base::trace_event::TraceConfig* trace_config) {
60 std::string data;
61 if (!base::Base64Decode(data64, &data)) {
62 LOG(ERROR) << "Options were not base64 encoded.";
63 return false;
64 }
65
66 std::unique_ptr<base::Value> optionsRaw = base::JSONReader::Read(data);
67 if (!optionsRaw) {
68 LOG(ERROR) << "Options were not valid JSON";
69 return false;
70 }
71 base::DictionaryValue* options;
72 if (!optionsRaw->GetAsDictionary(&options)) {
73 LOG(ERROR) << "Options must be dict";
74 return false;
75 }
76
77 if (!trace_config) {
78 LOG(ERROR) << "trace_config can't be passed as NULL";
79 return false;
80 }
81
82 bool options_ok = true;
83 std::string category_filter_string;
84 options_ok &= options->GetString("categoryFilter", &category_filter_string);
85
86 std::string record_mode;
87 options_ok &= options->GetString("tracingRecordMode", &record_mode);
88
89 *trace_config = base::trace_event::TraceConfig(category_filter_string,
90 record_mode);
91
92 bool enable_systrace;
93 options_ok &= options->GetBoolean("useSystemTracing", &enable_systrace);
94 if (enable_systrace)
95 trace_config->EnableSystrace();
96
97 if (!options_ok) {
98 LOG(ERROR) << "Malformed options";
99 return false;
100 }
101 return true;
102 }
103
104 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); 58 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback);
105 59
106 bool BeginRecording(const std::string& data64, 60 bool BeginRecording(const std::string& data64,
107 const WebUIDataSource::GotDataCallback& callback) { 61 const WebUIDataSource::GotDataCallback& callback) {
108 base::trace_event::TraceConfig trace_config("", ""); 62 base::trace_event::TraceConfig trace_config("", "");
109 if (!GetTracingOptions(data64, &trace_config)) 63 if (!TracingUI::GetTracingOptions(data64, &trace_config))
110 return false; 64 return false;
111 65
112 return TracingController::GetInstance()->StartTracing( 66 return TracingController::GetInstance()->StartTracing(
113 trace_config, 67 trace_config,
114 base::Bind(&OnRecordingEnabledAck, callback)); 68 base::Bind(&OnRecordingEnabledAck, callback));
115 } 69 }
116 70
117 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { 71 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) {
118 callback.Run( 72 callback.Run(
119 scoped_refptr<base::RefCountedMemory>(new base::RefCountedString())); 73 scoped_refptr<base::RefCountedMemory>(new base::RefCountedString()));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 255
302 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) { 256 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) {
303 DCHECK(current <= total); 257 DCHECK(current <= total);
304 int percent = (current / total) * 100; 258 int percent = (current / total) * 100;
305 web_ui()->CallJavascriptFunctionUnsafe( 259 web_ui()->CallJavascriptFunctionUnsafe(
306 "onUploadProgress", base::Value(percent), 260 "onUploadProgress", base::Value(percent),
307 base::Value(base::StringPrintf("%" PRId64, current)), 261 base::Value(base::StringPrintf("%" PRId64, current)),
308 base::Value(base::StringPrintf("%" PRId64, total))); 262 base::Value(base::StringPrintf("%" PRId64, total)));
309 } 263 }
310 264
265 // static
266 bool TracingUI::GetTracingOptions(
267 const std::string& data64,
268 base::trace_event::TraceConfig* trace_config) {
269 std::string data;
270 if (!base::Base64Decode(data64, &data)) {
271 LOG(ERROR) << "Options were not base64 encoded.";
272 return false;
273 }
274
275 std::unique_ptr<base::Value> optionsRaw = base::JSONReader::Read(data);
276 if (!optionsRaw) {
277 LOG(ERROR) << "Options were not valid JSON";
278 return false;
279 }
280 base::DictionaryValue* options;
281 if (!optionsRaw->GetAsDictionary(&options)) {
282 LOG(ERROR) << "Options must be dict";
283 return false;
284 }
285
286 if (!trace_config) {
287 LOG(ERROR) << "trace_config can't be passed as NULL";
288 return false;
289 }
290
291 // New style options dictionary.
292 if (options->HasKey("included_categories")) {
293 *trace_config = base::trace_event::TraceConfig(*options);
294 return true;
295 }
296
297 bool options_ok = true;
298 std::string category_filter_string;
299 options_ok &= options->GetString("categoryFilter", &category_filter_string);
300
301 std::string record_mode;
302 options_ok &= options->GetString("tracingRecordMode", &record_mode);
303
304 *trace_config =
305 base::trace_event::TraceConfig(category_filter_string, record_mode);
306
307 bool enable_systrace;
308 options_ok &= options->GetBoolean("useSystemTracing", &enable_systrace);
309 if (enable_systrace)
310 trace_config->EnableSystrace();
311
312 if (!options_ok) {
313 LOG(ERROR) << "Malformed options";
314 return false;
315 }
316 return true;
317 }
318
311 void TracingUI::OnTraceUploadComplete(bool success, 319 void TracingUI::OnTraceUploadComplete(bool success,
312 const std::string& feedback) { 320 const std::string& feedback) {
313 if (success) { 321 if (success) {
314 web_ui()->CallJavascriptFunctionUnsafe("onUploadComplete", 322 web_ui()->CallJavascriptFunctionUnsafe("onUploadComplete",
315 base::Value(feedback)); 323 base::Value(feedback));
316 } else { 324 } else {
317 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", 325 web_ui()->CallJavascriptFunctionUnsafe("onUploadError",
318 base::Value(feedback)); 326 base::Value(feedback));
319 } 327 }
320 trace_uploader_.reset(); 328 trace_uploader_.reset();
321 } 329 }
322 330
323 } // namespace content 331 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698