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

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

Issue 1148633007: Hooked the trace event argument whitelist up to the background_trace_manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/background_tracing_manager_impl.h" 5 #include "content/browser/tracing/background_tracing_manager_impl.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "content/public/browser/background_tracing_preemptive_config.h" 8 #include "content/public/browser/background_tracing_preemptive_config.h"
9 #include "content/public/browser/background_tracing_reactive_config.h" 9 #include "content/public/browser/background_tracing_reactive_config.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) 86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED)
87 return false; 87 return false;
88 } 88 }
89 89
90 return true; 90 return true;
91 } 91 }
92 92
93 bool BackgroundTracingManagerImpl::SetActiveScenario( 93 bool BackgroundTracingManagerImpl::SetActiveScenario(
94 scoped_ptr<BackgroundTracingConfig> config, 94 scoped_ptr<BackgroundTracingConfig> config,
95 const BackgroundTracingManager::ReceiveCallback& receive_callback, 95 const BackgroundTracingManager::ReceiveCallback& receive_callback,
96 const base::Closure& enabled_callback,
96 bool requires_anonymized_data) { 97 bool requires_anonymized_data) {
97 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 98 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
98 if (is_tracing_) 99 if (is_tracing_)
99 return false; 100 return false;
100 101
101 if (!IsSupportedConfig(config.get())) 102 if (!IsSupportedConfig(config.get()))
102 return false; 103 return false;
103 104
104 // No point in tracing if there's nowhere to send it. 105 // No point in tracing if there's nowhere to send it.
105 if (config && receive_callback.is_null()) 106 if (config && receive_callback.is_null())
106 return false; 107 return false;
107 108
108 config_ = config.Pass(); 109 config_ = config.Pass();
109 receive_callback_ = receive_callback; 110 receive_callback_ = receive_callback;
110 requires_anonymized_data_ = requires_anonymized_data; 111 requires_anonymized_data_ = requires_anonymized_data;
111 112
112 EnableRecordingIfConfigNeedsIt(); 113 EnableRecordingIfConfigNeedsIt(enabled_callback);
113 114
114 return true; 115 return true;
115 } 116 }
116 117
117 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { 118 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt(
119 const base::Closure& enabled_callback) {
118 if (!config_) 120 if (!config_)
119 return; 121 return;
120 122
121 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { 123 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
122 EnableRecording(GetCategoryFilterForCategoryPreset( 124 EnableRecording(GetCategoryFilterForCategoryPreset(
123 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) 125 static_cast<BackgroundTracingPreemptiveConfig*>(
124 ->category_preset)); 126 config_.get())->category_preset),
127 enabled_callback);
125 } else { 128 } else {
126 // TODO(simonhatch): Implement reactive tracing path. 129 // TODO(simonhatch): Implement reactive tracing path.
127 NOTREACHED(); 130 NOTREACHED();
128 } 131 }
129 } 132 }
130 133
131 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( 134 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing(
132 TriggerHandle handle) const { 135 TriggerHandle handle) const {
133 if (!config_) 136 if (!config_)
134 return false; 137 return false;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 trigger_handles_.begin(); 224 trigger_handles_.begin();
222 it != trigger_handles_.end(); ++it) 225 it != trigger_handles_.end(); ++it)
223 trigger_names->push_back(it->second); 226 trigger_names->push_back(it->second);
224 } 227 }
225 228
226 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { 229 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() {
227 trigger_handles_.clear(); 230 trigger_handles_.clear();
228 } 231 }
229 232
230 void BackgroundTracingManagerImpl::EnableRecording( 233 void BackgroundTracingManagerImpl::EnableRecording(
231 base::trace_event::CategoryFilter category_filter) { 234 base::trace_event::CategoryFilter category_filter,
235 const base::Closure& enabled_callback) {
236 base::trace_event::TraceOptions trace_options(
237 base::trace_event::RECORD_CONTINUOUSLY);
238 trace_options.enable_argument_filter = requires_anonymized_data_;
shatch 2015/05/22 22:21:37 Am I taking crazy pills, or is this not actually u
232 is_tracing_ = TracingController::GetInstance()->EnableRecording( 239 is_tracing_ = TracingController::GetInstance()->EnableRecording(
233 category_filter, 240 category_filter,
234 base::trace_event::TraceOptions(base::trace_event::RECORD_CONTINUOUSLY), 241 base::trace_event::TraceOptions(base::trace_event::RECORD_CONTINUOUSLY),
235 TracingController::EnableRecordingDoneCallback()); 242 enabled_callback);
236 } 243 }
237 244
238 void BackgroundTracingManagerImpl::OnFinalizeStarted( 245 void BackgroundTracingManagerImpl::OnFinalizeStarted(
239 scoped_refptr<base::RefCountedString> file_contents) { 246 scoped_refptr<base::RefCountedString> file_contents) {
240 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 247 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
241 248
242 if (!receive_callback_.is_null()) 249 if (!receive_callback_.is_null())
243 receive_callback_.Run( 250 receive_callback_.Run(
244 file_contents.get(), 251 file_contents,
245 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, 252 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete,
246 base::Unretained(this))); 253 base::Unretained(this)));
247 } 254 }
248 255
249 void BackgroundTracingManagerImpl::OnFinalizeComplete() { 256 void BackgroundTracingManagerImpl::OnFinalizeComplete() {
250 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 257 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
251 BrowserThread::PostTask( 258 BrowserThread::PostTask(
252 BrowserThread::UI, FROM_HERE, 259 BrowserThread::UI, FROM_HERE,
253 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, 260 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete,
254 base::Unretained(this))); 261 base::Unretained(this)));
255 return; 262 return;
256 } 263 }
257 264
258 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 265 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
259 266
260 is_gathering_ = false; 267 is_gathering_ = false;
261 268
262 if (!idle_callback_.is_null()) 269 if (!idle_callback_.is_null())
263 idle_callback_.Run(); 270 idle_callback_.Run();
264 271
265 // Now that a trace has completed, we may need to enable recording again. 272 // Now that a trace has completed, we may need to enable recording again.
266 EnableRecordingIfConfigNeedsIt(); 273 EnableRecordingIfConfigNeedsIt(base::Closure());
267 } 274 }
268 275
269 void BackgroundTracingManagerImpl::BeginFinalizing( 276 void BackgroundTracingManagerImpl::BeginFinalizing(
270 StartedFinalizingCallback callback) { 277 StartedFinalizingCallback callback) {
271 is_gathering_ = true; 278 is_gathering_ = true;
272 is_tracing_ = false; 279 is_tracing_ = false;
273 280
274 content::TracingController::GetInstance()->DisableRecording( 281 scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink;
275 content::TracingController::CreateCompressedStringSink( 282 if (config_->compress_trace) {
276 data_endpoint_wrapper_)); 283 trace_data_sink = content::TracingController::CreateCompressedStringSink(
284 data_endpoint_wrapper_);
285 } else {
286 trace_data_sink =
287 content::TracingController::CreateStringSink(data_endpoint_wrapper_);
288 }
289
290 content::TracingController::GetInstance()->DisableRecording(trace_data_sink);
277 291
278 if (!callback.is_null()) 292 if (!callback.is_null())
279 callback.Run(true); 293 callback.Run(true);
280 } 294 }
281 295
282 base::trace_event::CategoryFilter 296 base::trace_event::CategoryFilter
283 BackgroundTracingManagerImpl::GetCategoryFilterForCategoryPreset( 297 BackgroundTracingManagerImpl::GetCategoryFilterForCategoryPreset(
284 BackgroundTracingConfig::CategoryPreset preset) const { 298 BackgroundTracingConfig::CategoryPreset preset) const {
285 switch (preset) { 299 switch (preset) {
286 case BackgroundTracingConfig::CategoryPreset::BENCHMARK: 300 case BackgroundTracingConfig::CategoryPreset::BENCHMARK:
(...skipping 16 matching lines...) Expand all
303 return NULL; 317 return NULL;
304 } 318 }
305 319
306 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, 320 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config,
307 base::DictionaryValue* dict) { 321 base::DictionaryValue* dict) {
308 // TODO(simonhatch): Implement this. 322 // TODO(simonhatch): Implement this.
309 CHECK(false); 323 CHECK(false);
310 } 324 }
311 325
312 } // namspace content 326 } // namspace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698