Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
blobd22402cdafecc669b3ab8adc7aeb1b2845ba0a38
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 "base/trace_event/memory_dump_manager.h"
14 #include "content/public/browser/tracing_controller.h"
16 namespace base {
17 class RefCountedString;
18 class RefCountedMemory;
21 namespace content {
23 class TraceMessageFilter;
24 class TracingUI;
26 class TracingControllerImpl
27 : public TracingController,
28 public base::trace_event::MemoryDumpManagerDelegate {
29 public:
30 static TracingControllerImpl* GetInstance();
32 // TracingController implementation.
33 bool GetCategories(const GetCategoriesDoneCallback& callback) override;
34 bool EnableRecording(const base::trace_event::CategoryFilter& category_filter,
35 const base::trace_event::TraceOptions& trace_options,
36 const EnableRecordingDoneCallback& callback) override;
37 bool DisableRecording(const scoped_refptr<TraceDataSink>& sink) override;
38 bool EnableMonitoring(
39 const base::trace_event::CategoryFilter& category_filter,
40 const base::trace_event::TraceOptions& trace_options,
41 const EnableMonitoringDoneCallback& callback) override;
42 bool DisableMonitoring(
43 const DisableMonitoringDoneCallback& callback) override;
44 void GetMonitoringStatus(
45 bool* out_enabled,
46 base::trace_event::CategoryFilter* out_category_filter,
47 base::trace_event::TraceOptions* out_trace_options) override;
48 bool CaptureMonitoringSnapshot(
49 const scoped_refptr<TraceDataSink>& sink) override;
50 bool GetTraceBufferUsage(
51 const GetTraceBufferUsageCallback& callback) override;
52 bool SetWatchEvent(const std::string& category_name,
53 const std::string& event_name,
54 const WatchEventCallback& callback) override;
55 bool CancelWatchEvent() override;
57 void RegisterTracingUI(TracingUI* tracing_ui);
58 void UnregisterTracingUI(TracingUI* tracing_ui);
60 // base::trace_event::MemoryDumpManagerDelegate implementation.
61 void RequestGlobalMemoryDump(
62 const base::trace_event::MemoryDumpRequestArgs& args,
63 const base::trace_event::MemoryDumpCallback& callback) override;
65 private:
66 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet;
68 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
69 friend class TraceMessageFilter;
71 TracingControllerImpl();
72 ~TracingControllerImpl() override;
74 bool can_enable_recording() const {
75 return !is_recording_;
78 bool can_disable_recording() const {
79 return is_recording_ && !trace_data_sink_.get();
82 bool can_enable_monitoring() const {
83 return !is_monitoring_;
86 bool can_disable_monitoring() const {
87 return is_monitoring_ && !monitoring_data_sink_.get();
90 bool can_get_trace_buffer_usage() const {
91 return pending_trace_buffer_usage_callback_.is_null();
94 bool can_cancel_watch_event() const {
95 return !watch_event_callback_.is_null();
98 // Methods for use by TraceMessageFilter.
99 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
100 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
102 void OnTraceDataCollected(
103 const scoped_refptr<base::RefCountedString>& events_str_ptr);
104 void OnMonitoringTraceDataCollected(
105 const scoped_refptr<base::RefCountedString>& events_str_ptr);
107 // Callback of TraceLog::Flush() for the local trace.
108 void OnLocalTraceDataCollected(
109 const scoped_refptr<base::RefCountedString>& events_str_ptr,
110 bool has_more_events);
111 // Callback of TraceLog::FlushMonitoring() for the local trace.
112 void OnLocalMonitoringTraceDataCollected(
113 const scoped_refptr<base::RefCountedString>& events_str_ptr,
114 bool has_more_events);
116 void OnDisableRecordingAcked(
117 TraceMessageFilter* trace_message_filter,
118 const std::vector<std::string>& known_category_groups);
120 #if defined(OS_CHROMEOS) || defined(OS_WIN)
121 void OnEndSystemTracingAcked(
122 const scoped_refptr<base::RefCountedString>& events_str_ptr);
123 #endif
125 void OnCaptureMonitoringSnapshotAcked(
126 TraceMessageFilter* trace_message_filter);
128 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter,
129 const base::trace_event::TraceLogStatus& status);
130 void OnProcessMemoryDumpResponse(TraceMessageFilter* trace_message_filter,
131 uint64 dump_guid,
132 bool success);
133 void OnWatchEventMatched();
135 void SetEnabledOnFileThread(
136 const base::trace_event::CategoryFilter& category_filter,
137 int mode,
138 const base::trace_event::TraceOptions& trace_options,
139 const base::Closure& callback);
140 void SetDisabledOnFileThread(const base::Closure& callback);
141 void OnEnableRecordingDone(
142 const base::trace_event::CategoryFilter& category_filter,
143 const base::trace_event::TraceOptions& trace_options,
144 const EnableRecordingDoneCallback& callback);
145 void OnDisableRecordingDone();
146 void OnEnableMonitoringDone(
147 const base::trace_event::CategoryFilter& category_filter,
148 const base::trace_event::TraceOptions& trace_options,
149 const EnableMonitoringDoneCallback& callback);
150 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
152 void OnMonitoringStateChanged(bool is_monitoring);
154 TraceMessageFilterSet trace_message_filters_;
156 // Pending acks for DisableRecording.
157 int pending_disable_recording_ack_count_;
158 TraceMessageFilterSet pending_disable_recording_filters_;
159 // Pending acks for CaptureMonitoringSnapshot.
160 int pending_capture_monitoring_snapshot_ack_count_;
161 TraceMessageFilterSet pending_capture_monitoring_filters_;
162 // Pending acks for GetTraceLogStatus.
163 int pending_trace_log_status_ack_count_;
164 TraceMessageFilterSet pending_trace_log_status_filters_;
165 float maximum_trace_buffer_usage_;
166 size_t approximate_event_count_;
168 #if defined(OS_CHROMEOS) || defined(OS_WIN)
169 bool is_system_tracing_;
170 #endif
171 bool is_recording_;
172 bool is_monitoring_;
173 base::trace_event::TraceOptions trace_options_;
175 GetCategoriesDoneCallback pending_get_categories_done_callback_;
176 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_;
178 std::string watch_category_name_;
179 std::string watch_event_name_;
180 WatchEventCallback watch_event_callback_;
182 std::set<std::string> known_category_groups_;
183 std::set<TracingUI*> tracing_uis_;
184 scoped_refptr<TraceDataSink> trace_data_sink_;
185 scoped_refptr<TraceDataSink> monitoring_data_sink_;
186 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
189 } // namespace content
191 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_