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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_RULE_H_ 6 #define CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_RULE_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "base/values.h" 12 #include "content/browser/tracing/background_tracing_config_impl.h" 13 #include "content/common/content_export.h" 14 #include "content/public/browser/background_tracing_manager.h" 15 #include "third_party/perfetto/protos/perfetto/trace/chrome/chrome_metadata.pbzero.h" 16 17 namespace base { 18 class DictionaryValue; 19 } // namespace base 20 21 namespace content { 22 23 class CONTENT_EXPORT BackgroundTracingRule { 24 public: 25 using MetadataProto = 26 perfetto::protos::pbzero::BackgroundTracingMetadata::TriggerRule; 27 28 BackgroundTracingRule(); 29 explicit BackgroundTracingRule(int trigger_delay); 30 31 virtual ~BackgroundTracingRule(); 32 33 void Setup(const base::DictionaryValue* dict); category_preset()34 BackgroundTracingConfigImpl::CategoryPreset category_preset() const { 35 return category_preset_; 36 } set_category_preset(BackgroundTracingConfigImpl::CategoryPreset category_preset)37 void set_category_preset( 38 BackgroundTracingConfigImpl::CategoryPreset category_preset) { 39 category_preset_ = category_preset; 40 } 41 Install()42 virtual void Install() {} 43 virtual void IntoDict(base::DictionaryValue* dict) const; 44 virtual void GenerateMetadataProto(MetadataProto* out) const; 45 virtual bool ShouldTriggerNamedEvent(const std::string& named_event) const; OnHistogramTrigger(const std::string & histogram_name)46 virtual void OnHistogramTrigger(const std::string& histogram_name) const {} 47 48 // Seconds from the rule is triggered to finalization should start. 49 virtual int GetTraceDelay() const; 50 51 // Probability that we should allow a tigger to happen. trigger_chance()52 double trigger_chance() const { return trigger_chance_; } 53 stop_tracing_on_repeated_reactive()54 bool stop_tracing_on_repeated_reactive() const { 55 return stop_tracing_on_repeated_reactive_; 56 } 57 58 static std::unique_ptr<BackgroundTracingRule> CreateRuleFromDict( 59 const base::DictionaryValue* dict); 60 SetArgs(const base::DictionaryValue & args)61 void SetArgs(const base::DictionaryValue& args) { 62 args_ = args.CreateDeepCopy(); 63 } args()64 const base::DictionaryValue* args() const { return args_.get(); } 65 rule_id()66 const std::string& rule_id() const { return rule_id_; } 67 68 protected: 69 virtual std::string GetDefaultRuleId() const; 70 71 private: 72 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingRule); 73 74 double trigger_chance_; 75 int trigger_delay_; 76 bool stop_tracing_on_repeated_reactive_; 77 std::string rule_id_; 78 BackgroundTracingConfigImpl::CategoryPreset category_preset_; 79 std::unique_ptr<base::DictionaryValue> args_; 80 }; 81 82 } // namespace content 83 84 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_RULE_H_ 85