ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
bloba5563a8547ce9057fc9d1b331881cf67f7a4c859
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_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/lazy_instance.h"
13 #include "content/public/browser/tracing_controller.h"
15 namespace base {
16 class RefCountedString;
17 class RefCountedMemory;
20 namespace content {
22 class TraceMessageFilter;
23 class TracingUI;
25 class TracingControllerImpl : public TracingController {
26 public:
27 static TracingControllerImpl* GetInstance();
29 // TracingController implementation.
30 bool GetCategories(const GetCategoriesDoneCallback& callback) override;
31 bool EnableRecording(const base::trace_event::CategoryFilter& category_filter,
32 const base::trace_event::TraceOptions& trace_options,
33 const EnableRecordingDoneCallback& callback) override;
34 bool DisableRecording(const scoped_refptr<TraceDataSink>& sink) override;
35 bool EnableMonitoring(
36 const base::trace_event::CategoryFilter& category_filter,
37 const base::trace_event::TraceOptions& trace_options,
38 const EnableMonitoringDoneCallback& callback) override;
39 bool DisableMonitoring(
40 const DisableMonitoringDoneCallback& callback) override;
41 void GetMonitoringStatus(
42 bool* out_enabled,
43 base::trace_event::CategoryFilter* out_category_filter,
44 base::trace_event::TraceOptions* out_trace_options) override;
45 bool CaptureMonitoringSnapshot(
46 const scoped_refptr<TraceDataSink>& sink) override;
47 bool GetTraceBufferUsage(
48 const GetTraceBufferUsageCallback& callback) override;
49 bool SetWatchEvent(const std::string& category_name,
50 const std::string& event_name,
51 const WatchEventCallback& callback) override;
52 bool CancelWatchEvent() override;
54 void RegisterTracingUI(TracingUI* tracing_ui);
55 void UnregisterTracingUI(TracingUI* tracing_ui);
57 private:
58 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet;
60 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
61 friend class TraceMessageFilter;
63 TracingControllerImpl();
64 ~TracingControllerImpl() override;
66 bool can_enable_recording() const {
67 return !is_recording_;
70 bool can_disable_recording() const {
71 return is_recording_ && !trace_data_sink_.get();
74 bool can_enable_monitoring() const {
75 return !is_monitoring_;
78 bool can_disable_monitoring() const {
79 return is_monitoring_ && !monitoring_data_sink_.get();
82 bool can_get_trace_buffer_usage() const {
83 return pending_trace_buffer_usage_callback_.is_null();
86 bool can_cancel_watch_event() const {
87 return !watch_event_callback_.is_null();
90 // Methods for use by TraceMessageFilter.
91 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
92 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
94 void OnTraceDataCollected(
95 const scoped_refptr<base::RefCountedString>& events_str_ptr);
96 void OnMonitoringTraceDataCollected(
97 const scoped_refptr<base::RefCountedString>& events_str_ptr);
99 // Callback of TraceLog::Flush() for the local trace.
100 void OnLocalTraceDataCollected(
101 const scoped_refptr<base::RefCountedString>& events_str_ptr,
102 bool has_more_events);
103 // Callback of TraceLog::FlushMonitoring() for the local trace.
104 void OnLocalMonitoringTraceDataCollected(
105 const scoped_refptr<base::RefCountedString>& events_str_ptr,
106 bool has_more_events);
108 void OnDisableRecordingAcked(
109 TraceMessageFilter* trace_message_filter,
110 const std::vector<std::string>& known_category_groups);
112 #if defined(OS_CHROMEOS) || defined(OS_WIN)
113 void OnEndSystemTracingAcked(
114 const scoped_refptr<base::RefCountedString>& events_str_ptr);
115 #endif
117 void OnCaptureMonitoringSnapshotAcked(
118 TraceMessageFilter* trace_message_filter);
120 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter,
121 const base::trace_event::TraceLogStatus& status);
123 void OnWatchEventMatched();
125 void SetEnabledOnFileThread(
126 const base::trace_event::CategoryFilter& category_filter,
127 int mode,
128 const base::trace_event::TraceOptions& trace_options,
129 const base::Closure& callback);
130 void SetDisabledOnFileThread(const base::Closure& callback);
131 void OnEnableRecordingDone(
132 const base::trace_event::CategoryFilter& category_filter,
133 const base::trace_event::TraceOptions& trace_options,
134 const EnableRecordingDoneCallback& callback);
135 void OnDisableRecordingDone();
136 void OnEnableMonitoringDone(
137 const base::trace_event::CategoryFilter& category_filter,
138 const base::trace_event::TraceOptions& trace_options,
139 const EnableMonitoringDoneCallback& callback);
140 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
142 void OnMonitoringStateChanged(bool is_monitoring);
144 TraceMessageFilterSet trace_message_filters_;
146 // Pending acks for DisableRecording.
147 int pending_disable_recording_ack_count_;
148 TraceMessageFilterSet pending_disable_recording_filters_;
149 // Pending acks for CaptureMonitoringSnapshot.
150 int pending_capture_monitoring_snapshot_ack_count_;
151 TraceMessageFilterSet pending_capture_monitoring_filters_;
152 // Pending acks for GetTraceLogStatus.
153 int pending_trace_log_status_ack_count_;
154 TraceMessageFilterSet pending_trace_log_status_filters_;
155 float maximum_trace_buffer_usage_;
156 size_t approximate_event_count_;
158 #if defined(OS_CHROMEOS) || defined(OS_WIN)
159 bool is_system_tracing_;
160 #endif
161 bool is_recording_;
162 bool is_monitoring_;
163 base::trace_event::TraceOptions trace_options_;
165 GetCategoriesDoneCallback pending_get_categories_done_callback_;
166 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_;
168 std::string watch_category_name_;
169 std::string watch_event_name_;
170 WatchEventCallback watch_event_callback_;
172 std::set<std::string> known_category_groups_;
173 std::set<TracingUI*> tracing_uis_;
174 scoped_refptr<TraceDataSink> trace_data_sink_;
175 scoped_refptr<TraceDataSink> monitoring_data_sink_;
176 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
179 } // namespace content
181 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_