[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
blob9af728ef0697814cd07c1665c5389c40ddfac484
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::TraceConfig& trace_config,
35 const EnableRecordingDoneCallback& callback) override;
36 bool DisableRecording(const scoped_refptr<TraceDataSink>& sink) override;
37 bool EnableMonitoring(
38 const base::trace_event::TraceConfig& trace_config,
39 const EnableMonitoringDoneCallback& callback) override;
40 bool DisableMonitoring(
41 const DisableMonitoringDoneCallback& callback) override;
42 void GetMonitoringStatus(
43 bool* out_enabled,
44 base::trace_event::TraceConfig* out_trace_config) 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;
53 bool IsRecording() const override;
55 void RegisterTracingUI(TracingUI* tracing_ui);
56 void UnregisterTracingUI(TracingUI* tracing_ui);
58 // base::trace_event::MemoryDumpManagerDelegate implementation.
59 void RequestGlobalMemoryDump(
60 const base::trace_event::MemoryDumpRequestArgs& args,
61 const base::trace_event::MemoryDumpCallback& callback) override;
62 uint64 GetTracingProcessId() const override;
64 class TraceMessageFilterObserver {
65 public:
66 virtual void OnTraceMessageFilterAdded(TraceMessageFilter* filter) = 0;
67 virtual void OnTraceMessageFilterRemoved(TraceMessageFilter* filter) = 0;
69 void AddTraceMessageFilterObserver(TraceMessageFilterObserver* observer);
70 void RemoveTraceMessageFilterObserver(TraceMessageFilterObserver* observer);
72 private:
73 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
74 friend class TraceMessageFilter;
76 TracingControllerImpl();
77 ~TracingControllerImpl() override;
79 bool can_enable_recording() const {
80 return !is_recording_;
83 bool can_disable_recording() const {
84 return is_recording_ && !trace_data_sink_.get();
87 bool can_enable_monitoring() const {
88 return !is_monitoring_;
91 bool can_disable_monitoring() const {
92 return is_monitoring_ && !monitoring_data_sink_.get();
95 bool can_get_trace_buffer_usage() const {
96 return pending_trace_buffer_usage_callback_.is_null();
99 bool can_cancel_watch_event() const {
100 return !watch_event_callback_.is_null();
103 // Methods for use by TraceMessageFilter.
104 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
105 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
107 void OnTraceDataCollected(
108 const scoped_refptr<base::RefCountedString>& events_str_ptr);
109 void OnMonitoringTraceDataCollected(
110 const scoped_refptr<base::RefCountedString>& events_str_ptr);
112 // Callback of TraceLog::Flush() for the local trace.
113 void OnLocalTraceDataCollected(
114 const scoped_refptr<base::RefCountedString>& events_str_ptr,
115 bool has_more_events);
116 // Callback of TraceLog::FlushMonitoring() for the local trace.
117 void OnLocalMonitoringTraceDataCollected(
118 const scoped_refptr<base::RefCountedString>& events_str_ptr,
119 bool has_more_events);
121 void OnDisableRecordingAcked(
122 TraceMessageFilter* trace_message_filter,
123 const std::vector<std::string>& known_category_groups);
125 #if defined(OS_CHROMEOS) || defined(OS_WIN)
126 void OnEndSystemTracingAcked(
127 const scoped_refptr<base::RefCountedString>& events_str_ptr);
128 #endif
130 void OnEndPowerTracingAcked(
131 const scoped_refptr<base::RefCountedString>& events_str_ptr);
133 void OnCaptureMonitoringSnapshotAcked(
134 TraceMessageFilter* trace_message_filter);
136 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter,
137 const base::trace_event::TraceLogStatus& status);
138 void OnProcessMemoryDumpResponse(TraceMessageFilter* trace_message_filter,
139 uint64 dump_guid,
140 bool success);
142 // Callback of MemoryDumpManager::CreateProcessDump().
143 void OnBrowserProcessMemoryDumpDone(uint64 dump_guid, bool success);
145 void FinalizeGlobalMemoryDumpIfAllProcessesReplied();
147 void OnWatchEventMatched();
149 void SetEnabledOnFileThread(
150 const base::trace_event::TraceConfig& trace_config,
151 int mode,
152 const base::Closure& callback);
153 void SetDisabledOnFileThread(const base::Closure& callback);
154 void OnEnableRecordingDone(
155 const base::trace_event::TraceConfig& trace_config,
156 const EnableRecordingDoneCallback& callback);
157 void OnDisableRecordingDone();
158 void OnEnableMonitoringDone(
159 const base::trace_event::TraceConfig& trace_config,
160 const EnableMonitoringDoneCallback& callback);
161 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
163 void OnMonitoringStateChanged(bool is_monitoring);
165 typedef std::set<scoped_refptr<TraceMessageFilter>> TraceMessageFilterSet;
166 TraceMessageFilterSet trace_message_filters_;
168 // Pending acks for DisableRecording.
169 int pending_disable_recording_ack_count_;
170 TraceMessageFilterSet pending_disable_recording_filters_;
172 // Pending acks for CaptureMonitoringSnapshot.
173 int pending_capture_monitoring_snapshot_ack_count_;
174 TraceMessageFilterSet pending_capture_monitoring_filters_;
176 // Pending acks for GetTraceLogStatus.
177 int pending_trace_log_status_ack_count_;
178 TraceMessageFilterSet pending_trace_log_status_filters_;
179 float maximum_trace_buffer_usage_;
180 size_t approximate_event_count_;
182 // Pending acks for memory RequestGlobalDumpPoint.
183 int pending_memory_dump_ack_count_;
184 int failed_memory_dump_count_;
185 TraceMessageFilterSet pending_memory_dump_filters_;
186 uint64 pending_memory_dump_guid_;
187 base::trace_event::MemoryDumpCallback pending_memory_dump_callback_;
189 #if defined(OS_CHROMEOS) || defined(OS_WIN)
190 bool is_system_tracing_;
191 #endif
192 bool is_recording_;
193 bool is_monitoring_;
194 bool is_power_tracing_;
196 GetCategoriesDoneCallback pending_get_categories_done_callback_;
197 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_;
199 std::string watch_category_name_;
200 std::string watch_event_name_;
201 WatchEventCallback watch_event_callback_;
203 base::ObserverList<TraceMessageFilterObserver>
204 trace_message_filter_observers_;
206 std::set<std::string> known_category_groups_;
207 std::set<TracingUI*> tracing_uis_;
208 scoped_refptr<TraceDataSink> trace_data_sink_;
209 scoped_refptr<TraceDataSink> monitoring_data_sink_;
211 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
214 } // namespace content
216 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_