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

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 Nat'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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Hand-craft protocol notification message so we can substitute JSON 110 // Hand-craft protocol notification message so we can substitute JSON
110 // that we already got as string as a bare object, not a quoted string. 111 // that we already got as string as a bare object, not a quoted string.
111 std::string message = base::StringPrintf( 112 std::string message = base::StringPrintf(
112 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }", 113 "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }",
113 devtools::Tracing::dataCollected::kName, 114 devtools::Tracing::dataCollected::kName,
114 devtools::Tracing::dataCollected::kParamValue, 115 devtools::Tracing::dataCollected::kParamValue,
115 trace_fragment.c_str()); 116 trace_fragment.c_str());
116 SendRawMessage(message); 117 SendRawMessage(message);
117 } 118 }
118 119
119 TracingController::Options DevToolsTracingHandler::TraceOptionsFromString( 120 base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString(
120 const std::string& options) { 121 const std::string& options) {
121 std::vector<std::string> split; 122 std::vector<std::string> split;
122 std::vector<std::string>::iterator iter; 123 std::vector<std::string>::iterator iter;
123 int ret = 0; 124 base::debug::TraceOptions ret;
124 125
125 base::SplitString(options, ',', &split); 126 base::SplitString(options, ',', &split);
126 for (iter = split.begin(); iter != split.end(); ++iter) { 127 for (iter = split.begin(); iter != split.end(); ++iter) {
127 if (*iter == kRecordUntilFull) { 128 if (*iter == kRecordUntilFull) {
128 ret &= ~TracingController::RECORD_CONTINUOUSLY; 129 ret.record_mode = base::debug::RECORD_UNTIL_FULL;
129 } else if (*iter == kRecordContinuously) { 130 } else if (*iter == kRecordContinuously) {
130 ret |= TracingController::RECORD_CONTINUOUSLY; 131 ret.record_mode = base::debug::RECORD_CONTINUOUSLY;
131 } else if (*iter == kEnableSampling) { 132 } else if (*iter == kEnableSampling) {
132 ret |= TracingController::ENABLE_SAMPLING; 133 ret.enable_sampling = true;
dsinclair 2014/07/30 14:25:26 Should we add systrace here as well?
nednguyen 2014/07/30 16:51:15 I would leave this to another patch since it's a d
133 } 134 }
134 } 135 }
135 return static_cast<TracingController::Options>(ret); 136 return ret;
136 } 137 }
137 138
138 scoped_refptr<DevToolsProtocol::Response> 139 scoped_refptr<DevToolsProtocol::Response>
139 DevToolsTracingHandler::OnStart( 140 DevToolsTracingHandler::OnStart(
140 scoped_refptr<DevToolsProtocol::Command> command) { 141 scoped_refptr<DevToolsProtocol::Command> command) {
141 is_recording_ = true; 142 is_recording_ = true;
142 std::string categories; 143 std::string categories;
143 base::DictionaryValue* params = command->params(); 144 base::DictionaryValue* params = command->params();
144 if (params) 145 if (params)
145 params->GetString(devtools::Tracing::start::kParamCategories, &categories); 146 params->GetString(devtools::Tracing::start::kParamCategories, &categories);
146 147
147 TracingController::Options options = TracingController::DEFAULT_OPTIONS; 148 base::debug::TraceOptions options;
148 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) { 149 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) {
149 std::string options_param; 150 std::string options_param;
150 params->GetString(devtools::Tracing::start::kParamOptions, &options_param); 151 params->GetString(devtools::Tracing::start::kParamOptions, &options_param);
151 options = TraceOptionsFromString(options_param); 152 options = TraceOptionsFromString(options_param);
152 } 153 }
153 154
154 if (params && params->HasKey( 155 if (params && params->HasKey(
155 devtools::Tracing::start::kParamBufferUsageReportingInterval)) { 156 devtools::Tracing::start::kParamBufferUsageReportingInterval)) {
156 double usage_reporting_interval = 0.0; 157 double usage_reporting_interval = 0.0;
157 params->GetDouble( 158 params->GetDouble(
(...skipping 12 matching lines...) Expand all
170 weak_factory_.GetWeakPtr())), 171 weak_factory_.GetWeakPtr())),
171 true)); 172 true));
172 buffer_usage_poll_timer_->Reset(); 173 buffer_usage_poll_timer_->Reset();
173 } 174 }
174 } 175 }
175 176
176 // If inspected target is a render process Tracing.start will be handled by 177 // If inspected target is a render process Tracing.start will be handled by
177 // tracing agent in the renderer. 178 // tracing agent in the renderer.
178 if (target_ == Renderer) { 179 if (target_ == Renderer) {
179 TracingController::GetInstance()->EnableRecording( 180 TracingController::GetInstance()->EnableRecording(
180 categories, options, TracingController::EnableRecordingDoneCallback()); 181 base::debug::CategoryFilter(categories),
dsinclair 2014/07/30 14:25:26 unrelated?
nednguyen 2014/07/30 16:51:15 ditto
182 options,
183 TracingController::EnableRecordingDoneCallback());
181 return NULL; 184 return NULL;
182 } 185 }
183 186
184 TracingController::GetInstance()->EnableRecording( 187 TracingController::GetInstance()->EnableRecording(
185 categories, options, 188 base::debug::CategoryFilter(categories),
dsinclair 2014/07/30 14:25:26 Unrelated?
nednguyen 2014/07/30 16:51:15 ditto
189 options,
186 base::Bind(&DevToolsTracingHandler::OnTracingStarted, 190 base::Bind(&DevToolsTracingHandler::OnTracingStarted,
187 weak_factory_.GetWeakPtr(), 191 weak_factory_.GetWeakPtr(),
188 command)); 192 command));
189 193
190 return command->AsyncResponsePromise(); 194 return command->AsyncResponsePromise();
191 } 195 }
192 196
193 void DevToolsTracingHandler::OnTracingStarted( 197 void DevToolsTracingHandler::OnTracingStarted(
194 scoped_refptr<DevToolsProtocol::Command> command) { 198 scoped_refptr<DevToolsProtocol::Command> command) {
195 SendAsyncResponse(command->SuccessResponse(NULL)); 199 SendAsyncResponse(command->SuccessResponse(NULL));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 it != category_set.end(); ++it) { 246 it != category_set.end(); ++it) {
243 category_list->AppendString(*it); 247 category_list->AppendString(*it);
244 } 248 }
245 249
246 response->Set(devtools::Tracing::getCategories::kResponseCategories, 250 response->Set(devtools::Tracing::getCategories::kResponseCategories,
247 category_list); 251 category_list);
248 SendAsyncResponse(command->SuccessResponse(response)); 252 SendAsyncResponse(command->SuccessResponse(response));
249 } 253 }
250 254
251 } // namespace content 255 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698