| Index: content/public/browser/background_tracing_manager.cc
|
| diff --git a/content/public/browser/background_tracing_manager.cc b/content/public/browser/background_tracing_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..877b369e2606b613e4b80180e20d33c9a474ef01
|
| --- /dev/null
|
| +++ b/content/public/browser/background_tracing_manager.cc
|
| @@ -0,0 +1,207 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/public/browser/background_tracing_manager.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +const char kConfigsKey[] = "configs";
|
| +
|
| +const char kConfigModeKey[] = "mode";
|
| +const char kConfigModePreemptive[] = "preemptive";
|
| +const char kConfigModeReactive[] = "reactive";
|
| +
|
| +const char kConfigCategoryKey[] = "category";
|
| +const char kConfigCategoryBenchmark[] = "benchmark";
|
| +const char kConfigCategoryBenchmarkDeep[] = "benchmark-deep";
|
| +
|
| +const char kConfigRuleKey[] = "rule";
|
| +const char kConfigRuleMonitorNamed[] = "monitor_named";
|
| +const char kConfigRuleTriggerNameKey[] = "trigger_name";
|
| +
|
| +} // namespace
|
| +
|
| +BackgroundTracingConfig::BackgroundTracingConfig(Mode mode) : mode_(mode) {
|
| +}
|
| +
|
| +BackgroundTracingConfig::~BackgroundTracingConfig() {
|
| +}
|
| +
|
| +BackgroundTracingConfig::Mode BackgroundTracingConfig::mode() const {
|
| + return mode_;
|
| +}
|
| +
|
| +scoped_refptr<BackgroundTracingConfig> BackgroundTracingConfig::FromDict(
|
| + const base::DictionaryValue* dict) {
|
| + std::string mode;
|
| + if (!dict->GetString(kConfigModeKey, &mode))
|
| + return NULL;
|
| +
|
| + scoped_refptr<BackgroundTracingConfig> config = NULL;
|
| +
|
| + if (mode == kConfigModePreemptive) {
|
| + config = BackgroundTracingPreemptiveConfig::FromDict(dict);
|
| + } else if (mode == kConfigModeReactive) {
|
| + config = BackgroundTracingReactiveConfig::FromDict(dict);
|
| + } else {
|
| + CHECK(false);
|
| + }
|
| +
|
| + return config;
|
| +}
|
| +
|
| +void BackgroundTracingConfig::IntoDict(base::DictionaryValue* dict) {
|
| + CHECK(dict);
|
| +
|
| + switch (mode_) {
|
| + case PREEMPTIVE_TRACING_MODE:
|
| + dict->SetString(kConfigModeKey, kConfigModePreemptive);
|
| + static_cast<BackgroundTracingPreemptiveConfig*>(this)->AsDict(dict);
|
| + break;
|
| + case REACTIVE_TRACING_MODE:
|
| + dict->SetString(kConfigModeKey, kConfigModeReactive);
|
| + static_cast<BackgroundTracingPreemptiveConfig*>(this)->AsDict(dict);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +BackgroundTracingPreemptiveConfig::BackgroundTracingPreemptiveConfig()
|
| + : BackgroundTracingConfig(BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE),
|
| + category_preset_(BackgroundTracingConfig::BENCHMARK) {
|
| +}
|
| +
|
| +BackgroundTracingPreemptiveConfig::~BackgroundTracingPreemptiveConfig() {
|
| +}
|
| +
|
| +void BackgroundTracingPreemptiveConfig::AddHistogramTriggerRule(
|
| + const std::string& histogram_name,
|
| + int histogram_bin) {
|
| + MonitoringRule rule;
|
| + rule.type = MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE;
|
| + rule.histogram_trigger_info.histogram_name_to_trigger_on = histogram_name;
|
| + rule.histogram_trigger_info.histogram_bin_to_trigger_on = histogram_bin;
|
| + configs_.push_back(rule);
|
| +}
|
| +
|
| +void BackgroundTracingPreemptiveConfig::AddNamedTriggerRule(
|
| + const std::string& name) {
|
| + MonitoringRule rule;
|
| + rule.type = MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED;
|
| + rule.named_trigger_info.trigger_name = name;
|
| + configs_.push_back(rule);
|
| +}
|
| +
|
| +BackgroundTracingConfig::CategoryPreset
|
| +BackgroundTracingPreemptiveConfig::category_preset() const {
|
| + return category_preset_;
|
| +}
|
| +
|
| +const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
|
| +BackgroundTracingPreemptiveConfig::configs() const {
|
| + return configs_;
|
| +}
|
| +
|
| +scoped_refptr<BackgroundTracingPreemptiveConfig>
|
| +BackgroundTracingPreemptiveConfig::FromDict(const base::DictionaryValue* dict) {
|
| + scoped_refptr<BackgroundTracingPreemptiveConfig> config(
|
| + new BackgroundTracingPreemptiveConfig());
|
| +
|
| + std::string category_preset;
|
| + if (!dict->GetString(kConfigCategoryKey, &category_preset))
|
| + return NULL;
|
| +
|
| + if (category_preset == kConfigCategoryBenchmark) {
|
| + config->category_preset_ = BENCHMARK;
|
| + } else if (category_preset == kConfigCategoryBenchmarkDeep) {
|
| + config->category_preset_ = BENCHMARK_DEEP;
|
| + } else {
|
| + CHECK(false);
|
| + }
|
| +
|
| + const base::ListValue* configs_list = NULL;
|
| + if (!dict->GetList(kConfigsKey, &configs_list))
|
| + return NULL;
|
| +
|
| + for (auto it = configs_list->begin(); it != configs_list->end(); ++it) {
|
| + const base::DictionaryValue* config_dict = NULL;
|
| + if (!(*it)->GetAsDictionary(&config_dict))
|
| + return NULL;
|
| +
|
| + std::string type;
|
| + if (!config_dict->GetString(kConfigRuleKey, &type))
|
| + return NULL;
|
| +
|
| + if (type == kConfigRuleMonitorNamed) {
|
| + std::string trigger_name;
|
| + if (!config_dict->GetString(kConfigRuleTriggerNameKey, &trigger_name))
|
| + return NULL;
|
| +
|
| + config->AddNamedTriggerRule(trigger_name);
|
| + } else {
|
| + CHECK(false);
|
| + }
|
| + }
|
| +
|
| + return config.Pass();
|
| +}
|
| +
|
| +void BackgroundTracingPreemptiveConfig::AsDict(base::DictionaryValue* dict) {
|
| + // TODO: Move to function.
|
| + switch (category_preset_) {
|
| + case BENCHMARK:
|
| + dict->SetString(kConfigCategoryKey, kConfigCategoryBenchmark);
|
| + break;
|
| + case BENCHMARK_DEEP:
|
| + dict->SetString(kConfigCategoryKey, kConfigCategoryBenchmarkDeep);
|
| + break;
|
| + }
|
| +
|
| + base::ListValue* configs_list = new base::ListValue();
|
| +
|
| + for (size_t i = 0; i < configs_.size(); ++i) {
|
| + base::DictionaryValue* config_dict = new base::DictionaryValue();
|
| +
|
| + if (configs_[i].type == MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) {
|
| + config_dict->SetString(kConfigRuleKey, kConfigRuleMonitorNamed);
|
| + config_dict->SetString(
|
| + kConfigRuleTriggerNameKey,
|
| + configs_[i].named_trigger_info.trigger_name.c_str());
|
| + }
|
| +
|
| + configs_list->Append(config_dict);
|
| + }
|
| +
|
| + dict->Set(kConfigsKey, configs_list);
|
| +}
|
| +
|
| +BackgroundTracingReactiveConfig::BackgroundTracingReactiveConfig()
|
| + : BackgroundTracingConfig(BackgroundTracingConfig::REACTIVE_TRACING_MODE) {
|
| +}
|
| +
|
| +BackgroundTracingReactiveConfig::~BackgroundTracingReactiveConfig() {
|
| +}
|
| +
|
| +void BackgroundTracingReactiveConfig::AddTracingRule(
|
| + RuleType rule_type,
|
| + const char* trigger_name,
|
| + CategoryPreset category_preset) {
|
| + // TODO(simonhatch): Implement this.
|
| + CHECK(false);
|
| +}
|
| +
|
| +scoped_refptr<BackgroundTracingReactiveConfig>
|
| +BackgroundTracingReactiveConfig::FromDict(const base::DictionaryValue* dict) {
|
| + // TODO(simonhatch): Implement this.
|
| + CHECK(false);
|
| + return NULL;
|
| +}
|
| +
|
| +void BackgroundTracingReactiveConfig::AsDict(base::DictionaryValue* dict) {
|
| + // TODO(simonhatch): Implement this.
|
| + CHECK(false);
|
| +}
|
| +}
|
| +// namespace content
|
|
|