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