| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/debug/trace_event.h" | |
| 13 #include "base/lazy_instance.h" | |
| 14 #include "content/public/browser/trace_controller.h" | |
| 15 | |
| 16 class CommandLine; | |
| 17 | |
| 18 namespace content { | |
| 19 class TraceMessageFilter; | |
| 20 | |
| 21 class TraceControllerImpl : public TraceController { | |
| 22 public: | |
| 23 static TraceControllerImpl* GetInstance(); | |
| 24 | |
| 25 // Called on the main thread of the browser process to initialize | |
| 26 // startup tracing. | |
| 27 void InitStartupTracing(const CommandLine& command_line); | |
| 28 | |
| 29 // Get set of known categories. This can change as new code paths are reached. | |
| 30 // If true is returned, subscriber->OnKnownCategoriesCollected will be called | |
| 31 // once the categories are retrieved from child processes. | |
| 32 bool GetKnownCategoriesAsync(TraceSubscriber* subscriber); | |
| 33 | |
| 34 // Same as above, but specifies which categories to trace. | |
| 35 // If both included_categories and excluded_categories are empty, | |
| 36 // all categories are traced. | |
| 37 // Else if included_categories is non-empty, only those are traced. | |
| 38 // Else if excluded_categories is non-empty, everything but those are traced. | |
| 39 bool BeginTracing(TraceSubscriber* subscriber, | |
| 40 const std::vector<std::string>& included_categories, | |
| 41 const std::vector<std::string>& excluded_categories); | |
| 42 | |
| 43 // TraceController implementation: | |
| 44 virtual bool BeginTracing(TraceSubscriber* subscriber, | |
| 45 const std::string& categories) OVERRIDE; | |
| 46 virtual bool EndTracingAsync(TraceSubscriber* subscriber) OVERRIDE; | |
| 47 virtual bool GetTraceBufferPercentFullAsync( | |
| 48 TraceSubscriber* subscriber) OVERRIDE; | |
| 49 virtual bool SetWatchEvent(TraceSubscriber* subscriber, | |
| 50 const std::string& category_name, | |
| 51 const std::string& event_name) OVERRIDE; | |
| 52 virtual bool CancelWatchEvent(TraceSubscriber* subscriber) OVERRIDE; | |
| 53 virtual void CancelSubscriber(TraceSubscriber* subscriber) OVERRIDE; | |
| 54 | |
| 55 private: | |
| 56 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; | |
| 57 | |
| 58 friend struct base::DefaultLazyInstanceTraits<TraceControllerImpl>; | |
| 59 friend class TraceMessageFilter; | |
| 60 | |
| 61 TraceControllerImpl(); | |
| 62 virtual ~TraceControllerImpl(); | |
| 63 | |
| 64 bool is_tracing_enabled() const { | |
| 65 return can_end_tracing(); | |
| 66 } | |
| 67 | |
| 68 bool can_end_tracing() const { | |
| 69 return is_tracing_ && pending_end_ack_count_ == 0; | |
| 70 } | |
| 71 | |
| 72 // Can get Buffer Percent Full | |
| 73 bool can_get_buffer_percent_full() const { | |
| 74 return is_tracing_ && | |
| 75 pending_end_ack_count_ == 0 && | |
| 76 pending_bpf_ack_count_ == 0; | |
| 77 } | |
| 78 | |
| 79 bool can_begin_tracing(TraceSubscriber* subscriber) const { | |
| 80 return !is_tracing_ && | |
| 81 (subscriber_ == NULL || subscriber == subscriber_); | |
| 82 } | |
| 83 | |
| 84 // Methods for use by TraceMessageFilter. | |
| 85 | |
| 86 void AddFilter(TraceMessageFilter* filter); | |
| 87 void RemoveFilter(TraceMessageFilter* filter); | |
| 88 void OnTracingBegan(TraceSubscriber* subscriber); | |
| 89 void OnEndTracingAck(const std::vector<std::string>& known_categories); | |
| 90 void OnTraceDataCollected( | |
| 91 const scoped_refptr<base::RefCountedString>& events_str_ptr); | |
| 92 void OnTraceNotification(int notification); | |
| 93 void OnTraceBufferPercentFullReply(float percent_full); | |
| 94 | |
| 95 FilterMap filters_; | |
| 96 TraceSubscriber* subscriber_; | |
| 97 // Pending acks for EndTracingAsync: | |
| 98 int pending_end_ack_count_; | |
| 99 // Pending acks for GetTraceBufferPercentFullAsync: | |
| 100 int pending_bpf_ack_count_; | |
| 101 float maximum_bpf_; | |
| 102 bool is_tracing_; | |
| 103 bool is_get_categories_; | |
| 104 std::set<std::string> known_categories_; | |
| 105 std::vector<std::string> included_categories_; | |
| 106 std::vector<std::string> excluded_categories_; | |
| 107 std::string watch_category_; | |
| 108 std::string watch_name_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(TraceControllerImpl); | |
| 111 }; | |
| 112 | |
| 113 } // namespace content | |
| 114 | |
| 115 #endif // CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_ | |
| 116 | |
| OLD | NEW |