Chromium Code Reviews| 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 "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "content/browser/tracing/tracing_controller_impl.h" | 13 #include "content/browser/tracing/tracing_controller_impl.h" |
| 14 #include "content/public/browser/background_tracing_config.h" | 14 #include "content/public/browser/background_tracing_config.h" |
| 15 #include "content/public/browser/background_tracing_manager.h" | 15 #include "content/public/browser/background_tracing_manager.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 class TraceMessageFilter; | |
| 19 class TracingDelegate; | 20 class TracingDelegate; |
| 20 | 21 |
| 21 class BackgroundTracingManagerImpl : public content::BackgroundTracingManager { | 22 class BackgroundTracingManagerImpl : public content::BackgroundTracingManager { |
| 22 public: | 23 public: |
| 23 static BackgroundTracingManagerImpl* GetInstance(); | 24 static BackgroundTracingManagerImpl* GetInstance(); |
| 24 | 25 |
| 25 bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig>, | 26 bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig>, |
| 26 const ReceiveCallback&, | 27 const ReceiveCallback&, |
| 27 DataFiltering data_filtering) override; | 28 DataFiltering data_filtering) override; |
| 28 void WhenIdle(IdleCallback idle_callback) override; | 29 void WhenIdle(IdleCallback idle_callback) override; |
| 29 | 30 |
| 30 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; | 31 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override; |
| 31 TriggerHandle RegisterTriggerType(const char* trigger_name) override; | 32 TriggerHandle RegisterTriggerType(const char* trigger_name) override; |
| 32 void GetTriggerNameList(std::vector<std::string>* trigger_names) override; | 33 void GetTriggerNameList(std::vector<std::string>* trigger_names) override; |
| 33 | 34 |
| 34 void InvalidateTriggerHandlesForTesting() override; | 35 void InvalidateTriggerHandlesForTesting() override; |
| 35 void SetTracingEnabledCallbackForTesting( | 36 void SetTracingEnabledCallbackForTesting( |
| 36 const base::Closure& callback) override; | 37 const base::Closure& callback) override; |
| 37 void FireTimerForTesting() override; | 38 void FireTimerForTesting() override; |
| 38 bool HasActiveScenarioForTesting() override; | 39 bool HasActiveScenarioForTesting() override; |
| 39 | 40 |
| 41 void AddFilter(scoped_refptr<TraceMessageFilter> filter); | |
| 42 void RemoveFilter(scoped_refptr<TraceMessageFilter> filter); | |
| 43 | |
| 44 void OnHistogramTrigger(const std::string& histogram_name) override; | |
| 45 | |
| 40 private: | 46 private: |
| 41 BackgroundTracingManagerImpl(); | 47 BackgroundTracingManagerImpl(); |
| 42 ~BackgroundTracingManagerImpl() override; | 48 ~BackgroundTracingManagerImpl() override; |
| 43 | 49 |
| 50 void CreateDelegate(); | |
| 44 void EnableRecording(std::string, base::trace_event::TraceRecordMode); | 51 void EnableRecording(std::string, base::trace_event::TraceRecordMode); |
| 45 void EnableRecordingIfConfigNeedsIt(); | 52 void EnableRecordingIfConfigNeedsIt(); |
| 46 void OnFinalizeStarted(base::RefCountedString*); | 53 void OnFinalizeStarted(base::RefCountedString*); |
| 47 void OnFinalizeComplete(); | 54 void OnFinalizeComplete(); |
| 48 void BeginFinalizing(StartedFinalizingCallback); | 55 void BeginFinalizing(StartedFinalizingCallback); |
| 49 void ValidateStartupScenario(); | 56 void ValidateStartupScenario(); |
| 50 void AbortScenario(); | 57 void AbortScenario(); |
| 51 | 58 |
| 52 enum SetupUMACallMode { CLEAR_CALLBACKS, BIND_CALLBACKS }; | 59 enum SetupUMACallMode { CLEAR_CALLBACKS, BIND_CALLBACKS }; |
| 53 | 60 |
| 54 void SetupUMACallbacks(SetupUMACallMode mode); | 61 void SetupUMACallbacks(SetupUMACallMode mode); |
| 55 | 62 |
| 56 void OnHistogramChanged(const std::string& histogram_name, | 63 void OnHistogramChangedCallback(const std::string& histogram_name, |
| 57 base::Histogram::Sample reference_value, | 64 base::Histogram::Sample reference_value, |
| 58 base::Histogram::Sample actual_value); | 65 base::Histogram::Sample actual_value); |
| 66 void SetupFiltersFromConfig(SetupUMACallMode mode); | |
| 67 void SetupFilterFromConfig(scoped_refptr<TraceMessageFilter> filter, | |
| 68 SetupUMACallMode mode); | |
| 59 | 69 |
| 60 scoped_ptr<base::DictionaryValue> GenerateMetadataDict() const; | 70 scoped_ptr<base::DictionaryValue> GenerateMetadataDict() const; |
| 61 | 71 |
| 62 std::string GetTriggerNameFromHandle(TriggerHandle handle) const; | 72 std::string GetTriggerNameFromHandle(TriggerHandle handle) const; |
| 63 bool IsTriggerHandleValid(TriggerHandle handle) const; | 73 bool IsTriggerHandleValid(TriggerHandle handle) const; |
| 64 | 74 |
| 65 bool IsAbleToTriggerTracing(TriggerHandle handle) const; | 75 bool IsAbleToTriggerTracing(TriggerHandle handle) const; |
| 66 bool IsSupportedConfig(BackgroundTracingConfig* config); | 76 bool IsSupportedConfig(BackgroundTracingConfig* config); |
| 67 | 77 |
| 68 std::string GetCategoryFilterStringForCategoryPreset( | 78 std::string GetCategoryFilterStringForCategoryPreset( |
| 69 BackgroundTracingConfig::CategoryPreset) const; | 79 BackgroundTracingConfig::CategoryPreset) const; |
| 70 | 80 |
| 71 class TracingTimer { | 81 class TracingTimer { |
| 72 public: | 82 public: |
| 73 explicit TracingTimer(StartedFinalizingCallback); | 83 explicit TracingTimer(StartedFinalizingCallback); |
| 74 ~TracingTimer(); | 84 ~TracingTimer(); |
| 75 | 85 |
| 76 void StartTimer(); | 86 void StartTimer(); |
| 77 void CancelTimer(); | 87 void CancelTimer(); |
| 78 | 88 |
| 79 void FireTimerForTesting(); | 89 void FireTimerForTesting(); |
| 80 | 90 |
| 81 private: | 91 private: |
| 82 void TracingTimerFired(); | 92 void TracingTimerFired(); |
| 83 | 93 |
| 84 base::OneShotTimer<TracingTimer> tracing_timer_; | 94 base::OneShotTimer<TracingTimer> tracing_timer_; |
| 85 StartedFinalizingCallback callback_; | 95 StartedFinalizingCallback callback_; |
| 86 }; | 96 }; |
| 87 | 97 |
| 98 typedef std::set<scoped_refptr<TraceMessageFilter>> FilterSet; | |
| 99 FilterSet filters_; | |
|
oystein (OOO til 10th of July)
2015/07/21 20:52:45
Could we just use the list in TraceControllerImpl,
shatch
2015/07/22 17:44:13
Thought about this a bit more, didn't get any grea
| |
| 100 | |
| 88 scoped_ptr<TracingDelegate> delegate_; | 101 scoped_ptr<TracingDelegate> delegate_; |
| 89 scoped_ptr<content::BackgroundTracingConfig> config_; | 102 scoped_ptr<content::BackgroundTracingConfig> config_; |
| 90 std::map<TriggerHandle, std::string> trigger_handles_; | 103 std::map<TriggerHandle, std::string> trigger_handles_; |
| 91 scoped_ptr<TracingTimer> tracing_timer_; | 104 scoped_ptr<TracingTimer> tracing_timer_; |
| 92 ReceiveCallback receive_callback_; | 105 ReceiveCallback receive_callback_; |
| 93 | 106 |
| 94 bool is_gathering_; | 107 bool is_gathering_; |
| 95 bool is_tracing_; | 108 bool is_tracing_; |
| 96 bool requires_anonymized_data_; | 109 bool requires_anonymized_data_; |
| 97 int trigger_handle_ids_; | 110 int trigger_handle_ids_; |
| 98 | 111 |
| 99 IdleCallback idle_callback_; | 112 IdleCallback idle_callback_; |
| 100 base::Closure tracing_enabled_callback_for_testing_; | 113 base::Closure tracing_enabled_callback_for_testing_; |
| 101 | 114 |
| 102 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>; | 115 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>; |
| 103 | 116 |
| 104 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); | 117 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl); |
| 105 }; | 118 }; |
| 106 | 119 |
| 107 } // namespace content | 120 } // namespace content |
| 108 | 121 |
| 109 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ | 122 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_ |
| OLD | NEW |