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

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

Issue 425593002: Refactor trace_event_impl's SetEnabled to use TraceOptions. Propagate this through the whole stack. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address joechan's comments Created 6 years, 4 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"
11 #include "base/debug/trace_event_impl.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
16 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "base/timer/timer.h" 20 #include "base/timer/timer.h"
20 #include "base/values.h" 21 #include "base/values.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // Hand-craft protocol notification message so we can substitute JSON 122 // Hand-craft protocol notification message so we can substitute JSON
122 // that we already got as string as a bare object, not a quoted string. 123 // that we already got as string as a bare object, not a quoted string.
123 std::string message = base::StringPrintf( 124 std::string message = base::StringPrintf(
124 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }", 125 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }",
125 devtools::Tracing::dataCollected::kName, 126 devtools::Tracing::dataCollected::kName,
126 devtools::Tracing::dataCollected::kParamValue, 127 devtools::Tracing::dataCollected::kParamValue,
127 trace_fragment.c_str()); 128 trace_fragment.c_str());
128 SendRawMessage(message); 129 SendRawMessage(message);
129 } 130 }
130 131
131 TracingController::Options DevToolsTracingHandler::TraceOptionsFromString( 132 base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString(
132 const std::string& options) { 133 const std::string& options) {
133 std::vector<std::string> split; 134 std::vector<std::string> split;
134 std::vector<std::string>::iterator iter; 135 std::vector<std::string>::iterator iter;
135 int ret = 0; 136 base::debug::TraceOptions ret;
136 137
137 base::SplitString(options, ',', &split); 138 base::SplitString(options, ',', &split);
138 for (iter = split.begin(); iter != split.end(); ++iter) { 139 for (iter = split.begin(); iter != split.end(); ++iter) {
139 if (*iter == kRecordUntilFull) { 140 if (*iter == kRecordUntilFull) {
140 ret &= ~TracingController::RECORD_CONTINUOUSLY; 141 ret.record_mode = base::debug::RECORD_UNTIL_FULL;
141 } else if (*iter == kRecordContinuously) { 142 } else if (*iter == kRecordContinuously) {
142 ret |= TracingController::RECORD_CONTINUOUSLY; 143 ret.record_mode = base::debug::RECORD_CONTINUOUSLY;
143 } else if (*iter == kEnableSampling) { 144 } else if (*iter == kEnableSampling) {
144 ret |= TracingController::ENABLE_SAMPLING; 145 ret.enable_sampling = true;
145 } 146 }
146 } 147 }
147 return static_cast<TracingController::Options>(ret); 148 return ret;
148 } 149 }
149 150
150 scoped_refptr<DevToolsProtocol::Response> 151 scoped_refptr<DevToolsProtocol::Response>
151 DevToolsTracingHandler::OnStart( 152 DevToolsTracingHandler::OnStart(
152 scoped_refptr<DevToolsProtocol::Command> command) { 153 scoped_refptr<DevToolsProtocol::Command> command) {
153 is_recording_ = true; 154 is_recording_ = true;
154 155
155 std::string categories; 156 std::string categories;
156 TracingController::Options options = TracingController::DEFAULT_OPTIONS; 157 base::debug::TraceOptions options;
157 double usage_reporting_interval = 0.0; 158 double usage_reporting_interval = 0.0;
158 159
159 base::DictionaryValue* params = command->params(); 160 base::DictionaryValue* params = command->params();
160 if (params) { 161 if (params) {
161 params->GetString(devtools::Tracing::start::kParamCategories, &categories); 162 params->GetString(devtools::Tracing::start::kParamCategories, &categories);
162 std::string options_param; 163 std::string options_param;
163 if (params->GetString(devtools::Tracing::start::kParamOptions, 164 if (params->GetString(devtools::Tracing::start::kParamOptions,
164 &options_param)) { 165 &options_param)) {
165 options = TraceOptionsFromString(options_param); 166 options = TraceOptionsFromString(options_param);
166 } 167 }
167 params->GetDouble( 168 params->GetDouble(
168 devtools::Tracing::start::kParamBufferUsageReportingInterval, 169 devtools::Tracing::start::kParamBufferUsageReportingInterval,
169 &usage_reporting_interval); 170 &usage_reporting_interval);
170 } 171 }
171 172
172 SetupTimer(usage_reporting_interval); 173 SetupTimer(usage_reporting_interval);
173 174
174 // If inspected target is a render process Tracing.start will be handled by 175 // If inspected target is a render process Tracing.start will be handled by
175 // tracing agent in the renderer. 176 // tracing agent in the renderer.
176 if (target_ == Renderer) { 177 if (target_ == Renderer) {
177 TracingController::GetInstance()->EnableRecording( 178 TracingController::GetInstance()->EnableRecording(
178 categories, options, TracingController::EnableRecordingDoneCallback()); 179 base::debug::CategoryFilter(categories),
180 options,
181 TracingController::EnableRecordingDoneCallback());
179 return NULL; 182 return NULL;
180 } 183 }
181 184
182 TracingController::GetInstance()->EnableRecording( 185 TracingController::GetInstance()->EnableRecording(
183 categories, options, 186 base::debug::CategoryFilter(categories),
187 options,
184 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled, 188 base::Bind(&DevToolsTracingHandler::OnRecordingEnabled,
185 weak_factory_.GetWeakPtr(), 189 weak_factory_.GetWeakPtr(),
186 command)); 190 command));
187 return command->AsyncResponsePromise(); 191 return command->AsyncResponsePromise();
188 } 192 }
189 193
190 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) { 194 void DevToolsTracingHandler::SetupTimer(double usage_reporting_interval) {
191 if (usage_reporting_interval == 0) return; 195 if (usage_reporting_interval == 0) return;
192 196
193 if (usage_reporting_interval < kMinimumReportingInterval) 197 if (usage_reporting_interval < kMinimumReportingInterval)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 271
268 void DevToolsTracingHandler::OnTracingStarted( 272 void DevToolsTracingHandler::OnTracingStarted(
269 scoped_refptr<DevToolsProtocol::Notification> notification) { 273 scoped_refptr<DevToolsProtocol::Notification> notification) {
270 if (is_recording_) 274 if (is_recording_)
271 return; 275 return;
272 is_recording_ = true; 276 is_recording_ = true;
273 277
274 SetupTimer(kDefaultReportingInterval); 278 SetupTimer(kDefaultReportingInterval);
275 279
276 TracingController::GetInstance()->EnableRecording( 280 TracingController::GetInstance()->EnableRecording(
277 kDefaultCategories, 281 base::debug::CategoryFilter(kDefaultCategories),
278 TracingController::DEFAULT_OPTIONS, 282 base::debug::TraceOptions(),
279 TracingController::EnableRecordingDoneCallback()); 283 TracingController::EnableRecordingDoneCallback());
280 } 284 }
281 285
282 void DevToolsTracingHandler::OnTracingStopped( 286 void DevToolsTracingHandler::OnTracingStopped(
283 scoped_refptr<DevToolsProtocol::Notification> notification) { 287 scoped_refptr<DevToolsProtocol::Notification> notification) {
284 if (!is_recording_) 288 if (!is_recording_)
285 return; 289 return;
286 is_recording_ = false; 290 is_recording_ = false;
287 DisableRecording( 291 DisableRecording(
288 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, 292 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
289 weak_factory_.GetWeakPtr())); 293 weak_factory_.GetWeakPtr()));
290 } 294 }
291 295
292 296
293 } // namespace content 297 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_tracing_handler.h ('k') | content/browser/media/webrtc_getusermedia_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698