Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / tracing / background_tracing_manager_impl.h
blob8eeec970b8e3a84acaab62c532d72c12d81cd0b4
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.
5 #ifndef CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_
8 #include "base/lazy_instance.h"
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/metrics/histogram.h"
13 #include "content/browser/tracing/tracing_controller_impl.h"
14 #include "content/public/browser/background_tracing_config.h"
15 #include "content/public/browser/background_tracing_manager.h"
17 namespace content {
19 class TraceMessageFilter;
20 class TracingDelegate;
22 class BackgroundTracingManagerImpl : public content::BackgroundTracingManager {
23 public:
24 static BackgroundTracingManagerImpl* GetInstance();
26 bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig>,
27 const ReceiveCallback&,
28 DataFiltering data_filtering) override;
29 void WhenIdle(IdleCallback idle_callback) override;
31 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override;
32 TriggerHandle RegisterTriggerType(const char* trigger_name) override;
33 void GetTriggerNameList(std::vector<std::string>* trigger_names) override;
35 void InvalidateTriggerHandlesForTesting() override;
36 void SetTracingEnabledCallbackForTesting(
37 const base::Closure& callback) override;
38 void FireTimerForTesting() override;
39 bool HasActiveScenarioForTesting() override;
41 void OnHistogramTrigger(const std::string& histogram_name);
43 private:
44 BackgroundTracingManagerImpl();
45 ~BackgroundTracingManagerImpl() override;
47 void EnableRecording(std::string, base::trace_event::TraceRecordMode);
48 void EnableRecordingIfConfigNeedsIt();
49 void OnFinalizeStarted(base::RefCountedString*);
50 void OnFinalizeComplete();
51 void BeginFinalizing(StartedFinalizingCallback);
52 void ValidateStartupScenario();
53 void AbortScenario();
55 enum SetupUMACallMode { CLEAR_CALLBACKS, BIND_CALLBACKS };
57 void SetupUMACallbacks(SetupUMACallMode mode);
59 void OnHistogramChangedCallback(const std::string& histogram_name,
60 base::Histogram::Sample reference_value,
61 base::Histogram::Sample actual_value);
62 void OnTraceMessageFilterAdded(TraceMessageFilter* filter);
63 void SetupFiltersFromConfig(SetupUMACallMode mode);
64 void SetupFilterFromConfig(scoped_refptr<TraceMessageFilter> filter,
65 SetupUMACallMode mode);
67 scoped_ptr<base::DictionaryValue> GenerateMetadataDict() const;
69 std::string GetTriggerNameFromHandle(TriggerHandle handle) const;
70 bool IsTriggerHandleValid(TriggerHandle handle) const;
72 bool IsAbleToTriggerTracing(TriggerHandle handle) const;
73 bool IsSupportedConfig(BackgroundTracingConfig* config);
75 std::string GetCategoryFilterStringForCategoryPreset(
76 BackgroundTracingConfig::CategoryPreset) const;
78 class TracingTimer {
79 public:
80 explicit TracingTimer(StartedFinalizingCallback);
81 ~TracingTimer();
83 void StartTimer();
84 void CancelTimer();
86 void FireTimerForTesting();
88 private:
89 void TracingTimerFired();
91 base::OneShotTimer<TracingTimer> tracing_timer_;
92 StartedFinalizingCallback callback_;
95 scoped_ptr<TracingDelegate> delegate_;
96 scoped_ptr<content::BackgroundTracingConfig> config_;
97 std::map<TriggerHandle, std::string> trigger_handles_;
98 scoped_ptr<TracingTimer> tracing_timer_;
99 ReceiveCallback receive_callback_;
101 bool is_gathering_;
102 bool is_tracing_;
103 bool requires_anonymized_data_;
104 int trigger_handle_ids_;
106 IdleCallback idle_callback_;
107 base::Closure tracing_enabled_callback_for_testing_;
109 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>;
111 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl);
114 } // namespace content
116 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_