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

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

Issue 541763002: tracing: get rid of files in TracingController interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed system trace collection Created 6 years, 3 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 <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/debug/trace_event.h"
16 #include "base/files/file_util.h"
17 #include "base/format_macros.h" 16 #include "base/format_macros.h"
18 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
19 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
20 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
21 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
25 #include "base/values.h" 24 #include "base/values.h"
26 #include "content/browser/tracing/grit/tracing_resources.h" 25 #include "content/browser/tracing/grit/tracing_resources.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 base::RefCountedString* res = new base::RefCountedString(); 128 base::RefCountedString* res = new base::RefCountedString();
130 callback.Run(res); 129 callback.Run(res);
131 } 130 }
132 131
133 void OnTraceBufferPercentFullResult( 132 void OnTraceBufferPercentFullResult(
134 const WebUIDataSource::GotDataCallback& callback, float result) { 133 const WebUIDataSource::GotDataCallback& callback, float result) {
135 std::string str = base::DoubleToString(result); 134 std::string str = base::DoubleToString(result);
136 callback.Run(base::RefCountedString::TakeString(&str)); 135 callback.Run(base::RefCountedString::TakeString(&str));
137 } 136 }
138 137
139 void ReadRecordingResult(const WebUIDataSource::GotDataCallback& callback,
140 const base::FilePath& path) {
141 std::string tmp;
142 if (!base::ReadFileToString(path, &tmp))
143 LOG(ERROR) << "Failed to read file " << path.value();
144 base::DeleteFile(path, false);
145 callback.Run(base::RefCountedString::TakeString(&tmp));
146 }
147
148 void BeginReadingRecordingResult(
149 const WebUIDataSource::GotDataCallback& callback,
150 const base::FilePath& path) {
151 BrowserThread::PostTask(
152 BrowserThread::FILE, FROM_HERE,
153 base::Bind(ReadRecordingResult, callback, path));
154 }
155
156 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback); 138 void OnMonitoringEnabledAck(const WebUIDataSource::GotDataCallback& callback);
157 139
158 bool EnableMonitoring(const std::string& data64, 140 bool EnableMonitoring(const std::string& data64,
159 const WebUIDataSource::GotDataCallback& callback) { 141 const WebUIDataSource::GotDataCallback& callback) {
160 base::debug::TraceOptions tracing_options; 142 base::debug::TraceOptions tracing_options;
161 base::debug::CategoryFilter category_filter(""); 143 base::debug::CategoryFilter category_filter("");
162 if (!GetTracingOptions(data64, &category_filter, &tracing_options)) 144 if (!GetTracingOptions(data64, &category_filter, &tracing_options))
163 return false; 145 return false;
164 146
165 return TracingController::GetInstance()->EnableMonitoring( 147 return TracingController::GetInstance()->EnableMonitoring(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 std::string monitoring_options_json; 180 std::string monitoring_options_json;
199 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json); 181 base::JSONWriter::Write(monitoring_options.get(), &monitoring_options_json);
200 182
201 base::RefCountedString* monitoring_options_base64 = 183 base::RefCountedString* monitoring_options_base64 =
202 new base::RefCountedString(); 184 new base::RefCountedString();
203 base::Base64Encode(monitoring_options_json, 185 base::Base64Encode(monitoring_options_json,
204 &monitoring_options_base64->data()); 186 &monitoring_options_base64->data());
205 callback.Run(monitoring_options_base64); 187 callback.Run(monitoring_options_base64);
206 } 188 }
207 189
208 void ReadMonitoringSnapshot(const WebUIDataSource::GotDataCallback& callback, 190 void TracingCallbackWrapper(const WebUIDataSource::GotDataCallback& callback,
209 const base::FilePath& path) { 191 base::RefCountedString* data) {
210 std::string tmp; 192 callback.Run(data);
211 if (!base::ReadFileToString(path, &tmp))
212 LOG(ERROR) << "Failed to read file " << path.value();
213 base::DeleteFile(path, false);
214 callback.Run(base::RefCountedString::TakeString(&tmp));
215 }
216
217 void OnMonitoringSnapshotCaptured(
218 const WebUIDataSource::GotDataCallback& callback,
219 const base::FilePath& path) {
220 BrowserThread::PostTask(
221 BrowserThread::FILE, FROM_HERE,
222 base::Bind(ReadMonitoringSnapshot, callback, path));
223 } 193 }
224 194
225 bool OnBeginJSONRequest(const std::string& path, 195 bool OnBeginJSONRequest(const std::string& path,
226 const WebUIDataSource::GotDataCallback& callback) { 196 const WebUIDataSource::GotDataCallback& callback) {
227 if (path == "json/categories") { 197 if (path == "json/categories") {
228 return TracingController::GetInstance()->GetCategories( 198 return TracingController::GetInstance()->GetCategories(
229 base::Bind(OnGotCategories, callback)); 199 base::Bind(OnGotCategories, callback));
230 } 200 }
231 201
232 const char* beginRecordingPath = "json/begin_recording?"; 202 const char* beginRecordingPath = "json/begin_recording?";
233 if (StartsWithASCII(path, beginRecordingPath, true)) { 203 if (StartsWithASCII(path, beginRecordingPath, true)) {
234 std::string data = path.substr(strlen(beginRecordingPath)); 204 std::string data = path.substr(strlen(beginRecordingPath));
235 return BeginRecording(data, callback); 205 return BeginRecording(data, callback);
236 } 206 }
237 if (path == "json/get_buffer_percent_full") { 207 if (path == "json/get_buffer_percent_full") {
238 return TracingController::GetInstance()->GetTraceBufferPercentFull( 208 return TracingController::GetInstance()->GetTraceBufferPercentFull(
239 base::Bind(OnTraceBufferPercentFullResult, callback)); 209 base::Bind(OnTraceBufferPercentFullResult, callback));
240 } 210 }
241 if (path == "json/end_recording") { 211 if (path == "json/end_recording") {
242 return TracingController::GetInstance()->DisableRecording( 212 return TracingController::GetInstance()->DisableRecording(
243 base::FilePath(), base::Bind(BeginReadingRecordingResult, callback)); 213 TracingControllerImpl::CreateStringSink(
214 base::Bind(TracingCallbackWrapper, callback)));
244 } 215 }
245 216
246 const char* enableMonitoringPath = "json/begin_monitoring?"; 217 const char* enableMonitoringPath = "json/begin_monitoring?";
247 if (path.find(enableMonitoringPath) == 0) { 218 if (path.find(enableMonitoringPath) == 0) {
248 std::string data = path.substr(strlen(enableMonitoringPath)); 219 std::string data = path.substr(strlen(enableMonitoringPath));
249 return EnableMonitoring(data, callback); 220 return EnableMonitoring(data, callback);
250 } 221 }
251 if (path == "json/end_monitoring") { 222 if (path == "json/end_monitoring") {
252 return TracingController::GetInstance()->DisableMonitoring( 223 return TracingController::GetInstance()->DisableMonitoring(
253 base::Bind(OnMonitoringDisabled, callback)); 224 base::Bind(OnMonitoringDisabled, callback));
254 } 225 }
255 if (path == "json/capture_monitoring") { 226 if (path == "json/capture_monitoring") {
256 TracingController::GetInstance()->CaptureMonitoringSnapshot( 227 TracingController::GetInstance()->CaptureMonitoringSnapshot(
257 base::FilePath(), base::Bind(OnMonitoringSnapshotCaptured, callback)); 228 TracingControllerImpl::CreateStringSink(
229 base::Bind(TracingCallbackWrapper, callback)));
258 return true; 230 return true;
259 } 231 }
260 if (path == "json/get_monitoring_status") { 232 if (path == "json/get_monitoring_status") {
261 GetMonitoringStatus(callback); 233 GetMonitoringStatus(callback);
262 return true; 234 return true;
263 } 235 }
264 236
265 LOG(ERROR) << "Unhandled request to " << path; 237 LOG(ERROR) << "Unhandled request to " << path;
266 return false; 238 return false;
267 } 239 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 if (success) { 377 if (success) {
406 web_ui()->CallJavascriptFunction("onUploadComplete", 378 web_ui()->CallJavascriptFunction("onUploadComplete",
407 base::StringValue(report_id)); 379 base::StringValue(report_id));
408 } else { 380 } else {
409 web_ui()->CallJavascriptFunction("onUploadError", 381 web_ui()->CallJavascriptFunction("onUploadError",
410 base::StringValue(error_message)); 382 base::StringValue(error_message));
411 } 383 }
412 } 384 }
413 385
414 } // namespace content 386 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.cc ('k') | content/public/browser/tracing_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698