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

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: fix gn config. 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
« no previous file with comments | « content/browser/tracing/tracing_ui.h ('k') | content/browser/tracing/tracing_ui_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 trace_uploader_ = delegate_->GetTraceUploader( 246 trace_uploader_ = delegate_->GetTraceUploader(
293 BrowserContext::GetDefaultStoragePartition( 247 BrowserContext::GetDefaultStoragePartition(
294 web_ui()->GetWebContents()->GetBrowserContext())-> 248 web_ui()->GetWebContents()->GetBrowserContext())->
295 GetURLRequestContext()); 249 GetURLRequestContext());
296 DCHECK(trace_uploader_); 250 DCHECK(trace_uploader_);
297 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr, 251 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr,
298 progress_callback, done_callback); 252 progress_callback, done_callback);
299 // TODO(mmandlis): Add support for stopping the upload in progress. 253 // TODO(mmandlis): Add support for stopping the upload in progress.
300 } 254 }
301 255
256 // static
257 bool TracingUI::GetTracingOptions(
258 const std::string& data64,
259 base::trace_event::TraceConfig* trace_config) {
260 std::string data;
261 if (!base::Base64Decode(data64, &data)) {
262 LOG(ERROR) << "Options were not base64 encoded.";
263 return false;
264 }
265
266 std::unique_ptr<base::Value> optionsRaw = base::JSONReader::Read(data);
267 if (!optionsRaw) {
268 LOG(ERROR) << "Options were not valid JSON";
269 return false;
270 }
271 base::DictionaryValue* options;
272 if (!optionsRaw->GetAsDictionary(&options)) {
273 LOG(ERROR) << "Options must be dict";
274 return false;
275 }
276
277 if (!trace_config) {
278 LOG(ERROR) << "trace_config can't be passed as NULL";
279 return false;
280 }
281
282 // New style options dictionary.
283 if (options->HasKey("included_categories")) {
284 *trace_config = base::trace_event::TraceConfig(*options);
285 return true;
286 }
287
288 bool options_ok = true;
289 std::string category_filter_string;
290 options_ok &= options->GetString("categoryFilter", &category_filter_string);
291
292 std::string record_mode;
293 options_ok &= options->GetString("tracingRecordMode", &record_mode);
294
295 *trace_config =
296 base::trace_event::TraceConfig(category_filter_string, record_mode);
297
298 bool enable_systrace;
299 options_ok &= options->GetBoolean("useSystemTracing", &enable_systrace);
300 if (enable_systrace)
301 trace_config->EnableSystrace();
302
303 if (!options_ok) {
304 LOG(ERROR) << "Malformed options";
305 return false;
306 }
307 return true;
308 }
309
302 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) { 310 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) {
303 DCHECK(current <= total); 311 DCHECK(current <= total);
304 int percent = (current / total) * 100; 312 int percent = (current / total) * 100;
305 web_ui()->CallJavascriptFunctionUnsafe( 313 web_ui()->CallJavascriptFunctionUnsafe(
306 "onUploadProgress", base::Value(percent), 314 "onUploadProgress", base::Value(percent),
307 base::Value(base::StringPrintf("%" PRId64, current)), 315 base::Value(base::StringPrintf("%" PRId64, current)),
308 base::Value(base::StringPrintf("%" PRId64, total))); 316 base::Value(base::StringPrintf("%" PRId64, total)));
309 } 317 }
310 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
« no previous file with comments | « content/browser/tracing/tracing_ui.h ('k') | content/browser/tracing/tracing_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698