| 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/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "content/public/browser/trace_subscriber.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 content { | 17 namespace content { |
| 17 | 18 |
| 18 class TraceMessageFilter; | 19 class TraceMessageFilter; |
| 19 | 20 |
| 20 class TracingControllerImpl : | 21 class TracingControllerImpl : public TracingController { |
| 21 public TracingController, public TraceSubscriber { | |
| 22 public: | 22 public: |
| 23 static TracingControllerImpl* GetInstance(); | 23 static TracingControllerImpl* GetInstance(); |
| 24 | 24 |
| 25 // TracingController implementation. | 25 // TracingController implementation. |
| 26 virtual void GetCategories( | 26 virtual void GetCategories( |
| 27 const GetCategoriesDoneCallback& callback) OVERRIDE; | 27 const GetCategoriesDoneCallback& callback) OVERRIDE; |
| 28 virtual bool EnableRecording( | 28 virtual bool EnableRecording( |
| 29 const base::debug::CategoryFilter& filter, | 29 const base::debug::CategoryFilter& filter, |
| 30 TracingController::Options options, | 30 TracingController::Options options, |
| 31 const EnableRecordingDoneCallback& callback) OVERRIDE; | 31 const EnableRecordingDoneCallback& callback) OVERRIDE; |
| 32 virtual bool DisableRecording( | 32 virtual bool DisableRecording( |
| 33 const base::FilePath& result_file_path, |
| 33 const TracingFileResultCallback& callback) OVERRIDE; | 34 const TracingFileResultCallback& callback) OVERRIDE; |
| 34 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, | 35 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, |
| 35 TracingController::Options options, | 36 TracingController::Options options, |
| 36 const EnableMonitoringDoneCallback& callback) OVERRIDE; | 37 const EnableMonitoringDoneCallback& callback) OVERRIDE; |
| 37 virtual bool DisableMonitoring( | 38 virtual bool DisableMonitoring( |
| 38 const DisableMonitoringDoneCallback& callback) OVERRIDE; | 39 const DisableMonitoringDoneCallback& callback) OVERRIDE; |
| 39 virtual void GetMonitoringStatus( | 40 virtual void GetMonitoringStatus( |
| 40 bool* out_enabled, | 41 bool* out_enabled, |
| 41 base::debug::CategoryFilter* out_filter, | 42 base::debug::CategoryFilter* out_filter, |
| 42 TracingController::Options* out_options) OVERRIDE; | 43 TracingController::Options* out_options) OVERRIDE; |
| 43 virtual void CaptureMonitoringSnapshot( | 44 virtual void CaptureMonitoringSnapshot( |
| 45 const base::FilePath& result_file_path, |
| 44 const TracingFileResultCallback& callback) OVERRIDE; | 46 const TracingFileResultCallback& callback) OVERRIDE; |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; | 49 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; |
| 50 class ResultFile; |
| 48 | 51 |
| 49 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; | 52 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; |
| 50 friend class TraceMessageFilter; | 53 friend class TraceMessageFilter; |
| 51 | 54 |
| 52 TracingControllerImpl(); | 55 TracingControllerImpl(); |
| 53 virtual ~TracingControllerImpl(); | 56 virtual ~TracingControllerImpl(); |
| 54 | 57 |
| 55 // TraceSubscriber implementation. | |
| 56 virtual void OnTraceDataCollected( | |
| 57 const scoped_refptr<base::RefCountedString>& events_str_ptr) OVERRIDE; | |
| 58 | |
| 59 bool can_enable_recording() const { | 58 bool can_enable_recording() const { |
| 60 return !is_recording_; | 59 return !is_recording_; |
| 61 } | 60 } |
| 62 | 61 |
| 63 bool can_disable_recording() const { | 62 bool can_disable_recording() const { |
| 64 return is_recording_ && pending_disable_recording_ack_count_ == 0; | 63 return is_recording_ && pending_disable_recording_ack_count_ == 0; |
| 65 } | 64 } |
| 66 | 65 |
| 67 bool can_enable_monitoring() const { | 66 bool can_enable_monitoring() const { |
| 68 return !is_monitoring_; | 67 return !is_monitoring_; |
| 69 } | 68 } |
| 70 | 69 |
| 71 bool can_disable_monitoring() const { | 70 bool can_disable_monitoring() const { |
| 72 return is_monitoring_ && | 71 return is_monitoring_ && |
| 73 pending_capture_monitoring_snapshot_ack_count_ == 0; | 72 pending_capture_monitoring_snapshot_ack_count_ == 0; |
| 74 } | 73 } |
| 75 | 74 |
| 76 // Methods for use by TraceMessageFilter. | 75 // Methods for use by TraceMessageFilter. |
| 77 void AddFilter(TraceMessageFilter* filter); | 76 void AddFilter(TraceMessageFilter* filter); |
| 78 void RemoveFilter(TraceMessageFilter* filter); | 77 void RemoveFilter(TraceMessageFilter* filter); |
| 79 | 78 |
| 79 void OnTraceDataCollected( |
| 80 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 81 void OnMonitoringTraceDataCollected( |
| 82 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 83 |
| 80 // Callback of TraceLog::Flush() for the local trace. | 84 // Callback of TraceLog::Flush() for the local trace. |
| 81 void OnLocalTraceDataCollected( | 85 void OnLocalTraceDataCollected( |
| 82 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 86 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 83 bool has_more_events); | 87 bool has_more_events); |
| 84 // Callback of TraceLog::FlushMonitoring() for the local trace. | 88 // Callback of TraceLog::FlushMonitoring() for the local trace. |
| 85 void OnLocalMonitoringTraceDataCollected( | 89 void OnLocalMonitoringTraceDataCollected( |
| 86 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 90 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 87 bool has_more_events); | 91 bool has_more_events); |
| 88 | 92 |
| 89 void OnDisableRecordingAcked( | 93 void OnDisableRecordingAcked( |
| 90 const std::vector<std::string>& known_category_groups); | 94 const std::vector<std::string>& known_category_groups); |
| 95 void OnResultFileClosed(); |
| 96 |
| 91 void OnCaptureMonitoringSnapshotAcked(); | 97 void OnCaptureMonitoringSnapshotAcked(); |
| 98 void OnMonitoringSnapshotFileClosed(); |
| 92 | 99 |
| 93 FilterMap filters_; | 100 FilterMap filters_; |
| 94 // Pending acks for DisableRecording. | 101 // Pending acks for DisableRecording. |
| 95 int pending_disable_recording_ack_count_; | 102 int pending_disable_recording_ack_count_; |
| 96 // Pending acks for CaptureMonitoringSnapshot. | 103 // Pending acks for CaptureMonitoringSnapshot. |
| 97 int pending_capture_monitoring_snapshot_ack_count_; | 104 int pending_capture_monitoring_snapshot_ack_count_; |
| 98 bool is_recording_; | 105 bool is_recording_; |
| 99 bool is_monitoring_; | 106 bool is_monitoring_; |
| 100 GetCategoriesDoneCallback pending_get_categories_done_callback_; | 107 GetCategoriesDoneCallback pending_get_categories_done_callback_; |
| 101 TracingFileResultCallback pending_disable_recording_done_callback_; | 108 TracingFileResultCallback pending_disable_recording_done_callback_; |
| 102 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_; | 109 TracingFileResultCallback pending_capture_monitoring_snapshot_done_callback_; |
| 103 std::set<std::string> known_category_groups_; | 110 std::set<std::string> known_category_groups_; |
| 104 base::debug::TraceLog::Options trace_options_; | 111 base::debug::TraceLog::Options trace_options_; |
| 105 base::debug::CategoryFilter category_filter_; | 112 base::debug::CategoryFilter category_filter_; |
| 106 FILE* result_file_; | 113 scoped_ptr<ResultFile> result_file_; |
| 107 scoped_ptr<base::FilePath> result_file_path_; | 114 scoped_ptr<ResultFile> monitoring_snapshot_file_; |
| 108 bool result_file_has_at_least_one_result_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); | 115 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 } // namespace content | 118 } // namespace content |
| 114 | 119 |
| 115 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 120 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
| OLD | NEW |