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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 command_line->HasSwitch(switches::kDisableBlinkFeatures)) { | 171 command_line->HasSwitch(switches::kDisableBlinkFeatures)) { |
172 return false; | 172 return false; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 config_ = std::move(config_impl); | 176 config_ = std::move(config_impl); |
177 receive_callback_ = receive_callback; | 177 receive_callback_ = receive_callback; |
178 requires_anonymized_data_ = requires_anonymized_data; | 178 requires_anonymized_data_ = requires_anonymized_data; |
179 | 179 |
180 if (config_) { | 180 if (config_) { |
181 DCHECK(!config_.get()->rules().empty()); | 181 DCHECK(!config_->rules().empty()); |
182 for (auto* rule : config_.get()->rules()) | 182 for (const auto& rule : config_->rules()) |
183 static_cast<BackgroundTracingRule*>(rule)->Install(); | 183 rule->Install(); |
184 | 184 |
185 if (!config_->enable_blink_features().empty()) { | 185 if (!config_->enable_blink_features().empty()) { |
186 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 186 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
187 config_->enable_blink_features()); | 187 config_->enable_blink_features()); |
188 } | 188 } |
189 | 189 |
190 if (!config_->disable_blink_features().empty()) { | 190 if (!config_->disable_blink_features().empty()) { |
191 command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures, | 191 command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures, |
192 config_->disable_blink_features()); | 192 config_->disable_blink_features()); |
193 } | 193 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 // If the last trace is still uploading, we don't allow a new one to trigger. | 237 // If the last trace is still uploading, we don't allow a new one to trigger. |
238 if (is_gathering_) | 238 if (is_gathering_) |
239 return nullptr; | 239 return nullptr; |
240 | 240 |
241 if (!IsTriggerHandleValid(handle)) { | 241 if (!IsTriggerHandleValid(handle)) { |
242 return nullptr; | 242 return nullptr; |
243 } | 243 } |
244 | 244 |
245 std::string trigger_name = GetTriggerNameFromHandle(handle); | 245 std::string trigger_name = GetTriggerNameFromHandle(handle); |
246 for (auto* rule : config_.get()->rules()) { | 246 for (const auto& rule : config_->rules()) { |
247 if (static_cast<BackgroundTracingRule*>(rule) | 247 if (rule->ShouldTriggerNamedEvent(trigger_name)) |
248 ->ShouldTriggerNamedEvent(trigger_name)) | 248 return rule.get(); |
249 return static_cast<BackgroundTracingRule*>(rule); | |
250 } | 249 } |
251 | 250 |
252 return nullptr; | 251 return nullptr; |
253 } | 252 } |
254 | 253 |
255 void BackgroundTracingManagerImpl::OnHistogramTrigger( | 254 void BackgroundTracingManagerImpl::OnHistogramTrigger( |
256 const std::string& histogram_name) { | 255 const std::string& histogram_name) { |
257 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 256 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
258 content::BrowserThread::PostTask( | 257 content::BrowserThread::PostTask( |
259 content::BrowserThread::UI, FROM_HERE, | 258 content::BrowserThread::UI, FROM_HERE, |
260 base::Bind(&BackgroundTracingManagerImpl::OnHistogramTrigger, | 259 base::Bind(&BackgroundTracingManagerImpl::OnHistogramTrigger, |
261 base::Unretained(this), histogram_name)); | 260 base::Unretained(this), histogram_name)); |
262 return; | 261 return; |
263 } | 262 } |
264 | 263 |
265 for (auto* rule : config_->rules()) { | 264 for (const auto& rule : config_->rules()) { |
266 if (rule->ShouldTriggerNamedEvent(histogram_name)) | 265 if (rule->ShouldTriggerNamedEvent(histogram_name)) |
267 OnRuleTriggered(rule, StartedFinalizingCallback()); | 266 OnRuleTriggered(rule.get(), StartedFinalizingCallback()); |
268 } | 267 } |
269 } | 268 } |
270 | 269 |
271 void BackgroundTracingManagerImpl::TriggerNamedEvent( | 270 void BackgroundTracingManagerImpl::TriggerNamedEvent( |
272 BackgroundTracingManagerImpl::TriggerHandle handle, | 271 BackgroundTracingManagerImpl::TriggerHandle handle, |
273 StartedFinalizingCallback callback) { | 272 StartedFinalizingCallback callback) { |
274 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 273 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
275 content::BrowserThread::PostTask( | 274 content::BrowserThread::PostTask( |
276 content::BrowserThread::UI, FROM_HERE, | 275 content::BrowserThread::UI, FROM_HERE, |
277 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, | 276 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: | 566 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: |
568 return "blink_style"; | 567 return "blink_style"; |
569 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: | 568 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: |
570 NOTREACHED(); | 569 NOTREACHED(); |
571 } | 570 } |
572 NOTREACHED(); | 571 NOTREACHED(); |
573 return ""; | 572 return ""; |
574 } | 573 } |
575 | 574 |
576 } // namspace content | 575 } // namspace content |
OLD | NEW |