Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
blob4b732ece0d3333c8d58b527e9c1a4aa7889363a8
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;
64 bool IsCoordinatorProcess() const override;
66 private:
67 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet;
69 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
70 friend class TraceMessageFilter;
72 TracingControllerImpl();
73 ~TracingControllerImpl() override;
75 bool can_enable_recording() const {
76 return !is_recording_;
79 bool can_disable_recording() const {
80 return is_recording_ && !trace_data_sink_.get();
83 bool can_enable_monitoring() const {
84 return !is_monitoring_;
87 bool can_disable_monitoring() const {
88 return is_monitoring_ && !monitoring_data_sink_.get();
91 bool can_get_trace_buffer_usage() const {
92 return pending_trace_buffer_usage_callback_.is_null();
95 bool can_cancel_watch_event() const {
96 return !watch_event_callback_.is_null();
99 // Methods for use by TraceMessageFilter.
100 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
101 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
103 void OnTraceDataCollected(
104 const scoped_refptr<base::RefCountedString>& events_str_ptr);
105 void OnMonitoringTraceDataCollected(
106 const scoped_refptr<base::RefCountedString>& events_str_ptr);
108 // Callback of TraceLog::Flush() for the local trace.
109 void OnLocalTraceDataCollected(
110 const scoped_refptr<base::RefCountedString>& events_str_ptr,
111 bool has_more_events);
112 // Callback of TraceLog::FlushMonitoring() for the local trace.
113 void OnLocalMonitoringTraceDataCollected(
114 const scoped_refptr<base::RefCountedString>& events_str_ptr,
115 bool has_more_events);
117 void OnDisableRecordingAcked(
118 TraceMessageFilter* trace_message_filter,
119 const std::vector<std::string>& known_category_groups);
121 #if defined(OS_CHROMEOS) || defined(OS_WIN)
122 void OnEndSystemTracingAcked(
123 const scoped_refptr<base::RefCountedString>& events_str_ptr);
124 #endif
126 void OnCaptureMonitoringSnapshotAcked(
127 TraceMessageFilter* trace_message_filter);
129 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter,
130 const base::trace_event::TraceLogStatus& status);
131 void OnProcessMemoryDumpResponse(TraceMessageFilter* trace_message_filter,
132 uint64 dump_guid,
133 bool success);
135 // Callback of MemoryDumpManager::CreateProcessDump().
136 void OnBrowserProcessMemoryDumpDone(uint64 dump_guid, bool success);
138 void FinalizeGlobalMemoryDumpIfAllProcessesReplied();
140 void OnWatchEventMatched();
142 void SetEnabledOnFileThread(
143 const base::trace_event::CategoryFilter& category_filter,
144 int mode,
145 const base::trace_event::TraceOptions& trace_options,
146 const base::Closure& callback);
147 void SetDisabledOnFileThread(const base::Closure& callback);
148 void OnEnableRecordingDone(
149 const base::trace_event::CategoryFilter& category_filter,
150 const base::trace_event::TraceOptions& trace_options,
151 const EnableRecordingDoneCallback& callback);
152 void OnDisableRecordingDone();
153 void OnEnableMonitoringDone(
154 const base::trace_event::CategoryFilter& category_filter,
155 const base::trace_event::TraceOptions& trace_options,
156 const EnableMonitoringDoneCallback& callback);
157 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
159 void OnMonitoringStateChanged(bool is_monitoring);
161 TraceMessageFilterSet trace_message_filters_;
163 // Pending acks for DisableRecording.
164 int pending_disable_recording_ack_count_;
165 TraceMessageFilterSet pending_disable_recording_filters_;
167 // Pending acks for CaptureMonitoringSnapshot.
168 int pending_capture_monitoring_snapshot_ack_count_;
169 TraceMessageFilterSet pending_capture_monitoring_filters_;
171 // Pending acks for GetTraceLogStatus.
172 int pending_trace_log_status_ack_count_;
173 TraceMessageFilterSet pending_trace_log_status_filters_;
174 float maximum_trace_buffer_usage_;
175 size_t approximate_event_count_;
177 // Pending acks for memory RequestGlobalDumpPoint.
178 int pending_memory_dump_ack_count_;
179 int failed_memory_dump_count_;
180 TraceMessageFilterSet pending_memory_dump_filters_;
181 uint64 pending_memory_dump_guid_;
182 base::trace_event::MemoryDumpCallback pending_memory_dump_callback_;
184 #if defined(OS_CHROMEOS) || defined(OS_WIN)
185 bool is_system_tracing_;
186 #endif
187 bool is_recording_;
188 bool is_monitoring_;
189 base::trace_event::TraceOptions trace_options_;
191 GetCategoriesDoneCallback pending_get_categories_done_callback_;
192 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_;
194 std::string watch_category_name_;
195 std::string watch_event_name_;
196 WatchEventCallback watch_event_callback_;
198 std::set<std::string> known_category_groups_;
199 std::set<TracingUI*> tracing_uis_;
200 scoped_refptr<TraceDataSink> trace_data_sink_;
201 scoped_refptr<TraceDataSink> monitoring_data_sink_;
202 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
205 } // namespace content
207 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_