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/background_tracing_config_impl.h"
14 #include "content/browser/tracing/tracing_controller_impl.h"
15 #include "content/public/browser/background_tracing_manager.h"
19 class BackgroundTracingRule
;
20 class TraceMessageFilter
;
21 class TracingDelegate
;
23 class BackgroundTracingManagerImpl
: public BackgroundTracingManager
{
25 static BackgroundTracingManagerImpl
* GetInstance();
27 bool SetActiveScenario(scoped_ptr
<BackgroundTracingConfig
>,
28 const ReceiveCallback
&,
29 DataFiltering data_filtering
) override
;
30 void WhenIdle(IdleCallback idle_callback
) override
;
32 void TriggerNamedEvent(TriggerHandle
, StartedFinalizingCallback
) override
;
33 TriggerHandle
RegisterTriggerType(const char* trigger_name
) override
;
35 void InvalidateTriggerHandlesForTesting() override
;
36 void SetTracingEnabledCallbackForTesting(
37 const base::Closure
& callback
) override
;
38 void FireTimerForTesting() override
;
39 bool HasActiveScenarioForTesting() override
;
40 void OnHistogramTrigger(const std::string
& histogram_name
);
42 void TriggerPreemptiveFinalization();
45 BackgroundTracingManagerImpl();
46 ~BackgroundTracingManagerImpl() override
;
48 void EnableRecording(std::string
, base::trace_event::TraceRecordMode
);
49 void EnableRecordingIfConfigNeedsIt();
50 void OnFinalizeStarted(base::RefCountedString
*);
51 void OnFinalizeComplete();
52 void BeginFinalizing(StartedFinalizingCallback
);
53 void ValidateStartupScenario();
56 scoped_ptr
<base::DictionaryValue
> GenerateMetadataDict() const;
58 std::string
GetTriggerNameFromHandle(TriggerHandle handle
) const;
59 bool IsTriggerHandleValid(TriggerHandle handle
) const;
61 BackgroundTracingRule
* GetRuleAbleToTriggerTracing(
62 TriggerHandle handle
) const;
63 bool IsSupportedConfig(BackgroundTracingConfigImpl
* config
);
65 std::string
GetCategoryFilterStringForCategoryPreset(
66 BackgroundTracingConfigImpl::CategoryPreset
) const;
70 explicit TracingTimer(StartedFinalizingCallback
);
76 void FireTimerForTesting();
79 void TracingTimerFired();
81 base::OneShotTimer
<TracingTimer
> tracing_timer_
;
82 StartedFinalizingCallback callback_
;
85 scoped_ptr
<TracingDelegate
> delegate_
;
86 scoped_ptr
<const content::BackgroundTracingConfigImpl
> config_
;
87 std::map
<TriggerHandle
, std::string
> trigger_handles_
;
88 scoped_ptr
<TracingTimer
> tracing_timer_
;
89 ReceiveCallback receive_callback_
;
93 bool requires_anonymized_data_
;
94 int trigger_handle_ids_
;
96 IdleCallback idle_callback_
;
97 base::Closure tracing_enabled_callback_for_testing_
;
99 friend struct base::DefaultLazyInstanceTraits
<BackgroundTracingManagerImpl
>;
101 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerImpl
);
104 } // namespace content
106 #endif // CONTENT_BROWSER_TRACING_BACKGROUND_TRACING_MANAGER_IMPL_H_