1 // Copyright (c) 2013 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_TRACING_CONTROLLER_IMPL_H_
6 #define CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_
12 #include "base/lazy_instance.h"
13 #include "content/public/browser/tracing_controller.h"
16 class RefCountedString
;
17 class RefCountedMemory
;
22 class TraceMessageFilter
;
25 class TracingControllerImpl
: public TracingController
{
27 static TracingControllerImpl
* GetInstance();
29 // TracingController implementation.
30 virtual bool GetCategories(
31 const GetCategoriesDoneCallback
& callback
) override
;
32 virtual bool EnableRecording(
33 const base::debug::CategoryFilter
& category_filter
,
34 const base::debug::TraceOptions
& trace_options
,
35 const EnableRecordingDoneCallback
& callback
) override
;
36 virtual bool DisableRecording(
37 const scoped_refptr
<TraceDataSink
>& sink
) override
;
38 virtual bool EnableMonitoring(
39 const base::debug::CategoryFilter
& category_filter
,
40 const base::debug::TraceOptions
& trace_options
,
41 const EnableMonitoringDoneCallback
& callback
) override
;
42 virtual bool DisableMonitoring(
43 const DisableMonitoringDoneCallback
& callback
) override
;
44 virtual void GetMonitoringStatus(
46 base::debug::CategoryFilter
* out_category_filter
,
47 base::debug::TraceOptions
* out_trace_options
) override
;
48 virtual bool CaptureMonitoringSnapshot(
49 const scoped_refptr
<TraceDataSink
>& sink
) override
;
50 virtual bool GetTraceBufferPercentFull(
51 const GetTraceBufferPercentFullCallback
& callback
) override
;
52 virtual bool SetWatchEvent(const std::string
& category_name
,
53 const std::string
& event_name
,
54 const WatchEventCallback
& callback
) override
;
55 virtual bool CancelWatchEvent() override
;
57 void RegisterTracingUI(TracingUI
* tracing_ui
);
58 void UnregisterTracingUI(TracingUI
* tracing_ui
);
61 typedef std::set
<scoped_refptr
<TraceMessageFilter
> > TraceMessageFilterSet
;
63 friend struct base::DefaultLazyInstanceTraits
<TracingControllerImpl
>;
64 friend class TraceMessageFilter
;
66 TracingControllerImpl();
67 virtual ~TracingControllerImpl();
69 bool can_enable_recording() const {
70 return !is_recording_
;
73 bool can_disable_recording() const {
74 return is_recording_
&& !trace_data_sink_
.get();
77 bool can_enable_monitoring() const {
78 return !is_monitoring_
;
81 bool can_disable_monitoring() const {
82 return is_monitoring_
&& !monitoring_data_sink_
.get();
85 bool can_get_trace_buffer_percent_full() const {
86 return pending_trace_buffer_percent_full_callback_
.is_null();
89 bool can_cancel_watch_event() const {
90 return !watch_event_callback_
.is_null();
93 // Methods for use by TraceMessageFilter.
94 void AddTraceMessageFilter(TraceMessageFilter
* trace_message_filter
);
95 void RemoveTraceMessageFilter(TraceMessageFilter
* trace_message_filter
);
97 void OnTraceDataCollected(
98 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
);
99 void OnMonitoringTraceDataCollected(
100 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
);
102 // Callback of TraceLog::Flush() for the local trace.
103 void OnLocalTraceDataCollected(
104 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
,
105 bool has_more_events
);
106 // Callback of TraceLog::FlushMonitoring() for the local trace.
107 void OnLocalMonitoringTraceDataCollected(
108 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
,
109 bool has_more_events
);
111 void OnDisableRecordingAcked(
112 TraceMessageFilter
* trace_message_filter
,
113 const std::vector
<std::string
>& known_category_groups
);
115 #if defined(OS_CHROMEOS) || defined(OS_WIN)
116 void OnEndSystemTracingAcked(
117 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
);
120 void OnCaptureMonitoringSnapshotAcked(
121 TraceMessageFilter
* trace_message_filter
);
123 void OnTraceBufferPercentFullReply(
124 TraceMessageFilter
* trace_message_filter
,
127 void OnWatchEventMatched();
129 void SetEnabledOnFileThread(
130 const base::debug::CategoryFilter
& category_filter
,
132 const base::debug::TraceOptions
& trace_options
,
133 const base::Closure
& callback
);
134 void SetDisabledOnFileThread(const base::Closure
& callback
);
135 void OnEnableRecordingDone(const base::debug::CategoryFilter
& category_filter
,
136 const base::debug::TraceOptions
& trace_options
,
137 const EnableRecordingDoneCallback
& callback
);
138 void OnDisableRecordingDone();
139 void OnEnableMonitoringDone(
140 const base::debug::CategoryFilter
& category_filter
,
141 const base::debug::TraceOptions
& trace_options
,
142 const EnableMonitoringDoneCallback
& callback
);
143 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback
& callback
);
145 void OnMonitoringStateChanged(bool is_monitoring
);
147 TraceMessageFilterSet trace_message_filters_
;
149 // Pending acks for DisableRecording.
150 int pending_disable_recording_ack_count_
;
151 TraceMessageFilterSet pending_disable_recording_filters_
;
152 // Pending acks for CaptureMonitoringSnapshot.
153 int pending_capture_monitoring_snapshot_ack_count_
;
154 TraceMessageFilterSet pending_capture_monitoring_filters_
;
155 // Pending acks for GetTraceBufferPercentFull.
156 int pending_trace_buffer_percent_full_ack_count_
;
157 TraceMessageFilterSet pending_trace_buffer_percent_full_filters_
;
158 float maximum_trace_buffer_percent_full_
;
160 #if defined(OS_CHROMEOS) || defined(OS_WIN)
161 bool is_system_tracing_
;
165 base::debug::TraceOptions trace_options_
;
167 GetCategoriesDoneCallback pending_get_categories_done_callback_
;
168 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_
;
170 std::string watch_category_name_
;
171 std::string watch_event_name_
;
172 WatchEventCallback watch_event_callback_
;
174 std::set
<std::string
> known_category_groups_
;
175 std::set
<TracingUI
*> tracing_uis_
;
176 scoped_refptr
<TraceDataSink
> trace_data_sink_
;
177 scoped_refptr
<TraceDataSink
> monitoring_data_sink_
;
178 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl
);
181 } // namespace content
183 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_