| 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" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/tracing_delegate.h" |
| 14 #include "content/public/common/content_client.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = | 20 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = |
| 18 LAZY_INSTANCE_INITIALIZER; | 21 LAZY_INSTANCE_INITIALIZER; |
| 19 | 22 |
| 20 } // namespace | 23 } // namespace |
| 21 | 24 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 70 |
| 68 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { | 71 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { |
| 69 return BackgroundTracingManagerImpl::GetInstance(); | 72 return BackgroundTracingManagerImpl::GetInstance(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { | 75 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { |
| 73 return g_controller.Pointer(); | 76 return g_controller.Pointer(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() | 79 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() |
| 77 : is_gathering_(false), | 80 : delegate_(GetContentClient()->browser()->GetTracingDelegate()), |
| 81 is_gathering_(false), |
| 78 is_tracing_(false), | 82 is_tracing_(false), |
| 79 requires_anonymized_data_(true), | 83 requires_anonymized_data_(true), |
| 80 trigger_handle_ids_(0) { | 84 trigger_handle_ids_(0) { |
| 81 data_endpoint_wrapper_ = new TraceDataEndpointWrapper( | 85 data_endpoint_wrapper_ = new TraceDataEndpointWrapper( |
| 82 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted, | 86 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted, |
| 83 base::Unretained(this))); | 87 base::Unretained(this))); |
| 84 } | 88 } |
| 85 | 89 |
| 86 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() { | 90 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() { |
| 87 NOTREACHED(); | 91 NOTREACHED(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 132 } |
| 129 | 133 |
| 130 bool BackgroundTracingManagerImpl::SetActiveScenario( | 134 bool BackgroundTracingManagerImpl::SetActiveScenario( |
| 131 scoped_ptr<BackgroundTracingConfig> config, | 135 scoped_ptr<BackgroundTracingConfig> config, |
| 132 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 136 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
| 133 bool requires_anonymized_data) { | 137 bool requires_anonymized_data) { |
| 134 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 138 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 135 if (is_tracing_) | 139 if (is_tracing_) |
| 136 return false; | 140 return false; |
| 137 | 141 |
| 142 // TODO(oysteine): Retry when time_until_allowed has elapsed. |
| 143 if (config && delegate_ && |
| 144 !delegate_->IsAllowedToBeginBackgroundScenario( |
| 145 *config.get(), requires_anonymized_data)) { |
| 146 return false; |
| 147 } |
| 148 |
| 138 if (!IsSupportedConfig(config.get())) | 149 if (!IsSupportedConfig(config.get())) |
| 139 return false; | 150 return false; |
| 140 | 151 |
| 141 // No point in tracing if there's nowhere to send it. | 152 // No point in tracing if there's nowhere to send it. |
| 142 if (config && receive_callback.is_null()) | 153 if (config && receive_callback.is_null()) |
| 143 return false; | 154 return false; |
| 144 | 155 |
| 145 config_ = config.Pass(); | 156 config_ = config.Pass(); |
| 146 receive_callback_ = receive_callback; | 157 receive_callback_ = receive_callback; |
| 147 requires_anonymized_data_ = requires_anonymized_data; | 158 requires_anonymized_data_ = requires_anonymized_data; |
| 148 | 159 |
| 149 EnableRecordingIfConfigNeedsIt(); | 160 EnableRecordingIfConfigNeedsIt(); |
| 150 | 161 |
| 151 return true; | 162 return true; |
| 152 } | 163 } |
| 153 | 164 |
| 154 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { | 165 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { |
| 155 if (!config_) | 166 if (!config_) |
| 156 return; | 167 return; |
| 157 | 168 |
| 169 // TODO(oysteine): Retry later. |
| 170 if (delegate_ && |
| 171 !delegate_->IsAllowedToBeginBackgroundScenario( |
| 172 *config_.get(), requires_anonymized_data_)) { |
| 173 return; |
| 174 } |
| 175 |
| 158 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 176 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| 159 EnableRecording(GetCategoryFilterStringForCategoryPreset( | 177 EnableRecording(GetCategoryFilterStringForCategoryPreset( |
| 160 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) | 178 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) |
| 161 ->category_preset), | 179 ->category_preset), |
| 162 base::trace_event::RECORD_CONTINUOUSLY); | 180 base::trace_event::RECORD_CONTINUOUSLY); |
| 163 } | 181 } |
| 164 // There is nothing to do in case of reactive tracing. | 182 // There is nothing to do in case of reactive tracing. |
| 165 } | 183 } |
| 166 | 184 |
| 167 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( | 185 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 355 |
| 338 // Now that a trace has completed, we may need to enable recording again. | 356 // Now that a trace has completed, we may need to enable recording again. |
| 339 EnableRecordingIfConfigNeedsIt(); | 357 EnableRecordingIfConfigNeedsIt(); |
| 340 } | 358 } |
| 341 | 359 |
| 342 void BackgroundTracingManagerImpl::BeginFinalizing( | 360 void BackgroundTracingManagerImpl::BeginFinalizing( |
| 343 StartedFinalizingCallback callback) { | 361 StartedFinalizingCallback callback) { |
| 344 is_gathering_ = true; | 362 is_gathering_ = true; |
| 345 is_tracing_ = false; | 363 is_tracing_ = false; |
| 346 | 364 |
| 347 content::TracingController::GetInstance()->DisableRecording( | 365 bool is_allowed_finalization = |
| 348 content::TracingController::CreateCompressedStringSink( | 366 !delegate_ || (config_ && |
| 349 data_endpoint_wrapper_)); | 367 delegate_->IsAllowedToEndBackgroundScenario( |
| 368 *config_.get(), requires_anonymized_data_)); |
| 369 |
| 370 scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink; |
| 371 if (is_allowed_finalization) { |
| 372 trace_data_sink = content::TracingController::CreateCompressedStringSink( |
| 373 data_endpoint_wrapper_); |
| 374 } |
| 375 |
| 376 content::TracingController::GetInstance()->DisableRecording(trace_data_sink); |
| 350 | 377 |
| 351 if (!callback.is_null()) | 378 if (!callback.is_null()) |
| 352 callback.Run(true); | 379 callback.Run(is_allowed_finalization); |
| 353 } | 380 } |
| 354 | 381 |
| 355 std::string | 382 std::string |
| 356 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset( | 383 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset( |
| 357 BackgroundTracingConfig::CategoryPreset preset) const { | 384 BackgroundTracingConfig::CategoryPreset preset) const { |
| 358 switch (preset) { | 385 switch (preset) { |
| 359 case BackgroundTracingConfig::CategoryPreset::BENCHMARK: | 386 case BackgroundTracingConfig::CategoryPreset::BENCHMARK: |
| 360 return "benchmark," | 387 return "benchmark," |
| 361 "disabled-by-default-toplevel.flow," | 388 "disabled-by-default-toplevel.flow," |
| 362 "disabled-by-default-ipc.flow"; | 389 "disabled-by-default-ipc.flow"; |
| 363 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: | 390 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: |
| 364 return "*,disabled-by-default-blink.debug.layout"; | 391 return "*,disabled-by-default-blink.debug.layout"; |
| 365 } | 392 } |
| 366 NOTREACHED(); | 393 NOTREACHED(); |
| 367 return ""; | 394 return ""; |
| 368 } | 395 } |
| 369 | 396 |
| 370 } // namspace content | 397 } // namspace content |
| OLD | NEW |