Chromium Code Reviews| 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 "content/public/browser/background_tracing_preemptive_config.h" | 9 #include "content/public/browser/background_tracing_preemptive_config.h" |
| 9 #include "content/public/browser/background_tracing_reactive_config.h" | 10 #include "content/public/browser/background_tracing_reactive_config.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = | 17 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = |
| 17 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 31 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: | 32 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: |
| 32 ReceiveTraceFinalContents(const std::string& file_contents) { | 33 ReceiveTraceFinalContents(const std::string& file_contents) { |
| 33 std::string tmp = file_contents; | 34 std::string tmp = file_contents; |
| 34 scoped_refptr<base::RefCountedString> contents_ptr = | 35 scoped_refptr<base::RefCountedString> contents_ptr = |
| 35 base::RefCountedString::TakeString(&tmp); | 36 base::RefCountedString::TakeString(&tmp); |
| 36 | 37 |
| 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 38 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 38 base::Bind(done_callback_, contents_ptr)); | 39 base::Bind(done_callback_, contents_ptr)); |
| 39 } | 40 } |
| 40 | 41 |
| 42 BackgroundTracingManagerImpl::TracingTimer:: | |
| 43 TracingTimer(StartedFinalizingCallback callback) : callback_(callback) { | |
|
dsinclair
2015/06/01 19:14:52
I think it's more common to wrap at the params the
fmeawad
2015/06/02 21:15:28
Done.
| |
| 44 } | |
| 45 | |
| 46 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { | |
| 47 } | |
| 48 | |
| 49 void BackgroundTracingManagerImpl::TracingTimer::StartTimer() { | |
| 50 tracing_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(10), this, | |
| 51 &BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired); | |
| 52 } | |
| 53 | |
| 54 void BackgroundTracingManagerImpl::TracingTimer::CancelTimer() { | |
| 55 tracing_timer_.Stop(); | |
| 56 } | |
| 57 | |
| 58 void BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired() { | |
| 59 BackgroundTracingManagerImpl::GetInstance()->BeginFinalizing(callback_); | |
| 60 } | |
| 61 | |
| 41 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { | 62 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { |
| 42 return BackgroundTracingManagerImpl::GetInstance(); | 63 return BackgroundTracingManagerImpl::GetInstance(); |
| 43 } | 64 } |
| 44 | 65 |
| 45 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { | 66 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { |
| 46 return g_controller.Pointer(); | 67 return g_controller.Pointer(); |
| 47 } | 68 } |
| 48 | 69 |
| 49 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() | 70 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() |
| 50 : is_gathering_(false), | 71 : is_gathering_(false), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 65 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 86 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 66 idle_callback_ = idle_callback; | 87 idle_callback_ = idle_callback; |
| 67 } | 88 } |
| 68 | 89 |
| 69 bool BackgroundTracingManagerImpl::IsSupportedConfig( | 90 bool BackgroundTracingManagerImpl::IsSupportedConfig( |
| 70 BackgroundTracingConfig* config) { | 91 BackgroundTracingConfig* config) { |
| 71 // No config is just fine, we just don't do anything. | 92 // No config is just fine, we just don't do anything. |
| 72 if (!config) | 93 if (!config) |
| 73 return true; | 94 return true; |
| 74 | 95 |
| 75 // TODO(simonhatch): Implement reactive tracing path. | 96 if (config->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| 76 if (config->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) | 97 BackgroundTracingPreemptiveConfig* preemptive_config = |
| 77 return false; | 98 static_cast<BackgroundTracingPreemptiveConfig*>(config); |
| 99 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& | |
| 100 configs = preemptive_config->configs; | |
| 101 for (size_t i = 0; i < configs.size(); ++i) { | |
| 102 if (configs[i].type != | |
| 103 BackgroundTracingPreemptiveConfig:: | |
| 104 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | |
| 105 return false; | |
| 106 } | |
| 107 } | |
| 78 | 108 |
| 79 // TODO(fmeawad): Implement uma triggers. | 109 if (config->mode == BackgroundTracingConfig::REACTIVE_TRACING_MODE) { |
| 80 BackgroundTracingPreemptiveConfig* preemptive_config = | 110 BackgroundTracingReactiveConfig* reactive_config = |
| 81 static_cast<BackgroundTracingPreemptiveConfig*>(config); | 111 static_cast<BackgroundTracingReactiveConfig*>(config); |
| 82 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& | 112 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& |
|
dsinclair
2015/06/01 19:14:53
What's the difference between monitoringRules and
fmeawad
2015/06/02 21:15:28
It is more of an explanation using variable names,
| |
| 83 configs = preemptive_config->configs; | 113 configs = reactive_config->configs; |
| 84 for (size_t i = 0; i < configs.size(); ++i) { | 114 for (size_t i = 0; i < configs.size(); ++i) { |
| 85 if (configs[i].type != | 115 if (configs[i].type != |
| 86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | 116 BackgroundTracingReactiveConfig:: |
| 87 return false; | 117 TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) |
| 118 return false; | |
| 119 } | |
| 88 } | 120 } |
| 89 | 121 |
| 90 return true; | 122 return true; |
| 91 } | 123 } |
| 92 | 124 |
| 93 bool BackgroundTracingManagerImpl::SetActiveScenario( | 125 bool BackgroundTracingManagerImpl::SetActiveScenario( |
| 94 scoped_ptr<BackgroundTracingConfig> config, | 126 scoped_ptr<BackgroundTracingConfig> config, |
| 95 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 127 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
| 96 bool requires_anonymized_data) { | 128 bool requires_anonymized_data) { |
| 97 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 129 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 116 | 148 |
| 117 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { | 149 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { |
| 118 if (!config_) | 150 if (!config_) |
| 119 return; | 151 return; |
| 120 | 152 |
| 121 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 153 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| 122 EnableRecording(GetCategoryFilterForCategoryPreset( | 154 EnableRecording(GetCategoryFilterForCategoryPreset( |
| 123 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) | 155 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) |
| 124 ->category_preset)); | 156 ->category_preset)); |
| 125 } else { | 157 } else { |
| 126 // TODO(simonhatch): Implement reactive tracing path. | 158 // There is nothing to do in case of reactive tracing. |
|
dsinclair
2015/06/01 19:14:53
Let's remove the else in that case. Just put the c
fmeawad
2015/06/02 21:15:28
Done.
| |
| 127 NOTREACHED(); | |
| 128 } | 159 } |
| 129 } | 160 } |
| 130 | 161 |
| 131 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( | 162 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( |
| 132 TriggerHandle handle) const { | 163 TriggerHandle handle) const { |
| 133 if (!config_) | 164 if (!config_) |
| 134 return false; | 165 return false; |
| 135 | 166 |
| 136 // If the last trace is still uploading, we don't allow a new one to trigger. | 167 // If the last trace is still uploading, we don't allow a new one to trigger. |
| 137 if (is_gathering_) | 168 if (is_gathering_) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 153 for (size_t i = 0; i < configs.size(); ++i) { | 184 for (size_t i = 0; i < configs.size(); ++i) { |
| 154 if (configs[i].type != BackgroundTracingPreemptiveConfig:: | 185 if (configs[i].type != BackgroundTracingPreemptiveConfig:: |
| 155 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | 186 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) |
| 156 continue; | 187 continue; |
| 157 | 188 |
| 158 if (trigger_name == configs[i].named_trigger_info.trigger_name) { | 189 if (trigger_name == configs[i].named_trigger_info.trigger_name) { |
| 159 return true; | 190 return true; |
| 160 } | 191 } |
| 161 } | 192 } |
| 162 } else { | 193 } else { |
| 163 // TODO(simonhatch): Implement reactive path. | 194 BackgroundTracingReactiveConfig* reactive_config = |
| 164 NOTREACHED(); | 195 static_cast<BackgroundTracingReactiveConfig*>(config_.get()); |
| 196 | |
| 197 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& | |
| 198 configs = reactive_config->configs; | |
| 199 | |
| 200 for (size_t i = 0; i < configs.size(); ++i) { | |
| 201 if (configs[i].type != | |
| 202 BackgroundTracingReactiveConfig:: | |
| 203 TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) | |
| 204 continue; | |
| 205 if (trigger_name == configs[i].trigger_name) { | |
| 206 return true; | |
| 207 } | |
| 208 } | |
| 165 } | 209 } |
| 166 | |
| 167 return false; | 210 return false; |
| 168 } | 211 } |
| 169 | 212 |
| 170 void BackgroundTracingManagerImpl::TriggerNamedEvent( | 213 void BackgroundTracingManagerImpl::TriggerNamedEvent( |
| 171 BackgroundTracingManagerImpl::TriggerHandle handle, | 214 BackgroundTracingManagerImpl::TriggerHandle handle, |
| 172 StartedFinalizingCallback callback) { | 215 StartedFinalizingCallback callback) { |
| 173 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 216 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 174 content::BrowserThread::PostTask( | 217 content::BrowserThread::PostTask( |
| 175 content::BrowserThread::UI, FROM_HERE, | 218 content::BrowserThread::UI, FROM_HERE, |
| 176 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, | 219 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, |
| 177 base::Unretained(this), handle, callback)); | 220 base::Unretained(this), handle, callback)); |
| 178 return; | 221 return; |
| 179 } | 222 } |
| 180 | 223 |
| 181 if (!IsAbleToTriggerTracing(handle)) { | 224 if (!IsAbleToTriggerTracing(handle)) { |
| 182 if (!callback.is_null()) | 225 if (!callback.is_null()) |
| 183 callback.Run(false); | 226 callback.Run(false); |
| 184 return; | 227 return; |
| 185 } | 228 } |
| 186 | 229 |
| 187 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 230 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
| 188 BeginFinalizing(callback); | 231 BeginFinalizing(callback); |
| 189 } else { | 232 } else { |
| 190 // TODO(simonhatch): Implement reactive tracing path. | 233 if (is_tracing_) { |
| 191 NOTREACHED(); | 234 tracing_timer_->CancelTimer(); |
| 235 BeginFinalizing(callback); | |
|
dsinclair
2015/06/01 19:14:52
Is there a race condition in here? The BeginFinali
fmeawad
2015/06/02 21:15:28
This code will not be reached on the second trigge
| |
| 236 return; | |
| 237 } else { | |
|
dsinclair
2015/06/01 19:14:52
The above returned, so don't need the else.
fmeawad
2015/06/02 21:15:28
Done.
| |
| 238 BackgroundTracingReactiveConfig* reactive_config = | |
| 239 static_cast<BackgroundTracingReactiveConfig*>(config_.get()); | |
| 240 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& | |
| 241 configs = reactive_config->configs; | |
| 242 std::string trigger_name = GetTriggerNameFromHandle(handle); | |
| 243 for (size_t i = 0; i < configs.size(); ++i) { | |
| 244 if (configs[i].trigger_name == trigger_name) { | |
| 245 EnableRecording( | |
| 246 GetCategoryFilterForCategoryPreset(configs[i].category_preset)); | |
| 247 tracing_timer_.reset(new TracingTimer(callback)); | |
| 248 tracing_timer_->StartTimer(); | |
| 249 break; | |
| 250 } | |
| 251 } | |
| 252 } | |
| 192 } | 253 } |
| 193 } | 254 } |
| 194 | 255 |
| 195 BackgroundTracingManagerImpl::TriggerHandle | 256 BackgroundTracingManagerImpl::TriggerHandle |
| 196 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) { | 257 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) { |
| 197 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 258 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 198 | 259 |
| 199 trigger_handle_ids_ += 1; | 260 trigger_handle_ids_ += 1; |
| 200 | 261 |
| 201 trigger_handles_.insert( | 262 trigger_handles_.insert( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 return NULL; | 364 return NULL; |
| 304 } | 365 } |
| 305 | 366 |
| 306 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, | 367 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, |
| 307 base::DictionaryValue* dict) { | 368 base::DictionaryValue* dict) { |
| 308 // TODO(simonhatch): Implement this. | 369 // TODO(simonhatch): Implement this. |
| 309 CHECK(false); | 370 CHECK(false); |
| 310 } | 371 } |
| 311 | 372 |
| 312 } // namspace content | 373 } // namspace content |
| OLD | NEW |