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 #include "content/browser/tracing/background_tracing_rule.h" | 4 #include "content/browser/tracing/background_tracing_rule.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 namespace { | 87 namespace { |
88 | 88 |
89 class NamedTriggerRule : public BackgroundTracingRule { | 89 class NamedTriggerRule : public BackgroundTracingRule { |
90 private: | 90 private: |
91 NamedTriggerRule(const std::string& named_event) | 91 NamedTriggerRule(const std::string& named_event) |
92 : named_event_(named_event) {} | 92 : named_event_(named_event) {} |
93 | 93 |
94 public: | 94 public: |
95 static scoped_ptr<BackgroundTracingRule> Create( | 95 static std::unique_ptr<BackgroundTracingRule> Create( |
96 const base::DictionaryValue* dict) { | 96 const base::DictionaryValue* dict) { |
97 std::string trigger_name; | 97 std::string trigger_name; |
98 if (!dict->GetString(kConfigRuleTriggerNameKey, &trigger_name)) | 98 if (!dict->GetString(kConfigRuleTriggerNameKey, &trigger_name)) |
99 return nullptr; | 99 return nullptr; |
100 | 100 |
101 return scoped_ptr<BackgroundTracingRule>( | 101 return std::unique_ptr<BackgroundTracingRule>( |
102 new NamedTriggerRule(trigger_name)); | 102 new NamedTriggerRule(trigger_name)); |
103 } | 103 } |
104 | 104 |
105 void IntoDict(base::DictionaryValue* dict) const override { | 105 void IntoDict(base::DictionaryValue* dict) const override { |
106 DCHECK(dict); | 106 DCHECK(dict); |
107 BackgroundTracingRule::IntoDict(dict); | 107 BackgroundTracingRule::IntoDict(dict); |
108 dict->SetString(kConfigRuleKey, kPreemptiveConfigRuleMonitorNamed); | 108 dict->SetString(kConfigRuleKey, kPreemptiveConfigRuleMonitorNamed); |
109 dict->SetString(kConfigRuleTriggerNameKey, named_event_.c_str()); | 109 dict->SetString(kConfigRuleTriggerNameKey, named_event_.c_str()); |
110 } | 110 } |
111 | 111 |
(...skipping 13 matching lines...) Expand all Loading... |
125 int histogram_upper_value, | 125 int histogram_upper_value, |
126 bool repeat, | 126 bool repeat, |
127 int trigger_delay) | 127 int trigger_delay) |
128 : histogram_name_(histogram_name), | 128 : histogram_name_(histogram_name), |
129 histogram_lower_value_(histogram_lower_value), | 129 histogram_lower_value_(histogram_lower_value), |
130 histogram_upper_value_(histogram_upper_value), | 130 histogram_upper_value_(histogram_upper_value), |
131 repeat_(repeat), | 131 repeat_(repeat), |
132 trigger_delay_(trigger_delay) {} | 132 trigger_delay_(trigger_delay) {} |
133 | 133 |
134 public: | 134 public: |
135 static scoped_ptr<BackgroundTracingRule> Create( | 135 static std::unique_ptr<BackgroundTracingRule> Create( |
136 const base::DictionaryValue* dict) { | 136 const base::DictionaryValue* dict) { |
137 std::string histogram_name; | 137 std::string histogram_name; |
138 if (!dict->GetString(kConfigRuleHistogramNameKey, &histogram_name)) | 138 if (!dict->GetString(kConfigRuleHistogramNameKey, &histogram_name)) |
139 return nullptr; | 139 return nullptr; |
140 | 140 |
141 // Optional parameter, so we don't need to check if the key exists. | 141 // Optional parameter, so we don't need to check if the key exists. |
142 bool repeat = true; | 142 bool repeat = true; |
143 dict->GetBoolean(kConfigRuleHistogramRepeatKey, &repeat); | 143 dict->GetBoolean(kConfigRuleHistogramRepeatKey, &repeat); |
144 | 144 |
145 int histogram_lower_value; | 145 int histogram_lower_value; |
146 int histogram_upper_value = std::numeric_limits<int>::max(); | 146 int histogram_upper_value = std::numeric_limits<int>::max(); |
147 | 147 |
148 if (!dict->GetInteger(kConfigRuleHistogramValue1Key, | 148 if (!dict->GetInteger(kConfigRuleHistogramValue1Key, |
149 &histogram_lower_value)) { | 149 &histogram_lower_value)) { |
150 // Check for the old naming. | 150 // Check for the old naming. |
151 if (!dict->GetInteger(kConfigRuleHistogramValueOldKey, | 151 if (!dict->GetInteger(kConfigRuleHistogramValueOldKey, |
152 &histogram_lower_value)) | 152 &histogram_lower_value)) |
153 return nullptr; | 153 return nullptr; |
154 } | 154 } |
155 | 155 |
156 dict->GetInteger(kConfigRuleHistogramValue2Key, &histogram_upper_value); | 156 dict->GetInteger(kConfigRuleHistogramValue2Key, &histogram_upper_value); |
157 | 157 |
158 if (histogram_lower_value >= histogram_upper_value) | 158 if (histogram_lower_value >= histogram_upper_value) |
159 return nullptr; | 159 return nullptr; |
160 | 160 |
161 int trigger_delay = -1; | 161 int trigger_delay = -1; |
162 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay); | 162 dict->GetInteger(kConfigRuleTriggerDelay, &trigger_delay); |
163 | 163 |
164 return scoped_ptr<BackgroundTracingRule>( | 164 return std::unique_ptr<BackgroundTracingRule>( |
165 new HistogramRule(histogram_name, histogram_lower_value, | 165 new HistogramRule(histogram_name, histogram_lower_value, |
166 histogram_upper_value, repeat, trigger_delay)); | 166 histogram_upper_value, repeat, trigger_delay)); |
167 } | 167 } |
168 | 168 |
169 ~HistogramRule() override { | 169 ~HistogramRule() override { |
170 base::StatisticsRecorder::ClearCallback(histogram_name_); | 170 base::StatisticsRecorder::ClearCallback(histogram_name_); |
171 TracingControllerImpl::GetInstance()->RemoveTraceMessageFilterObserver( | 171 TracingControllerImpl::GetInstance()->RemoveTraceMessageFilterObserver( |
172 this); | 172 this); |
173 } | 173 } |
174 | 174 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 }; | 256 }; |
257 | 257 |
258 class ReactiveTraceForNSOrTriggerOrFullRule : public BackgroundTracingRule { | 258 class ReactiveTraceForNSOrTriggerOrFullRule : public BackgroundTracingRule { |
259 private: | 259 private: |
260 ReactiveTraceForNSOrTriggerOrFullRule( | 260 ReactiveTraceForNSOrTriggerOrFullRule( |
261 const std::string& named_event, | 261 const std::string& named_event, |
262 BackgroundTracingConfigImpl::CategoryPreset category_preset) | 262 BackgroundTracingConfigImpl::CategoryPreset category_preset) |
263 : named_event_(named_event), category_preset_(category_preset) {} | 263 : named_event_(named_event), category_preset_(category_preset) {} |
264 | 264 |
265 public: | 265 public: |
266 static scoped_ptr<BackgroundTracingRule> Create( | 266 static std::unique_ptr<BackgroundTracingRule> Create( |
267 const base::DictionaryValue* dict, | 267 const base::DictionaryValue* dict, |
268 BackgroundTracingConfigImpl::CategoryPreset category_preset) { | 268 BackgroundTracingConfigImpl::CategoryPreset category_preset) { |
269 std::string trigger_name; | 269 std::string trigger_name; |
270 if (!dict->GetString(kConfigRuleTriggerNameKey, &trigger_name)) | 270 if (!dict->GetString(kConfigRuleTriggerNameKey, &trigger_name)) |
271 return nullptr; | 271 return nullptr; |
272 | 272 |
273 return scoped_ptr<BackgroundTracingRule>( | 273 return std::unique_ptr<BackgroundTracingRule>( |
274 new ReactiveTraceForNSOrTriggerOrFullRule(trigger_name, | 274 new ReactiveTraceForNSOrTriggerOrFullRule(trigger_name, |
275 category_preset)); | 275 category_preset)); |
276 } | 276 } |
277 | 277 |
278 // BackgroundTracingRule implementation | 278 // BackgroundTracingRule implementation |
279 void IntoDict(base::DictionaryValue* dict) const override { | 279 void IntoDict(base::DictionaryValue* dict) const override { |
280 DCHECK(dict); | 280 DCHECK(dict); |
281 BackgroundTracingRule::IntoDict(dict); | 281 BackgroundTracingRule::IntoDict(dict); |
282 dict->SetString( | 282 dict->SetString( |
283 kConfigCategoryKey, | 283 kConfigCategoryKey, |
(...skipping 27 matching lines...) Expand all Loading... |
311 BackgroundTracingConfigImpl::CategoryPreset category_preset, | 311 BackgroundTracingConfigImpl::CategoryPreset category_preset, |
312 int timeout_min, | 312 int timeout_min, |
313 int timeout_max) | 313 int timeout_max) |
314 : category_preset_(category_preset), | 314 : category_preset_(category_preset), |
315 timeout_min_(timeout_min), | 315 timeout_min_(timeout_min), |
316 timeout_max_(timeout_max) { | 316 timeout_max_(timeout_max) { |
317 named_event_ = GenerateUniqueName(); | 317 named_event_ = GenerateUniqueName(); |
318 } | 318 } |
319 | 319 |
320 public: | 320 public: |
321 static scoped_ptr<BackgroundTracingRule> Create( | 321 static std::unique_ptr<BackgroundTracingRule> Create( |
322 const base::DictionaryValue* dict, | 322 const base::DictionaryValue* dict, |
323 BackgroundTracingConfigImpl::CategoryPreset category_preset) { | 323 BackgroundTracingConfigImpl::CategoryPreset category_preset) { |
324 int timeout_min; | 324 int timeout_min; |
325 if (!dict->GetInteger(kConfigRuleRandomIntervalTimeoutMin, &timeout_min)) | 325 if (!dict->GetInteger(kConfigRuleRandomIntervalTimeoutMin, &timeout_min)) |
326 return nullptr; | 326 return nullptr; |
327 | 327 |
328 int timeout_max; | 328 int timeout_max; |
329 if (!dict->GetInteger(kConfigRuleRandomIntervalTimeoutMax, &timeout_max)) | 329 if (!dict->GetInteger(kConfigRuleRandomIntervalTimeoutMax, &timeout_max)) |
330 return nullptr; | 330 return nullptr; |
331 | 331 |
332 if (timeout_min > timeout_max) | 332 if (timeout_min > timeout_max) |
333 return nullptr; | 333 return nullptr; |
334 | 334 |
335 return scoped_ptr<BackgroundTracingRule>( | 335 return std::unique_ptr<BackgroundTracingRule>( |
336 new ReactiveTraceAtRandomIntervalsRule(category_preset, timeout_min, | 336 new ReactiveTraceAtRandomIntervalsRule(category_preset, timeout_min, |
337 timeout_max)); | 337 timeout_max)); |
338 } | 338 } |
339 ~ReactiveTraceAtRandomIntervalsRule() override {} | 339 ~ReactiveTraceAtRandomIntervalsRule() override {} |
340 | 340 |
341 void IntoDict(base::DictionaryValue* dict) const override { | 341 void IntoDict(base::DictionaryValue* dict) const override { |
342 DCHECK(dict); | 342 DCHECK(dict); |
343 BackgroundTracingRule::IntoDict(dict); | 343 BackgroundTracingRule::IntoDict(dict); |
344 dict->SetString( | 344 dict->SetString( |
345 kConfigCategoryKey, | 345 kConfigCategoryKey, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 std::string named_event_; | 404 std::string named_event_; |
405 base::OneShotTimer trigger_timer_; | 405 base::OneShotTimer trigger_timer_; |
406 BackgroundTracingConfigImpl::CategoryPreset category_preset_; | 406 BackgroundTracingConfigImpl::CategoryPreset category_preset_; |
407 BackgroundTracingManagerImpl::TriggerHandle handle_; | 407 BackgroundTracingManagerImpl::TriggerHandle handle_; |
408 int timeout_min_; | 408 int timeout_min_; |
409 int timeout_max_; | 409 int timeout_max_; |
410 }; | 410 }; |
411 | 411 |
412 } // namespace | 412 } // namespace |
413 | 413 |
414 scoped_ptr<BackgroundTracingRule> BackgroundTracingRule::PreemptiveRuleFromDict( | 414 std::unique_ptr<BackgroundTracingRule> |
| 415 BackgroundTracingRule::PreemptiveRuleFromDict( |
415 const base::DictionaryValue* dict) { | 416 const base::DictionaryValue* dict) { |
416 DCHECK(dict); | 417 DCHECK(dict); |
417 | 418 |
418 std::string type; | 419 std::string type; |
419 if (!dict->GetString(kConfigRuleKey, &type)) | 420 if (!dict->GetString(kConfigRuleKey, &type)) |
420 return nullptr; | 421 return nullptr; |
421 | 422 |
422 scoped_ptr<BackgroundTracingRule> tracing_rule; | 423 std::unique_ptr<BackgroundTracingRule> tracing_rule; |
423 if (type == kPreemptiveConfigRuleMonitorNamed) | 424 if (type == kPreemptiveConfigRuleMonitorNamed) |
424 tracing_rule = NamedTriggerRule::Create(dict); | 425 tracing_rule = NamedTriggerRule::Create(dict); |
425 else if (type == kPreemptiveConfigRuleMonitorHistogram) | 426 else if (type == kPreemptiveConfigRuleMonitorHistogram) |
426 tracing_rule = HistogramRule::Create(dict); | 427 tracing_rule = HistogramRule::Create(dict); |
427 | 428 |
428 if (tracing_rule) | 429 if (tracing_rule) |
429 tracing_rule->Setup(dict); | 430 tracing_rule->Setup(dict); |
430 | 431 |
431 return tracing_rule; | 432 return tracing_rule; |
432 } | 433 } |
433 | 434 |
434 scoped_ptr<BackgroundTracingRule> BackgroundTracingRule::ReactiveRuleFromDict( | 435 std::unique_ptr<BackgroundTracingRule> |
| 436 BackgroundTracingRule::ReactiveRuleFromDict( |
435 const base::DictionaryValue* dict, | 437 const base::DictionaryValue* dict, |
436 BackgroundTracingConfigImpl::CategoryPreset category_preset) { | 438 BackgroundTracingConfigImpl::CategoryPreset category_preset) { |
437 DCHECK(dict); | 439 DCHECK(dict); |
438 | 440 |
439 std::string type; | 441 std::string type; |
440 if (!dict->GetString(kConfigRuleKey, &type)) | 442 if (!dict->GetString(kConfigRuleKey, &type)) |
441 return nullptr; | 443 return nullptr; |
442 | 444 |
443 scoped_ptr<BackgroundTracingRule> tracing_rule; | 445 std::unique_ptr<BackgroundTracingRule> tracing_rule; |
444 | 446 |
445 if (type == kReactiveConfigRuleTraceOnNavigationUntilTriggerOrFull) { | 447 if (type == kReactiveConfigRuleTraceOnNavigationUntilTriggerOrFull) { |
446 tracing_rule = | 448 tracing_rule = |
447 ReactiveTraceForNSOrTriggerOrFullRule::Create(dict, category_preset); | 449 ReactiveTraceForNSOrTriggerOrFullRule::Create(dict, category_preset); |
448 } else if (type == kReactiveConfigRuleTraceAtRandomIntervals) { | 450 } else if (type == kReactiveConfigRuleTraceAtRandomIntervals) { |
449 tracing_rule = | 451 tracing_rule = |
450 ReactiveTraceAtRandomIntervalsRule::Create(dict, category_preset); | 452 ReactiveTraceAtRandomIntervalsRule::Create(dict, category_preset); |
451 } | 453 } |
452 | 454 |
453 if (tracing_rule) | 455 if (tracing_rule) |
454 tracing_rule->Setup(dict); | 456 tracing_rule->Setup(dict); |
455 | 457 |
456 return tracing_rule; | 458 return tracing_rule; |
457 } | 459 } |
458 | 460 |
459 } // namespace content | 461 } // namespace content |
OLD | NEW |