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