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

Side by Side Diff: content/browser/devtools/devtools_tracing_handler.cc

Issue 511873002: DevTools: use explicit IPC messages for enabling/disabling tracing instead of intercepting protocol… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed category filter 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/devtools/devtools_tracing_handler.h" 5 #include "content/browser/devtools/devtools_tracing_handler.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 : weak_factory_(this), target_(target), is_recording_(false) { 58 : weak_factory_(this), target_(target), is_recording_(false) {
59 RegisterCommandHandler(devtools::Tracing::start::kName, 59 RegisterCommandHandler(devtools::Tracing::start::kName,
60 base::Bind(&DevToolsTracingHandler::OnStart, 60 base::Bind(&DevToolsTracingHandler::OnStart,
61 base::Unretained(this))); 61 base::Unretained(this)));
62 RegisterCommandHandler(devtools::Tracing::end::kName, 62 RegisterCommandHandler(devtools::Tracing::end::kName,
63 base::Bind(&DevToolsTracingHandler::OnEnd, 63 base::Bind(&DevToolsTracingHandler::OnEnd,
64 base::Unretained(this))); 64 base::Unretained(this)));
65 RegisterCommandHandler(devtools::Tracing::getCategories::kName, 65 RegisterCommandHandler(devtools::Tracing::getCategories::kName,
66 base::Bind(&DevToolsTracingHandler::OnGetCategories, 66 base::Bind(&DevToolsTracingHandler::OnGetCategories,
67 base::Unretained(this))); 67 base::Unretained(this)));
68 RegisterNotificationHandler(devtools::Tracing::started::kName,
69 base::Bind(&DevToolsTracingHandler::OnTracingStarted,
70 base::Unretained(this)));
71 RegisterNotificationHandler(devtools::Tracing::stopped::kName,
72 base::Bind(&DevToolsTracingHandler::OnTracingStopped,
73 base::Unretained(this)));
74 } 68 }
75 69
76 DevToolsTracingHandler::~DevToolsTracingHandler() { 70 DevToolsTracingHandler::~DevToolsTracingHandler() {
77 } 71 }
78 72
79 void DevToolsTracingHandler::BeginReadingRecordingResult( 73 void DevToolsTracingHandler::BeginReadingRecordingResult(
80 const base::FilePath& path) { 74 const base::FilePath& path) {
81 BrowserThread::PostTask( 75 BrowserThread::PostTask(
82 BrowserThread::FILE, FROM_HERE, 76 BrowserThread::FILE, FROM_HERE,
83 base::Bind(&ReadFile, path, 77 base::Bind(&ReadFile, path,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } else if (*iter == kEnableSampling) { 141 } else if (*iter == kEnableSampling) {
148 ret.enable_sampling = true; 142 ret.enable_sampling = true;
149 } 143 }
150 } 144 }
151 return ret; 145 return ret;
152 } 146 }
153 147
154 scoped_refptr<DevToolsProtocol::Response> 148 scoped_refptr<DevToolsProtocol::Response>
155 DevToolsTracingHandler::OnStart( 149 DevToolsTracingHandler::OnStart(
156 scoped_refptr<DevToolsProtocol::Command> command) { 150 scoped_refptr<DevToolsProtocol::Command> command) {
151 // If inspected target is a render process Tracing.start will be handled by
152 // tracing agent in the renderer.
153 if (target_ == Renderer)
154 return NULL;
155
157 is_recording_ = true; 156 is_recording_ = true;
158 157
159 std::string categories; 158 std::string categories;
160 base::debug::TraceOptions options; 159 base::debug::TraceOptions options;
161 double usage_reporting_interval = 0.0; 160 double usage_reporting_interval = 0.0;
162 161
163 base::DictionaryValue* params = command->params(); 162 base::DictionaryValue* params = command->params();
164 if (params) { 163 if (params) {
165 params->GetString(devtools::Tracing::start::kParamCategories, &categories); 164 params->GetString(devtools::Tracing::start::kParamCategories, &categories);
166 std::string options_param; 165 std::string options_param;
167 if (params->GetString(devtools::Tracing::start::kParamOptions, 166 if (params->GetString(devtools::Tracing::start::kParamOptions,
168 &options_param)) { 167 &options_param)) {
169 options = TraceOptionsFromString(options_param); 168 options = TraceOptionsFromString(options_param);
170 } 169 }
171 params->GetDouble( 170 params->GetDouble(
172 devtools::Tracing::start::kParamBufferUsageReportingInterval, 171 devtools::Tracing::start::kParamBufferUsageReportingInterval,
173 &usage_reporting_interval); 172 &usage_reporting_interval);
174 } 173 }
175 174
176 SetupTimer(usage_reporting_interval); 175 SetupTimer(usage_reporting_interval);
177 176
178 // If inspected target is a render process Tracing.start will be handled by
179 // tracing agent in the renderer.
180 if (target_ == Renderer) {
181 TracingController::GetInstance()->EnableRecording(
182 base::debug::CategoryFilter(categories),
183 options,
184 TracingController::EnableRecordingDoneCallback());
185 return NULL;
186 }
187
188 TracingController::GetInstance()->EnableRecording( 177 TracingController::GetInstance()->EnableRecording(
189 base::debug::CategoryFilter(categories), 178 base::debug::CategoryFilter(categories),
190 options, 179 options,
191 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, 180 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled,
192 weak_factory_.GetWeakPtr(), 181 weak_factory_.GetWeakPtr(),
193 command)); 182 command));
194 return command->AsyncResponsePromise(); 183 return command->AsyncResponsePromise();
195 } 184 }
196 185
197 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { 186 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) {
(...skipping 23 matching lines...) Expand all
221 210
222 void DevToolsTracingHandler::OnBufferUsage(float usage) { 211 void DevToolsTracingHandler::OnBufferUsage(float usage) {
223 base::DictionaryValue* params = new base::DictionaryValue(); 212 base::DictionaryValue* params = new base::DictionaryValue();
224 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage); 213 params->SetDouble(devtools::Tracing::bufferUsage::kParamValue, usage);
225 SendNotification(devtools::Tracing::bufferUsage::kName, params); 214 SendNotification(devtools::Tracing::bufferUsage::kName, params);
226 } 215 }
227 216
228 scoped_refptr<DevToolsProtocol::Response> 217 scoped_refptr<DevToolsProtocol::Response>
229 DevToolsTracingHandler::OnEnd( 218 DevToolsTracingHandler::OnEnd(
230 scoped_refptr<DevToolsProtocol::Command> command) { 219 scoped_refptr<DevToolsProtocol::Command> command) {
220 // If inspected target is a render process Tracing.end will be handled by
221 // tracing agent in the renderer.
222 if (target_ == Renderer)
223 return NULL;
231 DisableRecording( 224 DisableRecording(
232 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, 225 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
233 weak_factory_.GetWeakPtr())); 226 weak_factory_.GetWeakPtr()));
234 return command->SuccessResponse(NULL); 227 return command->SuccessResponse(NULL);
235 } 228 }
236 229
237 void DevToolsTracingHandler::DisableRecording( 230 void DevToolsTracingHandler::DisableRecording(
238 const TracingController::TracingFileResultCallback& callback) { 231 const TracingController::TracingFileResultCallback& callback) {
239 is_recording_ = false; 232 is_recording_ = false;
240 buffer_usage_poll_timer_.reset(); 233 buffer_usage_poll_timer_.reset();
(...skipping 24 matching lines...) Expand all
265 for (std::set<std::string>::const_iterator it = category_set.begin(); 258 for (std::set<std::string>::const_iterator it = category_set.begin();
266 it != category_set.end(); ++it) { 259 it != category_set.end(); ++it) {
267 category_list->AppendString(*it); 260 category_list->AppendString(*it);
268 } 261 }
269 262
270 response->Set(devtools::Tracing::getCategories::kResponseCategories, 263 response->Set(devtools::Tracing::getCategories::kResponseCategories,
271 category_list); 264 category_list);
272 SendAsyncResponse(command->SuccessResponse(response)); 265 SendAsyncResponse(command->SuccessResponse(response));
273 } 266 }
274 267
275 void DevToolsTracingHandler::OnTracingStarted( 268 void DevToolsTracingHandler::EnableTracing(const std::string& category_filter) {
276 scoped_refptr<DevToolsProtocol::Notification> notification) {
277 if (is_recording_) 269 if (is_recording_)
278 return; 270 return;
279 is_recording_ = true; 271 is_recording_ = true;
280 272
281 SetupTimer(kDefaultReportingInterval); 273 SetupTimer(kDefaultReportingInterval);
282 274
283 TracingController::GetInstance()->EnableRecording( 275 TracingController::GetInstance()->EnableRecording(
284 base::debug::CategoryFilter(kDefaultCategories), 276 base::debug::CategoryFilter(category_filter),
dcheng 2014/08/27 16:43:31 I'm not super familiar with inspector. From the CL
285 base::debug::TraceOptions(), 277 base::debug::TraceOptions(),
286 TracingController::EnableRecordingDoneCallback()); 278 TracingController::EnableRecordingDoneCallback());
279 SendNotification(devtools::Tracing::started::kName, NULL);
287 } 280 }
288 281
289 void DevToolsTracingHandler::OnTracingStopped( 282 void DevToolsTracingHandler::DisableTracing() {
290 scoped_refptr<DevToolsProtocol::Notification> notification) {
291 if (!is_recording_) 283 if (!is_recording_)
292 return; 284 return;
293 is_recording_ = false; 285 is_recording_ = false;
294 DisableRecording( 286 DisableRecording(
295 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, 287 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
296 weak_factory_.GetWeakPtr())); 288 weak_factory_.GetWeakPtr()));
297 } 289 }
298 290
299 291
300 } // namespace content 292 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_tracing_handler.h ('k') | content/browser/devtools/render_view_devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698