| 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> |
| 9 |
| 8 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "content/browser/tracing/background_tracing_config_impl.h" | 15 #include "content/browser/tracing/background_tracing_config_impl.h" |
| 15 #include "content/browser/tracing/tracing_controller_impl.h" | 16 #include "content/browser/tracing/tracing_controller_impl.h" |
| 16 #include "content/public/browser/background_tracing_manager.h" | 17 #include "content/public/browser/background_tracing_manager.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 class BackgroundTracingRule; | 21 class BackgroundTracingRule; |
| 21 class TraceMessageFilter; | 22 class TraceMessageFilter; |
| 22 class TracingDelegate; | 23 class TracingDelegate; |
| 23 | 24 |
| 24 class BackgroundTracingManagerImpl : public BackgroundTracingManager { | 25 class BackgroundTracingManagerImpl : public BackgroundTracingManager { |
| 25 public: | 26 public: |
| 26 static CONTENT_EXPORT BackgroundTracingManagerImpl* GetInstance(); | 27 static CONTENT_EXPORT BackgroundTracingManagerImpl* GetInstance(); |
| 27 | 28 |
| 28 bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig>, | 29 bool SetActiveScenario(std::unique_ptr<BackgroundTracingConfig>, |
| 29 const ReceiveCallback&, | 30 const ReceiveCallback&, |
| 30 DataFiltering data_filtering) override; | 31 DataFiltering data_filtering) override; |
| 31 void WhenIdle(IdleCallback idle_callback) override; | 32 void WhenIdle(IdleCallback idle_callback) override; |
| 32 | 33 |
| 33 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; | 34 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; |
| 34 TriggerHandle RegisterTriggerType(const char* trigger_name) override; | 35 TriggerHandle RegisterTriggerType(const char* trigger_name) override; |
| 35 | 36 |
| 36 void OnHistogramTrigger(const std::string& histogram_name); | 37 void OnHistogramTrigger(const std::string& histogram_name); |
| 37 | 38 |
| 38 void OnRuleTriggered(const BackgroundTracingRule* triggered_rule, | 39 void OnRuleTriggered(const BackgroundTracingRule* triggered_rule, |
| 39 StartedFinalizingCallback callback); | 40 StartedFinalizingCallback callback); |
| 40 void AbortScenario(); | 41 void AbortScenario(); |
| 41 bool HasActiveScenario() override; | 42 bool HasActiveScenario() override; |
| 42 | 43 |
| 43 // For tests | 44 // For tests |
| 44 void InvalidateTriggerHandlesForTesting() override; | 45 void InvalidateTriggerHandlesForTesting() override; |
| 45 void SetTracingEnabledCallbackForTesting( | 46 void SetTracingEnabledCallbackForTesting( |
| 46 const base::Closure& callback) override; | 47 const base::Closure& callback) override; |
| 47 CONTENT_EXPORT void SetRuleTriggeredCallbackForTesting( | 48 CONTENT_EXPORT void SetRuleTriggeredCallbackForTesting( |
| 48 const base::Closure& callback); | 49 const base::Closure& callback); |
| 49 void FireTimerForTesting() override; | 50 void FireTimerForTesting() override; |
| 50 CONTENT_EXPORT bool IsTracingForTesting(); | 51 CONTENT_EXPORT bool IsTracingForTesting(); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 BackgroundTracingManagerImpl(); | 54 BackgroundTracingManagerImpl(); |
| 54 ~BackgroundTracingManagerImpl() override; | 55 ~BackgroundTracingManagerImpl() override; |
| 55 | 56 |
| 56 void StartTracing(std::string, base::trace_event::TraceRecordMode); | 57 void StartTracing(std::string, base::trace_event::TraceRecordMode); |
| 57 void StartTracingIfConfigNeedsIt(); | 58 void StartTracingIfConfigNeedsIt(); |
| 58 void OnFinalizeStarted( | 59 void OnFinalizeStarted(std::unique_ptr<const base::DictionaryValue> metadata, |
| 59 scoped_ptr<const base::DictionaryValue> metadata, | 60 base::RefCountedString*); |
| 60 base::RefCountedString*); | |
| 61 void OnFinalizeComplete(); | 61 void OnFinalizeComplete(); |
| 62 void BeginFinalizing(StartedFinalizingCallback); | 62 void BeginFinalizing(StartedFinalizingCallback); |
| 63 void ValidateStartupScenario(); | 63 void ValidateStartupScenario(); |
| 64 | 64 |
| 65 void AddCustomMetadata(TracingControllerImpl::TraceDataSink*) const; | 65 void AddCustomMetadata(TracingControllerImpl::TraceDataSink*) const; |
| 66 | 66 |
| 67 std::string GetTriggerNameFromHandle(TriggerHandle handle) const; | 67 std::string GetTriggerNameFromHandle(TriggerHandle handle) const; |
| 68 bool IsTriggerHandleValid(TriggerHandle handle) const; | 68 bool IsTriggerHandleValid(TriggerHandle handle) const; |
| 69 | 69 |
| 70 BackgroundTracingRule* GetRuleAbleToTriggerTracing( | 70 BackgroundTracingRule* GetRuleAbleToTriggerTracing( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 void CancelTimer(); | 83 void CancelTimer(); |
| 84 void FireTimerForTesting(); | 84 void FireTimerForTesting(); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 void TracingTimerFired(); | 87 void TracingTimerFired(); |
| 88 | 88 |
| 89 base::OneShotTimer tracing_timer_; | 89 base::OneShotTimer tracing_timer_; |
| 90 StartedFinalizingCallback callback_; | 90 StartedFinalizingCallback callback_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 scoped_ptr<TracingDelegate> delegate_; | 93 std::unique_ptr<TracingDelegate> delegate_; |
| 94 scoped_ptr<const content::BackgroundTracingConfigImpl> config_; | 94 std::unique_ptr<const content::BackgroundTracingConfigImpl> config_; |
| 95 std::map<TriggerHandle, std::string> trigger_handles_; | 95 std::map<TriggerHandle, std::string> trigger_handles_; |
| 96 scoped_ptr<TracingTimer> tracing_timer_; | 96 std::unique_ptr<TracingTimer> tracing_timer_; |
| 97 ReceiveCallback receive_callback_; | 97 ReceiveCallback receive_callback_; |
| 98 | 98 |
| 99 bool is_gathering_; | 99 bool is_gathering_; |
| 100 bool is_tracing_; | 100 bool is_tracing_; |
| 101 bool requires_anonymized_data_; | 101 bool requires_anonymized_data_; |
| 102 int trigger_handle_ids_; | 102 int trigger_handle_ids_; |
| 103 | 103 |
| 104 TriggerHandle triggered_named_event_handle_; | 104 TriggerHandle triggered_named_event_handle_; |
| 105 | 105 |
| 106 IdleCallback idle_callback_; | 106 IdleCallback idle_callback_; |
| 107 base::Closure tracing_enabled_callback_for_testing_; | 107 base::Closure tracing_enabled_callback_for_testing_; |
| 108 base::Closure rule_triggered_callback_for_testing_; | 108 base::Closure rule_triggered_callback_for_testing_; |
| 109 | 109 |
| 110 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>; | 110 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); | 112 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 } // namespace content | 115 } // namespace content |
| 116 | 116 |
| 117 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ | 117 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ |
| OLD | NEW |