| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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" | 12 #include "base/files/file_path.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "content/public/browser/trace_subscriber.h" |
| 14 #include "content/public/browser/tracing_controller.h" | 15 #include "content/public/browser/tracing_controller.h" |
| 15 | 16 |
| 16 namespace base { | |
| 17 class RefCountedString; | |
| 18 } | |
| 19 | |
| 20 namespace content { | 17 namespace content { |
| 21 | 18 |
| 22 class TraceMessageFilter; | 19 class TraceMessageFilter; |
| 23 | 20 |
| 24 class TracingControllerImpl : public TracingController { | 21 class TracingControllerImpl : public TracingController { |
| 25 public: | 22 public: |
| 26 static TracingControllerImpl* GetInstance(); | 23 static TracingControllerImpl* GetInstance(); |
| 27 | 24 |
| 28 // TracingController implementation. | 25 // TracingController implementation. |
| 29 virtual bool GetCategories( | 26 virtual void GetCategories( |
| 30 const GetCategoriesDoneCallback& callback) OVERRIDE; | 27 const GetCategoriesDoneCallback& callback) OVERRIDE; |
| 31 virtual bool EnableRecording( | 28 virtual bool EnableRecording( |
| 32 const std::string& category_filter, | 29 const base::debug::CategoryFilter& filter, |
| 33 TracingController::Options options, | 30 TracingController::Options options, |
| 34 const EnableRecordingDoneCallback& callback) OVERRIDE; | 31 const EnableRecordingDoneCallback& callback) OVERRIDE; |
| 35 virtual bool DisableRecording( | 32 virtual bool DisableRecording( |
| 36 const base::FilePath& result_file_path, | 33 const base::FilePath& result_file_path, |
| 37 const TracingFileResultCallback& callback) OVERRIDE; | 34 const TracingFileResultCallback& callback) OVERRIDE; |
| 38 virtual bool EnableMonitoring(const std::string& category_filter, | 35 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, |
| 39 TracingController::Options options, | 36 TracingController::Options options, |
| 40 const EnableMonitoringDoneCallback& callback) OVERRIDE; | 37 const EnableMonitoringDoneCallback& callback) OVERRIDE; |
| 41 virtual bool DisableMonitoring( | 38 virtual bool DisableMonitoring( |
| 42 const DisableMonitoringDoneCallback& callback) OVERRIDE; | 39 const DisableMonitoringDoneCallback& callback) OVERRIDE; |
| 43 virtual void GetMonitoringStatus( | 40 virtual void GetMonitoringStatus( |
| 44 bool* out_enabled, | 41 bool* out_enabled, |
| 45 std::string* out_category_filter, | 42 base::debug::CategoryFilter* out_filter, |
| 46 TracingController::Options* out_options) OVERRIDE; | 43 TracingController::Options* out_options) OVERRIDE; |
| 47 virtual bool CaptureMonitoringSnapshot( | 44 virtual void CaptureMonitoringSnapshot( |
| 48 const base::FilePath& result_file_path, | 45 const base::FilePath& result_file_path, |
| 49 const TracingFileResultCallback& callback) OVERRIDE; | 46 const TracingFileResultCallback& callback) OVERRIDE; |
| 50 virtual bool GetTraceBufferPercentFull( | 47 virtual bool GetTraceBufferPercentFull( |
| 51 const GetTraceBufferPercentFullCallback& callback) OVERRIDE; | 48 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; | |
| 56 | 49 |
| 57 private: | 50 private: |
| 58 typedef std::set<scoped_refptr<TraceMessageFilter> > TraceMessageFilterMap; | 51 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; |
| 59 class ResultFile; | 52 class ResultFile; |
| 60 | 53 |
| 61 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; | 54 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; |
| 62 friend class TraceMessageFilter; | 55 friend class TraceMessageFilter; |
| 63 | 56 |
| 64 TracingControllerImpl(); | 57 TracingControllerImpl(); |
| 65 virtual ~TracingControllerImpl(); | 58 virtual ~TracingControllerImpl(); |
| 66 | 59 |
| 67 bool can_enable_recording() const { | 60 bool can_enable_recording() const { |
| 68 return !is_recording_; | 61 return !is_recording_; |
| 69 } | 62 } |
| 70 | 63 |
| 71 bool can_disable_recording() const { | 64 bool can_disable_recording() const { |
| 72 return is_recording_ && !result_file_; | 65 return is_recording_ && !result_file_; |
| 73 } | 66 } |
| 74 | 67 |
| 75 bool can_enable_monitoring() const { | 68 bool can_enable_monitoring() const { |
| 76 return !is_monitoring_; | 69 return !is_monitoring_; |
| 77 } | 70 } |
| 78 | 71 |
| 79 bool can_disable_monitoring() const { | 72 bool can_disable_monitoring() const { |
| 80 return is_monitoring_ && !monitoring_snapshot_file_; | 73 return is_monitoring_ && !monitoring_snapshot_file_; |
| 81 } | 74 } |
| 82 | 75 |
| 83 bool can_get_trace_buffer_percent_full() const { | 76 bool can_get_trace_buffer_percent_full() const { |
| 84 return pending_trace_buffer_percent_full_callback_.is_null(); | 77 return pending_trace_buffer_percent_full_callback_.is_null(); |
| 85 } | 78 } |
| 86 | 79 |
| 87 bool can_cancel_watch_event() const { | |
| 88 return !watch_event_callback_.is_null(); | |
| 89 } | |
| 90 | |
| 91 // Methods for use by TraceMessageFilter. | 80 // Methods for use by TraceMessageFilter. |
| 92 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter); | 81 void AddFilter(TraceMessageFilter* filter); |
| 93 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter); | 82 void RemoveFilter(TraceMessageFilter* filter); |
| 94 | 83 |
| 95 void OnTraceDataCollected( | 84 void OnTraceDataCollected( |
| 96 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 85 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 97 void OnMonitoringTraceDataCollected( | 86 void OnMonitoringTraceDataCollected( |
| 98 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 87 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 99 | 88 |
| 100 // Callback of TraceLog::Flush() for the local trace. | 89 // Callback of TraceLog::Flush() for the local trace. |
| 101 void OnLocalTraceDataCollected( | 90 void OnLocalTraceDataCollected( |
| 102 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 91 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 103 bool has_more_events); | 92 bool has_more_events); |
| 104 // Callback of TraceLog::FlushMonitoring() for the local trace. | 93 // Callback of TraceLog::FlushMonitoring() for the local trace. |
| 105 void OnLocalMonitoringTraceDataCollected( | 94 void OnLocalMonitoringTraceDataCollected( |
| 106 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 95 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 107 bool has_more_events); | 96 bool has_more_events); |
| 108 | 97 |
| 109 void OnDisableRecordingAcked( | 98 void OnDisableRecordingAcked( |
| 110 const std::vector<std::string>& known_category_groups); | 99 const std::vector<std::string>& known_category_groups); |
| 111 void OnResultFileClosed(); | 100 void OnResultFileClosed(); |
| 112 | 101 |
| 113 void OnCaptureMonitoringSnapshotAcked(); | 102 void OnCaptureMonitoringSnapshotAcked(); |
| 114 void OnMonitoringSnapshotFileClosed(); | 103 void OnMonitoringSnapshotFileClosed(); |
| 115 | 104 |
| 105 void OnTraceNotification(int notification); |
| 116 void OnTraceBufferPercentFullReply(float percent_full); | 106 void OnTraceBufferPercentFullReply(float percent_full); |
| 117 | 107 |
| 118 void OnWatchEventMatched(); | 108 FilterMap filters_; |
| 119 | |
| 120 TraceMessageFilterMap trace_message_filters_; | |
| 121 // Pending acks for DisableRecording. | 109 // Pending acks for DisableRecording. |
| 122 int pending_disable_recording_ack_count_; | 110 int pending_disable_recording_ack_count_; |
| 123 // Pending acks for CaptureMonitoringSnapshot. | 111 // Pending acks for CaptureMonitoringSnapshot. |
| 124 int pending_capture_monitoring_snapshot_ack_count_; | 112 int pending_capture_monitoring_snapshot_ack_count_; |
| 125 // Pending acks for GetTraceBufferPercentFull. | 113 // Pending acks for GetTraceBufferPercentFull. |
| 126 int pending_trace_buffer_percent_full_ack_count_; | 114 int pending_trace_buffer_percent_full_ack_count_; |
| 127 float maximum_trace_buffer_percent_full_; | 115 float maximum_trace_buffer_percent_full_; |
| 128 | 116 |
| 129 bool is_recording_; | 117 bool is_recording_; |
| 130 bool is_monitoring_; | 118 bool is_monitoring_; |
| 131 | 119 |
| 132 GetCategoriesDoneCallback pending_get_categories_done_callback_; | 120 GetCategoriesDoneCallback pending_get_categories_done_callback_; |
| 133 TracingFileResultCallback pending_disable_recording_done_callback_; | 121 TracingFileResultCallback pending_disable_recording_done_callback_; |
| 134 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_; | 122 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_; |
| 135 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_; | 123 GetTraceBufferPercentFullCallback pending_trace_buffer_percent_full_callback_; |
| 136 | 124 |
| 137 std::string watch_category_name_; | |
| 138 std::string watch_event_name_; | |
| 139 WatchEventCallback watch_event_callback_; | |
| 140 | |
| 141 std::set<std::string> known_category_groups_; | 125 std::set<std::string> known_category_groups_; |
| 126 base::debug::CategoryFilter category_filter_; |
| 142 scoped_ptr<ResultFile> result_file_; | 127 scoped_ptr<ResultFile> result_file_; |
| 143 scoped_ptr<ResultFile> monitoring_snapshot_file_; | 128 scoped_ptr<ResultFile> monitoring_snapshot_file_; |
| 144 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); | 129 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); |
| 145 }; | 130 }; |
| 146 | 131 |
| 147 } // namespace content | 132 } // namespace content |
| 148 | 133 |
| 149 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 134 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
| OLD | NEW |