Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
blobbd4aaa10aaabf0e1e33bbd3a0b64b5441f88ea67
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/files/file_path.h"
13 #include "base/lazy_instance.h"
14 #include "content/public/browser/tracing_controller.h"
16 namespace base {
17 class RefCountedString;
20 namespace content {
22 class TraceMessageFilter;
23 class TracingUI;
25 class TracingControllerImpl : public TracingController {
26 public:
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 base::FilePath& result_file_path,
38 const TracingFileResultCallback& callback) OVERRIDE;
39 virtual bool EnableMonitoring(
40 const base::debug::CategoryFilter& category_filter,
41 const base::debug::TraceOptions& trace_options,
42 const EnableMonitoringDoneCallback& callback) OVERRIDE;
43 virtual bool DisableMonitoring(
44 const DisableMonitoringDoneCallback& callback) OVERRIDE;
45 virtual void GetMonitoringStatus(
46 bool* out_enabled,
47 base::debug::CategoryFilter* out_category_filter,
48 base::debug::TraceOptions* out_trace_options) OVERRIDE;
49 virtual bool CaptureMonitoringSnapshot(
50 const base::FilePath& result_file_path,
51 const TracingFileResultCallback& callback) OVERRIDE;
52 virtual bool GetTraceBufferPercentFull(
53 const GetTraceBufferPercentFullCallback& callback) OVERRIDE;
54 virtual bool SetWatchEvent(const std::string& category_name,
55 const std::string& event_name,
56 const WatchEventCallback& callback) OVERRIDE;
57 virtual bool CancelWatchEvent() OVERRIDE;
59 void RegisterTracingUI(TracingUI* tracing_ui);
60 void UnregisterTracingUI(TracingUI* tracing_ui);
62 private:
63 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet;
64 class ResultFile;
66 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
67 friend class TraceMessageFilter;
69 TracingControllerImpl();
70 virtual ~TracingControllerImpl();
72 bool can_enable_recording() const {
73 return !is_recording_;
76 bool can_disable_recording() const {
77 return is_recording_ && !result_file_;
80 bool can_enable_monitoring() const {
81 return !is_monitoring_;
84 bool can_disable_monitoring() const {
85 return is_monitoring_ && !monitoring_snapshot_file_;
88 bool can_get_trace_buffer_percent_full() const {
89 return pending_trace_buffer_percent_full_callback_.is_null();
92 bool can_cancel_watch_event() const {
93 return !watch_event_callback_.is_null();
96 // Methods for use by TraceMessageFilter.
97 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
98 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
100 void OnTraceDataCollected(
101 const scoped_refptr<base::RefCountedString>& events_str_ptr);
102 void OnMonitoringTraceDataCollected(
103 const scoped_refptr<base::RefCountedString>& events_str_ptr);
105 // Callback of TraceLog::Flush() for the local trace.
106 void OnLocalTraceDataCollected(
107 const scoped_refptr<base::RefCountedString>& events_str_ptr,
108 bool has_more_events);
109 // Callback of TraceLog::FlushMonitoring() for the local trace.
110 void OnLocalMonitoringTraceDataCollected(
111 const scoped_refptr<base::RefCountedString>& events_str_ptr,
112 bool has_more_events);
114 void OnDisableRecordingAcked(
115 TraceMessageFilter* trace_message_filter,
116 const std::vector<std::string>& known_category_groups);
117 void OnDisableRecordingComplete();
118 void OnResultFileClosed();
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);
127 void OnMonitoringSnapshotFileClosed();
129 void OnTraceBufferPercentFullReply(
130 TraceMessageFilter* trace_message_filter,
131 float percent_full);
133 void OnWatchEventMatched();
135 void SetEnabledOnFileThread(
136 const base::debug::CategoryFilter& category_filter,
137 int mode,
138 const base::debug::TraceOptions& trace_options,
139 const base::Closure& callback);
140 void SetDisabledOnFileThread(const base::Closure& callback);
141 void OnEnableRecordingDone(const base::debug::CategoryFilter& category_filter,
142 const base::debug::TraceOptions& trace_options,
143 const EnableRecordingDoneCallback& callback);
144 void OnDisableRecordingDone(const base::FilePath& result_file_path,
145 const TracingFileResultCallback& callback);
146 void OnEnableMonitoringDone(
147 const base::debug::CategoryFilter& category_filter,
148 const base::debug::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 GetTraceBufferPercentFull.
163 int pending_trace_buffer_percent_full_ack_count_;
164 TraceMessageFilterSet pending_trace_buffer_percent_full_filters_;
165 float maximum_trace_buffer_percent_full_;
167 #if defined(OS_CHROMEOS) || defined(OS_WIN)
168 bool is_system_tracing_;
169 #endif
170 bool is_recording_;
171 bool is_monitoring_;
172 base::debug::TraceOptions trace_options_;
174 GetCategoriesDoneCallback pending_get_categories_done_callback_;
175 TracingFileResultCallback pending_disable_recording_done_callback_;
176 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_;
177 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_;
179 std::string watch_category_name_;
180 std::string watch_event_name_;
181 WatchEventCallback watch_event_callback_;
183 std::set<std::string> known_category_groups_;
184 std::set<TracingUI*> tracing_uis_;
185 scoped_ptr<ResultFile> result_file_;
186 scoped_ptr<ResultFile> monitoring_snapshot_file_;
187 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
190 } // namespace content
192 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_