IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / tracing / tracing_controller_impl.h
blob0684373a96192c170d79a3e8a4d19429c2157172
1 // Copyright 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;
24 class TracingControllerImpl : public TracingController {
25 public:
26 static TracingControllerImpl* GetInstance();
28 // TracingController implementation.
29 virtual bool GetCategories(
30 const GetCategoriesDoneCallback& callback) OVERRIDE;
31 virtual bool EnableRecording(
32 const std::string& category_filter,
33 TracingController::Options options,
34 const EnableRecordingDoneCallback& callback) OVERRIDE;
35 virtual bool DisableRecording(
36 const base::FilePath& result_file_path,
37 const TracingFileResultCallback& callback) OVERRIDE;
38 virtual bool EnableMonitoring(const std::string& category_filter,
39 TracingController::Options options,
40 const EnableMonitoringDoneCallback& callback) OVERRIDE;
41 virtual bool DisableMonitoring(
42 const DisableMonitoringDoneCallback& callback) OVERRIDE;
43 virtual void GetMonitoringStatus(
44 bool* out_enabled,
45 std::string* out_category_filter,
46 TracingController::Options* out_options) OVERRIDE;
47 virtual bool CaptureMonitoringSnapshot(
48 const base::FilePath& result_file_path,
49 const TracingFileResultCallback& callback) OVERRIDE;
50 virtual bool GetTraceBufferPercentFull(
51 const GetTraceBufferPercentFullCallback& callback) OVERRIDE;
52 virtual bool SetWatchEvent(const std::string& category_name,
53 const std::string& event_name,
54 const WatchEventCallback& callback) OVERRIDE;
55 virtual bool CancelWatchEvent() OVERRIDE;
57 private:
58 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterSet;
59 class ResultFile;
61 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>;
62 friend class TraceMessageFilter;
64 TracingControllerImpl();
65 virtual ~TracingControllerImpl();
67 bool can_enable_recording() const {
68 return !is_recording_;
71 bool can_disable_recording() const {
72 return is_recording_ && !result_file_;
75 bool can_enable_monitoring() const {
76 return !is_monitoring_;
79 bool can_disable_monitoring() const {
80 return is_monitoring_ && !monitoring_snapshot_file_;
83 bool can_get_trace_buffer_percent_full() const {
84 return pending_trace_buffer_percent_full_callback_.is_null();
87 bool can_cancel_watch_event() const {
88 return !watch_event_callback_.is_null();
91 // Methods for use by TraceMessageFilter.
92 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter);
93 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter);
95 void OnTraceDataCollected(
96 const scoped_refptr<base::RefCountedString>& events_str_ptr);
97 void OnMonitoringTraceDataCollected(
98 const scoped_refptr<base::RefCountedString>& events_str_ptr);
100 // Callback of TraceLog::Flush() for the local trace.
101 void OnLocalTraceDataCollected(
102 const scoped_refptr<base::RefCountedString>& events_str_ptr,
103 bool has_more_events);
104 // Callback of TraceLog::FlushMonitoring() for the local trace.
105 void OnLocalMonitoringTraceDataCollected(
106 const scoped_refptr<base::RefCountedString>& events_str_ptr,
107 bool has_more_events);
109 void OnDisableRecordingAcked(
110 TraceMessageFilter* trace_message_filter,
111 const std::vector<std::string>& known_category_groups);
112 void OnResultFileClosed();
114 void OnCaptureMonitoringSnapshotAcked(
115 TraceMessageFilter* trace_message_filter);
116 void OnMonitoringSnapshotFileClosed();
118 void OnTraceBufferPercentFullReply(
119 TraceMessageFilter* trace_message_filter,
120 float percent_full);
122 void OnWatchEventMatched();
124 void SetEnabledOnFileThread(const std::string& category_filter,
125 int mode,
126 int options,
127 const base::Closure& callback);
128 void SetDisabledOnFileThread(const base::Closure& callback);
129 void OnEnableRecordingDone(const std::string& category_filter,
130 int trace_options,
131 const EnableRecordingDoneCallback& callback);
132 void OnDisableRecordingDone(const base::FilePath& result_file_path,
133 const TracingFileResultCallback& callback);
134 void OnEnableMonitoringDone(const std::string& category_filter,
135 int trace_options,
136 const EnableMonitoringDoneCallback& callback);
137 void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
139 TraceMessageFilterSet trace_message_filters_;
141 // Pending acks for DisableRecording.
142 int pending_disable_recording_ack_count_;
143 TraceMessageFilterSet pending_disable_recording_filters_;
144 // Pending acks for CaptureMonitoringSnapshot.
145 int pending_capture_monitoring_snapshot_ack_count_;
146 TraceMessageFilterSet pending_capture_monitoring_filters_;
147 // Pending acks for GetTraceBufferPercentFull.
148 int pending_trace_buffer_percent_full_ack_count_;
149 TraceMessageFilterSet pending_trace_buffer_percent_full_filters_;
150 float maximum_trace_buffer_percent_full_;
152 bool is_recording_;
153 bool is_monitoring_;
155 GetCategoriesDoneCallback pending_get_categories_done_callback_;
156 TracingFileResultCallback pending_disable_recording_done_callback_;
157 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_;
158 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_;
160 std::string watch_category_name_;
161 std::string watch_event_name_;
162 WatchEventCallback watch_event_callback_;
164 std::set<std::string> known_category_groups_;
165 scoped_ptr<ResultFile> result_file_;
166 scoped_ptr<ResultFile> monitoring_snapshot_file_;
167 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
170 } // namespace content
172 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_