Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / tracing / background_tracing_manager_impl.h
blob6ad99bbe59f743dd15e58d754da7ddb871c0acb8
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 TracingDelegate;
21 class BackgroundTracingManagerImpl : public content::BackgroundTracingManager {
22 public:
23 static BackgroundTracingManagerImpl* GetInstance();
25 bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig>,
26 const ReceiveCallback&,
27 DataFiltering data_filtering) override;
28 void WhenIdle(IdleCallback idle_callback) override;
30 void TriggerNamedEvent(TriggerHandle, StartedFinalizingCallback) override;
31 TriggerHandle RegisterTriggerType(const char* trigger_name) override;
32 void GetTriggerNameList(std::vector<std::string>* trigger_names) override;
34 void InvalidateTriggerHandlesForTesting() override;
35 void SetTracingEnabledCallbackForTesting(
36 const base::Closure& callback) override;
37 void FireTimerForTesting() override;
38 bool HasActiveScenarioForTesting() override;
40 private:
41 BackgroundTracingManagerImpl();
42 ~BackgroundTracingManagerImpl() override;
44 void EnableRecording(std::string, base::trace_event::TraceRecordMode);
45 void EnableRecordingIfConfigNeedsIt();
46 void OnFinalizeStarted(base::RefCountedString*);
47 void OnFinalizeComplete();
48 void BeginFinalizing(StartedFinalizingCallback);
49 void ValidateStartupScenario();
50 void AbortScenario();
52 enum SetupUMACallMode { CLEAR_CALLBACKS, BIND_CALLBACKS };
54 void SetupUMACallbacks(SetupUMACallMode mode);
56 void OnHistogramChanged(const std::string& histogram_name,
57 base::Histogram::Sample reference_value,
58 base::Histogram::Sample actual_value);
60 scoped_ptr<base::DictionaryValue> GenerateMetadataDict() const;
62 std::string GetTriggerNameFromHandle(TriggerHandle handle) const;
63 bool IsTriggerHandleValid(TriggerHandle handle) const;
65 bool IsAbleToTriggerTracing(TriggerHandle handle) const;
66 bool IsSupportedConfig(BackgroundTracingConfig* config);
68 std::string GetCategoryFilterStringForCategoryPreset(
69 BackgroundTracingConfig::CategoryPreset) const;
71 class TracingTimer {
72 public:
73 explicit TracingTimer(StartedFinalizingCallback);
74 ~TracingTimer();
76 void StartTimer();
77 void CancelTimer();
79 void FireTimerForTesting();
81 private:
82 void TracingTimerFired();
84 base::OneShotTimer<TracingTimer> tracing_timer_;
85 StartedFinalizingCallback callback_;
88 scoped_ptr<TracingDelegate> delegate_;
89 scoped_ptr<content::BackgroundTracingConfig> config_;
90 std::map<TriggerHandle, std::string> trigger_handles_;
91 scoped_ptr<TracingTimer> tracing_timer_;
92 ReceiveCallback receive_callback_;
94 bool is_gathering_;
95 bool is_tracing_;
96 bool requires_anonymized_data_;
97 int trigger_handle_ids_;
99 IdleCallback idle_callback_;
100 base::Closure tracing_enabled_callback_for_testing_;
102 friend struct base::DefaultLazyInstanceTraits<BackgroundTracingManagerImpl>;
104 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl);
107 } // namespace content
109 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_