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_TRACING_TRACE_CONTROLLER_IMPL_H_ | |
6 #define CONTENT_BROWSER_TRACING_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 // TraceController implementation: | |
26 virtual bool BeginTracing(TraceSubscriber* subscriber, | |
27 const std::string& category_patterns, | |
28 base::debug::TraceLog::Options options) OVERRIDE; | |
29 virtual bool EndTracingAsync(TraceSubscriber* subscriber) OVERRIDE; | |
30 virtual bool GetTraceBufferPercentFullAsync( | |
31 TraceSubscriber* subscriber) OVERRIDE; | |
32 virtual bool SetWatchEvent(TraceSubscriber* subscriber, | |
33 const std::string& category_name, | |
34 const std::string& event_name) OVERRIDE; | |
35 virtual bool CancelWatchEvent(TraceSubscriber* subscriber) OVERRIDE; | |
36 virtual void CancelSubscriber(TraceSubscriber* subscriber) OVERRIDE; | |
37 virtual bool GetKnownCategoryGroupsAsync(TraceSubscriber* subscriber) | |
38 OVERRIDE; | |
39 | |
40 private: | |
41 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; | |
42 | |
43 friend struct base::DefaultLazyInstanceTraits<TraceControllerImpl>; | |
44 friend class TraceMessageFilter; | |
45 | |
46 TraceControllerImpl(); | |
47 virtual ~TraceControllerImpl(); | |
48 | |
49 bool is_tracing_enabled() const { | |
50 return can_end_tracing(); | |
51 } | |
52 | |
53 bool can_end_tracing() const { | |
54 return is_tracing_ && pending_end_ack_count_ == 0; | |
55 } | |
56 | |
57 // Can get Buffer Percent Full | |
58 bool can_get_buffer_percent_full() const { | |
59 return is_tracing_ && | |
60 pending_end_ack_count_ == 0 && | |
61 pending_bpf_ack_count_ == 0; | |
62 } | |
63 | |
64 bool can_begin_tracing(TraceSubscriber* subscriber) const { | |
65 return !is_tracing_ && | |
66 (subscriber_ == NULL || subscriber == subscriber_); | |
67 } | |
68 | |
69 // Methods for use by TraceMessageFilter. | |
70 | |
71 void AddFilter(TraceMessageFilter* filter); | |
72 void RemoveFilter(TraceMessageFilter* filter); | |
73 void OnTracingBegan(TraceSubscriber* subscriber); | |
74 void OnEndTracingAck(const std::vector<std::string>& known_category_groups); | |
75 void OnTraceDataCollected( | |
76 const scoped_refptr<base::RefCountedString>& events_str_ptr); | |
77 void OnTraceNotification(int notification); | |
78 void OnTraceBufferPercentFullReply(float percent_full); | |
79 | |
80 // Callback of TraceLog::Flush() for the local trace. | |
81 void OnLocalTraceDataCollected( | |
82 const scoped_refptr<base::RefCountedString>& events_str_ptr, | |
83 bool has_more_events); | |
84 | |
85 FilterMap filters_; | |
86 TraceSubscriber* subscriber_; | |
87 // Pending acks for EndTracingAsync: | |
88 int pending_end_ack_count_; | |
89 // Pending acks for GetTraceBufferPercentFullAsync: | |
90 int pending_bpf_ack_count_; | |
91 float maximum_bpf_; | |
92 bool is_tracing_; | |
93 bool is_get_category_groups_; | |
94 std::set<std::string> known_category_groups_; | |
95 std::string watch_category_; | |
96 std::string watch_name_; | |
97 base::debug::TraceLog::Options trace_options_; | |
98 base::debug::CategoryFilter category_filter_; | |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(TraceControllerImpl); | |
101 }; | |
102 | |
103 } // namespace content | |
104 | |
105 #endif // CONTENT_BROWSER_TRACING_TRACE_CONTROLLER_IMPL_H_ | |
OLD | NEW |