| OLD | NEW |
| 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 "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "content/public/browser/background_tracing_preemptive_config.h" | 9 #include "content/public/browser/background_tracing_preemptive_config.h" |
| 10 #include "content/public/browser/background_tracing_reactive_config.h" | 10 #include "content/public/browser/background_tracing_reactive_config.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool BackgroundTracingManagerImpl::SetActiveScenario( | 130 bool BackgroundTracingManagerImpl::SetActiveScenario( |
| 131 scoped_ptr<BackgroundTracingConfig> config, | 131 scoped_ptr<BackgroundTracingConfig> config, |
| 132 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 132 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
| 133 bool requires_anonymized_data) { | 133 DataFiltering data_filtering) { |
| 134 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 134 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 135 if (is_tracing_) | 135 if (is_tracing_) |
| 136 return false; | 136 return false; |
| 137 | 137 |
| 138 if (!IsSupportedConfig(config.get())) | 138 if (!IsSupportedConfig(config.get())) |
| 139 return false; | 139 return false; |
| 140 | 140 |
| 141 // No point in tracing if there's nowhere to send it. | 141 // No point in tracing if there's nowhere to send it. |
| 142 if (config && receive_callback.is_null()) | 142 if (config && receive_callback.is_null()) |
| 143 return false; | 143 return false; |
| 144 | 144 |
| 145 config_ = config.Pass(); | 145 config_ = config.Pass(); |
| 146 receive_callback_ = receive_callback; | 146 receive_callback_ = receive_callback; |
| 147 requires_anonymized_data_ = requires_anonymized_data; | 147 requires_anonymized_data_ = (data_filtering == ANONYMIZE_DATA); |
| 148 | 148 |
| 149 EnableRecordingIfConfigNeedsIt(); | 149 EnableRecordingIfConfigNeedsIt(); |
| 150 | 150 |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { | 154 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { |
| 155 if (!config_) | 155 if (!config_) |
| 156 return; | 156 return; |
| 157 | 157 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 for (std::map<TriggerHandle, std::string>::iterator it = | 289 for (std::map<TriggerHandle, std::string>::iterator it = |
| 290 trigger_handles_.begin(); | 290 trigger_handles_.begin(); |
| 291 it != trigger_handles_.end(); ++it) | 291 it != trigger_handles_.end(); ++it) |
| 292 trigger_names->push_back(it->second); | 292 trigger_names->push_back(it->second); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { | 295 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { |
| 296 trigger_handles_.clear(); | 296 trigger_handles_.clear(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void BackgroundTracingManagerImpl::SetTracingEnabledCallbackForTesting( |
| 300 const base::Closure& callback) { |
| 301 tracing_enabled_callback_for_testing_ = callback; |
| 302 }; |
| 303 |
| 299 void BackgroundTracingManagerImpl::FireTimerForTesting() { | 304 void BackgroundTracingManagerImpl::FireTimerForTesting() { |
| 300 tracing_timer_->FireTimerForTesting(); | 305 tracing_timer_->FireTimerForTesting(); |
| 301 } | 306 } |
| 302 | 307 |
| 303 void BackgroundTracingManagerImpl::EnableRecording( | 308 void BackgroundTracingManagerImpl::EnableRecording( |
| 304 std::string category_filter_str, | 309 std::string category_filter_str, |
| 305 base::trace_event::TraceRecordMode record_mode) { | 310 base::trace_event::TraceRecordMode record_mode) { |
| 311 base::trace_event::TraceConfig trace_config(category_filter_str, record_mode); |
| 312 if (requires_anonymized_data_) |
| 313 trace_config.EnableArgumentFilter(); |
| 314 |
| 306 is_tracing_ = TracingController::GetInstance()->EnableRecording( | 315 is_tracing_ = TracingController::GetInstance()->EnableRecording( |
| 307 base::trace_event::TraceConfig(category_filter_str, record_mode), | 316 trace_config, tracing_enabled_callback_for_testing_); |
| 308 TracingController::EnableRecordingDoneCallback()); | |
| 309 } | 317 } |
| 310 | 318 |
| 311 void BackgroundTracingManagerImpl::OnFinalizeStarted( | 319 void BackgroundTracingManagerImpl::OnFinalizeStarted( |
| 312 scoped_refptr<base::RefCountedString> file_contents) { | 320 scoped_refptr<base::RefCountedString> file_contents) { |
| 313 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 321 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 314 | 322 |
| 315 if (!receive_callback_.is_null()) | 323 if (!receive_callback_.is_null()) |
| 316 receive_callback_.Run( | 324 receive_callback_.Run( |
| 317 file_contents.get(), | 325 file_contents, |
| 318 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, | 326 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, |
| 319 base::Unretained(this))); | 327 base::Unretained(this))); |
| 320 } | 328 } |
| 321 | 329 |
| 322 void BackgroundTracingManagerImpl::OnFinalizeComplete() { | 330 void BackgroundTracingManagerImpl::OnFinalizeComplete() { |
| 323 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 331 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 324 BrowserThread::PostTask( | 332 BrowserThread::PostTask( |
| 325 BrowserThread::UI, FROM_HERE, | 333 BrowserThread::UI, FROM_HERE, |
| 326 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, | 334 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, |
| 327 base::Unretained(this))); | 335 base::Unretained(this))); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 "disabled-by-default-toplevel.flow," | 369 "disabled-by-default-toplevel.flow," |
| 362 "disabled-by-default-ipc.flow"; | 370 "disabled-by-default-ipc.flow"; |
| 363 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: | 371 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: |
| 364 return "*,disabled-by-default-blink.debug.layout"; | 372 return "*,disabled-by-default-blink.debug.layout"; |
| 365 } | 373 } |
| 366 NOTREACHED(); | 374 NOTREACHED(); |
| 367 return ""; | 375 return ""; |
| 368 } | 376 } |
| 369 | 377 |
| 370 } // namspace content | 378 } // namspace content |
| OLD | NEW |