| 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 #ifndef CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "content/browser/tracing/background_tracing_config_impl.h" | 15 #include "content/browser/tracing/background_tracing_config_impl.h" |
| 16 #include "content/browser/tracing/tracing_controller_impl.h" | 16 #include "content/browser/tracing/tracing_controller_impl.h" |
| 17 #include "content/public/browser/background_tracing_manager.h" | 17 #include "content/public/browser/background_tracing_manager.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class BackgroundTracingRule; | 21 class BackgroundTracingRule; |
| 22 class TracingDelegate; | 22 class TracingDelegate; |
| 23 | 23 |
| 24 class BackgroundTracingManagerImpl : public BackgroundTracingManager { | 24 class CONTENT_EXPORT BackgroundTracingManagerImpl |
| 25 : public BackgroundTracingManager { |
| 25 public: | 26 public: |
| 26 static CONTENT_EXPORT BackgroundTracingManagerImpl* GetInstance(); | 27 // Enabled state observers get a callback when the state of background tracing |
| 28 // changes. |
| 29 class EnabledStateObserver { |
| 30 public: |
| 31 // Called when the activation of a background tracing scenario is |
| 32 // successful. |
| 33 virtual void OnScenarioActivated( |
| 34 const BackgroundTracingConfigImpl& config) = 0; |
| 35 |
| 36 // Called after tracing is enabled on all processes because the rule was |
| 37 // triggered. |
| 38 virtual void OnTracingEnabled( |
| 39 BackgroundTracingConfigImpl::CategoryPreset preset) = 0; |
| 40 }; |
| 41 |
| 42 static BackgroundTracingManagerImpl* GetInstance(); |
| 27 | 43 |
| 28 bool SetActiveScenario(std::unique_ptr<BackgroundTracingConfig>, | 44 bool SetActiveScenario(std::unique_ptr<BackgroundTracingConfig>, |
| 29 const ReceiveCallback&, | 45 const ReceiveCallback&, |
| 30 DataFiltering data_filtering) override; | 46 DataFiltering data_filtering) override; |
| 31 void WhenIdle(IdleCallback idle_callback) override; | 47 void WhenIdle(IdleCallback idle_callback) override; |
| 32 | 48 |
| 33 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; | 49 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; |
| 34 TriggerHandle RegisterTriggerType(const char* trigger_name) override; | 50 TriggerHandle RegisterTriggerType(const char* trigger_name) override; |
| 35 | 51 |
| 36 void OnHistogramTrigger(const std::string& histogram_name); | 52 void OnHistogramTrigger(const std::string& histogram_name); |
| 37 | 53 |
| 38 void OnRuleTriggered(const BackgroundTracingRule* triggered_rule, | 54 void OnRuleTriggered(const BackgroundTracingRule* triggered_rule, |
| 39 StartedFinalizingCallback callback); | 55 StartedFinalizingCallback callback); |
| 40 void AbortScenario(); | 56 void AbortScenario(); |
| 41 bool HasActiveScenario() override; | 57 bool HasActiveScenario() override; |
| 42 | 58 |
| 59 void OnStartTracingDone(BackgroundTracingConfigImpl::CategoryPreset preset); |
| 60 |
| 61 // Add/remove EnabledStateObserver. |
| 62 void AddEnabledStateObserver(EnabledStateObserver* observer); |
| 63 void RemoveEnabledStateObserver(EnabledStateObserver* observer); |
| 64 |
| 43 // For tests | 65 // For tests |
| 44 void InvalidateTriggerHandlesForTesting() override; | 66 void InvalidateTriggerHandlesForTesting() override; |
| 45 void SetTracingEnabledCallbackForTesting( | 67 void SetRuleTriggeredCallbackForTesting(const base::Closure& callback); |
| 46 const base::Closure& callback) override; | |
| 47 CONTENT_EXPORT void SetRuleTriggeredCallbackForTesting( | |
| 48 const base::Closure& callback); | |
| 49 void FireTimerForTesting() override; | 68 void FireTimerForTesting() override; |
| 50 CONTENT_EXPORT bool IsTracingForTesting(); | 69 bool IsTracingForTesting(); |
| 51 | 70 |
| 52 private: | 71 private: |
| 53 BackgroundTracingManagerImpl(); | 72 BackgroundTracingManagerImpl(); |
| 54 ~BackgroundTracingManagerImpl() override; | 73 ~BackgroundTracingManagerImpl() override; |
| 55 | 74 |
| 56 void StartTracing(BackgroundTracingConfigImpl::CategoryPreset, | 75 void StartTracing(BackgroundTracingConfigImpl::CategoryPreset, |
| 57 base::trace_event::TraceRecordMode); | 76 base::trace_event::TraceRecordMode); |
| 58 void StartTracingIfConfigNeedsIt(); | 77 void StartTracingIfConfigNeedsIt(); |
| 59 void OnFinalizeStarted(std::unique_ptr<const base::DictionaryValue> metadata, | 78 void OnFinalizeStarted(std::unique_ptr<const base::DictionaryValue> metadata, |
| 60 base::RefCountedString*); | 79 base::RefCountedString*); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 std::unique_ptr<TracingTimer> tracing_timer_; | 115 std::unique_ptr<TracingTimer> tracing_timer_; |
| 97 ReceiveCallback receive_callback_; | 116 ReceiveCallback receive_callback_; |
| 98 std::unique_ptr<base::DictionaryValue> last_triggered_rule_; | 117 std::unique_ptr<base::DictionaryValue> last_triggered_rule_; |
| 99 bool is_gathering_; | 118 bool is_gathering_; |
| 100 bool is_tracing_; | 119 bool is_tracing_; |
| 101 bool requires_anonymized_data_; | 120 bool requires_anonymized_data_; |
| 102 int trigger_handle_ids_; | 121 int trigger_handle_ids_; |
| 103 | 122 |
| 104 TriggerHandle triggered_named_event_handle_; | 123 TriggerHandle triggered_named_event_handle_; |
| 105 | 124 |
| 125 std::vector<EnabledStateObserver*> background_tracing_observer_list_; |
| 126 |
| 106 IdleCallback idle_callback_; | 127 IdleCallback idle_callback_; |
| 107 base::Closure tracing_enabled_callback_for_testing_; | 128 base::Closure tracing_enabled_callback_for_testing_; |
| 108 base::Closure rule_triggered_callback_for_testing_; | 129 base::Closure rule_triggered_callback_for_testing_; |
| 109 | 130 |
| 110 friend struct base::LazyInstanceTraitsBase<BackgroundTracingManagerImpl>; | 131 friend struct base::LazyInstanceTraitsBase<BackgroundTracingManagerImpl>; |
| 111 | 132 |
| 112 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); | 133 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); |
| 113 }; | 134 }; |
| 114 | 135 |
| 115 } // namespace content | 136 } // namespace content |
| 116 | 137 |
| 117 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ | 138 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ |
| OLD | NEW |