Chromium Code Reviews| Index: content/browser/tracing/background_tracing_manager_impl.cc |
| diff --git a/content/browser/tracing/background_tracing_manager_impl.cc b/content/browser/tracing/background_tracing_manager_impl.cc |
| index 64326d95a73feef83100e9bc721f356b1445517f..9f8b76c6e57ae0f3372581527f224cfcd348f3bf 100644 |
| --- a/content/browser/tracing/background_tracing_manager_impl.cc |
| +++ b/content/browser/tracing/background_tracing_manager_impl.cc |
| @@ -5,6 +5,7 @@ |
| #include "content/browser/tracing/background_tracing_manager_impl.h" |
| #include "base/macros.h" |
| +#include "base/time/time.h" |
| #include "content/public/browser/background_tracing_preemptive_config.h" |
| #include "content/public/browser/background_tracing_reactive_config.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -38,6 +39,27 @@ void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: |
| base::Bind(done_callback_, contents_ptr)); |
| } |
| +BackgroundTracingManagerImpl::TracingTimer:: |
| + TracingTimer(StartedFinalizingCallback callback) : callback_(callback) { |
| +} |
| + |
| +BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { |
| +} |
| + |
| +void BackgroundTracingManagerImpl::TracingTimer::StartTimer() { |
| + |
|
shatch
2015/06/01 15:33:33
nit: Remove blank line.
fmeawad
2015/06/01 18:15:26
Done.
|
| + tracing_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(10), this, |
| + &BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired); |
| +} |
| + |
| +void BackgroundTracingManagerImpl::TracingTimer::CancelTimer() { |
| + tracing_timer_.Stop(); |
| +} |
| + |
| +void BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired() { |
| + BackgroundTracingManagerImpl::GetInstance()->BeginFinalizing(callback_); |
| +} |
| + |
| BackgroundTracingManager* BackgroundTracingManager::GetInstance() { |
| return BackgroundTracingManagerImpl::GetInstance(); |
| } |
| @@ -72,19 +94,30 @@ bool BackgroundTracingManagerImpl::IsSupportedConfig( |
| if (!config) |
| return true; |
| - // TODO(simonhatch): Implement reactive tracing path. |
| - if (config->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) |
| - return false; |
| + if (config->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| + BackgroundTracingPreemptiveConfig* preemptive_config = |
| + static_cast<BackgroundTracingPreemptiveConfig*>(config); |
| + const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& |
| + configs = preemptive_config->configs; |
| + for (size_t i = 0; i < configs.size(); ++i) { |
| + if (configs[i].type != |
| + BackgroundTracingPreemptiveConfig:: |
| + MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) |
| + return false; |
| + } |
| + } |
| - // TODO(fmeawad): Implement uma triggers. |
| - BackgroundTracingPreemptiveConfig* preemptive_config = |
| - static_cast<BackgroundTracingPreemptiveConfig*>(config); |
| - const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& |
| - configs = preemptive_config->configs; |
| - for (size_t i = 0; i < configs.size(); ++i) { |
| - if (configs[i].type != |
| - BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) |
| - return false; |
| + if (config->mode == BackgroundTracingConfig::REACTIVE_TRACING_MODE) { |
| + BackgroundTracingReactiveConfig* reactive_config = |
| + static_cast<BackgroundTracingReactiveConfig*>(config); |
| + const std::vector<BackgroundTracingReactiveConfig::TracingRule>& |
| + configs = reactive_config->configs; |
| + for (size_t i = 0; i < configs.size(); ++i) { |
| + if (configs[i].type != |
| + BackgroundTracingReactiveConfig:: |
| + TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) |
| + return false; |
| + } |
| } |
| return true; |
| @@ -123,8 +156,7 @@ void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { |
| static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) |
| ->category_preset)); |
| } else { |
| - // TODO(simonhatch): Implement reactive tracing path. |
| - NOTREACHED(); |
| + // There is nothing to do in case of reactive tracing. |
| } |
| } |
| @@ -160,10 +192,22 @@ bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( |
| } |
| } |
| } else { |
| - // TODO(simonhatch): Implement reactive path. |
| - NOTREACHED(); |
| - } |
| + BackgroundTracingReactiveConfig* reactive_config = |
| + static_cast<BackgroundTracingReactiveConfig*>(config_.get()); |
| + const std::vector<BackgroundTracingReactiveConfig::TracingRule>& |
| + configs = reactive_config->configs; |
| + |
| + for (size_t i = 0; i < configs.size(); ++i) { |
| + if (configs[i].type != |
| + BackgroundTracingReactiveConfig:: |
| + TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) |
| + continue; |
| + if (trigger_name == configs[i].trigger_name) { |
| + return true; |
| + } |
| + } |
| + } |
| return false; |
| } |
| @@ -187,8 +231,26 @@ void BackgroundTracingManagerImpl::TriggerNamedEvent( |
| if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| BeginFinalizing(callback); |
| } else { |
| - // TODO(simonhatch): Implement reactive tracing path. |
| - NOTREACHED(); |
| + if (is_tracing_) { |
| + tracing_timer_->CancelTimer(); |
| + BeginFinalizing(callback); |
| + return; |
| + } else { |
| + BackgroundTracingReactiveConfig* reactive_config = |
| + static_cast<BackgroundTracingReactiveConfig*>(config_.get()); |
| + const std::vector<BackgroundTracingReactiveConfig::TracingRule>& |
| + configs = reactive_config->configs; |
| + std::string trigger_name = GetTriggerNameFromHandle(handle); |
| + for (size_t i = 0; i < configs.size(); ++i) { |
| + if (configs[i].trigger_name == trigger_name) { |
| + EnableRecording( |
| + GetCategoryFilterForCategoryPreset(configs[i].category_preset)); |
| + tracing_timer_.reset(new TracingTimer(callback)); |
| + tracing_timer_->StartTimer(); |
| + break; |
| + } |
| + } |
| + } |
| } |
| } |