OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
6 #define CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 6 #define CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file_path.h" | |
13 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
14 #include "content/public/browser/tracing_controller.h" | 13 #include "content/public/browser/tracing_controller.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class RefCountedString; | 16 class RefCountedString; |
| 17 class RefCountedMemory; |
18 } | 18 } |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class TraceMessageFilter; | 22 class TraceMessageFilter; |
23 class TracingUI; | 23 class TracingUI; |
24 | 24 |
25 class TracingControllerImpl : public TracingController { | 25 class TracingControllerImpl : public TracingController { |
26 public: | 26 public: |
27 static TracingControllerImpl* GetInstance(); | 27 static TracingControllerImpl* GetInstance(); |
28 | 28 |
29 // TracingController implementation. | 29 // TracingController implementation. |
30 virtual bool GetCategories( | 30 virtual bool GetCategories( |
31 const GetCategoriesDoneCallback& callback) OVERRIDE; | 31 const GetCategoriesDoneCallback& callback) OVERRIDE; |
32 virtual bool EnableRecording( | 32 virtual bool EnableRecording( |
33 const base::debug::CategoryFilter& category_filter, | 33 const base::debug::CategoryFilter& category_filter, |
34 const base::debug::TraceOptions& trace_options, | 34 const base::debug::TraceOptions& trace_options, |
35 const EnableRecordingDoneCallback& callback) OVERRIDE; | 35 const EnableRecordingDoneCallback& callback) OVERRIDE; |
36 virtual bool DisableRecording( | 36 virtual bool DisableRecording( |
37 const base::FilePath& result_file_path, | 37 const scoped_refptr<TraceDataSink>& sink) OVERRIDE; |
38 const TracingFileResultCallback& callback) OVERRIDE; | |
39 virtual bool EnableMonitoring( | 38 virtual bool EnableMonitoring( |
40 const base::debug::CategoryFilter& category_filter, | 39 const base::debug::CategoryFilter& category_filter, |
41 const base::debug::TraceOptions& trace_options, | 40 const base::debug::TraceOptions& trace_options, |
42 const EnableMonitoringDoneCallback& callback) OVERRIDE; | 41 const EnableMonitoringDoneCallback& callback) OVERRIDE; |
43 virtual bool DisableMonitoring( | 42 virtual bool DisableMonitoring( |
44 const DisableMonitoringDoneCallback& callback) OVERRIDE; | 43 const DisableMonitoringDoneCallback& callback) OVERRIDE; |
45 virtual void GetMonitoringStatus( | 44 virtual void GetMonitoringStatus( |
46 bool* out_enabled, | 45 bool* out_enabled, |
47 base::debug::CategoryFilter* out_category_filter, | 46 base::debug::CategoryFilter* out_category_filter, |
48 base::debug::TraceOptions* out_trace_options) OVERRIDE; | 47 base::debug::TraceOptions* out_trace_options) OVERRIDE; |
49 virtual bool CaptureMonitoringSnapshot( | 48 virtual bool CaptureMonitoringSnapshot( |
50 const base::FilePath& result_file_path, | 49 const scoped_refptr<TraceDataSink>& sink) OVERRIDE; |
51 const TracingFileResultCallback& callback) OVERRIDE; | |
52 virtual bool GetTraceBufferPercentFull( | 50 virtual bool GetTraceBufferPercentFull( |
53 const GetTraceBufferPercentFullCallback& callback) OVERRIDE; | 51 const GetTraceBufferPercentFullCallback& callback) OVERRIDE; |
54 virtual bool SetWatchEvent(const std::string& category_name, | 52 virtual bool SetWatchEvent(const std::string& category_name, |
55 const std::string& event_name, | 53 const std::string& event_name, |
56 const WatchEventCallback& callback) OVERRIDE; | 54 const WatchEventCallback& callback) OVERRIDE; |
57 virtual bool CancelWatchEvent() OVERRIDE; | 55 virtual bool CancelWatchEvent() OVERRIDE; |
58 | 56 |
59 void RegisterTracingUI(TracingUI* tracing_ui); | 57 void RegisterTracingUI(TracingUI* tracing_ui); |
60 void UnregisterTracingUI(TracingUI* tracing_ui); | 58 void UnregisterTracingUI(TracingUI* tracing_ui); |
61 | 59 |
62 private: | 60 private: |
63 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet; | 61 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet; |
64 class ResultFile; | |
65 | 62 |
66 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; | 63 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; |
67 friend class TraceMessageFilter; | 64 friend class TraceMessageFilter; |
68 | 65 |
69 TracingControllerImpl(); | 66 TracingControllerImpl(); |
70 virtual ~TracingControllerImpl(); | 67 virtual ~TracingControllerImpl(); |
71 | 68 |
72 bool can_enable_recording() const { | 69 bool can_enable_recording() const { |
73 return !is_recording_; | 70 return !is_recording_; |
74 } | 71 } |
75 | 72 |
76 bool can_disable_recording() const { | 73 bool can_disable_recording() const { |
77 return is_recording_ && !result_file_; | 74 return is_recording_ && !trace_data_sink_.get(); |
78 } | 75 } |
79 | 76 |
80 bool can_enable_monitoring() const { | 77 bool can_enable_monitoring() const { |
81 return !is_monitoring_; | 78 return !is_monitoring_; |
82 } | 79 } |
83 | 80 |
84 bool can_disable_monitoring() const { | 81 bool can_disable_monitoring() const { |
85 return is_monitoring_ && !monitoring_snapshot_file_; | 82 return is_monitoring_ && !monitoring_data_sink_.get(); |
86 } | 83 } |
87 | 84 |
88 bool can_get_trace_buffer_percent_full() const { | 85 bool can_get_trace_buffer_percent_full() const { |
89 return pending_trace_buffer_percent_full_callback_.is_null(); | 86 return pending_trace_buffer_percent_full_callback_.is_null(); |
90 } | 87 } |
91 | 88 |
92 bool can_cancel_watch_event() const { | 89 bool can_cancel_watch_event() const { |
93 return !watch_event_callback_.is_null(); | 90 return !watch_event_callback_.is_null(); |
94 } | 91 } |
95 | 92 |
(...skipping 11 matching lines...) Expand all Loading... |
107 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 104 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
108 bool has_more_events); | 105 bool has_more_events); |
109 // Callback of TraceLog::FlushMonitoring() for the local trace. | 106 // Callback of TraceLog::FlushMonitoring() for the local trace. |
110 void OnLocalMonitoringTraceDataCollected( | 107 void OnLocalMonitoringTraceDataCollected( |
111 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 108 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
112 bool has_more_events); | 109 bool has_more_events); |
113 | 110 |
114 void OnDisableRecordingAcked( | 111 void OnDisableRecordingAcked( |
115 TraceMessageFilter* trace_message_filter, | 112 TraceMessageFilter* trace_message_filter, |
116 const std::vector<std::string>& known_category_groups); | 113 const std::vector<std::string>& known_category_groups); |
117 void OnDisableRecordingComplete(); | |
118 void OnResultFileClosed(); | |
119 | 114 |
120 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 115 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
121 void OnEndSystemTracingAcked( | 116 void OnEndSystemTracingAcked( |
122 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 117 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
123 #endif | 118 #endif |
124 | 119 |
125 void OnCaptureMonitoringSnapshotAcked( | 120 void OnCaptureMonitoringSnapshotAcked( |
126 TraceMessageFilter* trace_message_filter); | 121 TraceMessageFilter* trace_message_filter); |
127 void OnMonitoringSnapshotFileClosed(); | |
128 | 122 |
129 void OnTraceBufferPercentFullReply( | 123 void OnTraceBufferPercentFullReply( |
130 TraceMessageFilter* trace_message_filter, | 124 TraceMessageFilter* trace_message_filter, |
131 float percent_full); | 125 float percent_full); |
132 | 126 |
133 void OnWatchEventMatched(); | 127 void OnWatchEventMatched(); |
134 | 128 |
135 void SetEnabledOnFileThread( | 129 void SetEnabledOnFileThread( |
136 const base::debug::CategoryFilter& category_filter, | 130 const base::debug::CategoryFilter& category_filter, |
137 int mode, | 131 int mode, |
138 const base::debug::TraceOptions& trace_options, | 132 const base::debug::TraceOptions& trace_options, |
139 const base::Closure& callback); | 133 const base::Closure& callback); |
140 void SetDisabledOnFileThread(const base::Closure& callback); | 134 void SetDisabledOnFileThread(const base::Closure& callback); |
141 void OnEnableRecordingDone(const base::debug::CategoryFilter& category_filter, | 135 void OnEnableRecordingDone(const base::debug::CategoryFilter& category_filter, |
142 const base::debug::TraceOptions& trace_options, | 136 const base::debug::TraceOptions& trace_options, |
143 const EnableRecordingDoneCallback& callback); | 137 const EnableRecordingDoneCallback& callback); |
144 void OnDisableRecordingDone(const base::FilePath& result_file_path, | 138 void OnDisableRecordingDone(); |
145 const TracingFileResultCallback& callback); | |
146 void OnEnableMonitoringDone( | 139 void OnEnableMonitoringDone( |
147 const base::debug::CategoryFilter& category_filter, | 140 const base::debug::CategoryFilter& category_filter, |
148 const base::debug::TraceOptions& trace_options, | 141 const base::debug::TraceOptions& trace_options, |
149 const EnableMonitoringDoneCallback& callback); | 142 const EnableMonitoringDoneCallback& callback); |
150 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback); | 143 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback); |
151 | 144 |
152 void OnMonitoringStateChanged(bool is_monitoring); | 145 void OnMonitoringStateChanged(bool is_monitoring); |
153 | 146 |
154 TraceMessageFilterSet trace_message_filters_; | 147 TraceMessageFilterSet trace_message_filters_; |
155 | 148 |
156 // Pending acks for DisableRecording. | 149 // Pending acks for DisableRecording. |
157 int pending_disable_recording_ack_count_; | 150 int pending_disable_recording_ack_count_; |
158 TraceMessageFilterSet pending_disable_recording_filters_; | 151 TraceMessageFilterSet pending_disable_recording_filters_; |
159 // Pending acks for CaptureMonitoringSnapshot. | 152 // Pending acks for CaptureMonitoringSnapshot. |
160 int pending_capture_monitoring_snapshot_ack_count_; | 153 int pending_capture_monitoring_snapshot_ack_count_; |
161 TraceMessageFilterSet pending_capture_monitoring_filters_; | 154 TraceMessageFilterSet pending_capture_monitoring_filters_; |
162 // Pending acks for GetTraceBufferPercentFull. | 155 // Pending acks for GetTraceBufferPercentFull. |
163 int pending_trace_buffer_percent_full_ack_count_; | 156 int pending_trace_buffer_percent_full_ack_count_; |
164 TraceMessageFilterSet pending_trace_buffer_percent_full_filters_; | 157 TraceMessageFilterSet pending_trace_buffer_percent_full_filters_; |
165 float maximum_trace_buffer_percent_full_; | 158 float maximum_trace_buffer_percent_full_; |
166 | 159 |
167 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 160 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
168 bool is_system_tracing_; | 161 bool is_system_tracing_; |
169 #endif | 162 #endif |
170 bool is_recording_; | 163 bool is_recording_; |
171 bool is_monitoring_; | 164 bool is_monitoring_; |
172 base::debug::TraceOptions trace_options_; | 165 base::debug::TraceOptions trace_options_; |
173 | 166 |
174 GetCategoriesDoneCallback pending_get_categories_done_callback_; | 167 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_; | 168 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_; |
178 | 169 |
179 std::string watch_category_name_; | 170 std::string watch_category_name_; |
180 std::string watch_event_name_; | 171 std::string watch_event_name_; |
181 WatchEventCallback watch_event_callback_; | 172 WatchEventCallback watch_event_callback_; |
182 | 173 |
183 std::set<std::string> known_category_groups_; | 174 std::set<std::string> known_category_groups_; |
184 std::set<TracingUI*> tracing_uis_; | 175 std::set<TracingUI*> tracing_uis_; |
185 scoped_ptr<ResultFile> result_file_; | 176 scoped_refptr<TraceDataSink> trace_data_sink_; |
186 scoped_ptr<ResultFile> monitoring_snapshot_file_; | 177 scoped_refptr<TraceDataSink> monitoring_data_sink_; |
187 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); | 178 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); |
188 }; | 179 }; |
189 | 180 |
190 } // namespace content | 181 } // namespace content |
191 | 182 |
192 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 183 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
OLD | NEW |