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.
5 #ifndef CONTENT_BROWSER_TRACING_TRACE_CONTROLLER_IMPL_H_
6 #define CONTENT_BROWSER_TRACING_TRACE_CONTROLLER_IMPL_H_
12 #include "base/debug/trace_event.h"
13 #include "base/lazy_instance.h"
14 #include "content/public/browser/trace_controller.h"
19 class TraceMessageFilter
;
21 class TraceControllerImpl
: public TraceController
{
23 static TraceControllerImpl
* GetInstance();
25 // Called on the main thread of the browser process to initialize
27 void InitStartupTracing(const CommandLine
& command_line
);
29 // TraceController implementation:
30 virtual bool BeginTracing(TraceSubscriber
* subscriber
,
31 const std::string
& category_patterns
,
32 base::debug::TraceLog::Options options
) OVERRIDE
;
33 virtual bool EndTracingAsync(TraceSubscriber
* subscriber
) OVERRIDE
;
34 virtual bool GetTraceBufferPercentFullAsync(
35 TraceSubscriber
* subscriber
) OVERRIDE
;
36 virtual bool SetWatchEvent(TraceSubscriber
* subscriber
,
37 const std::string
& category_name
,
38 const std::string
& event_name
) OVERRIDE
;
39 virtual bool CancelWatchEvent(TraceSubscriber
* subscriber
) OVERRIDE
;
40 virtual void CancelSubscriber(TraceSubscriber
* subscriber
) OVERRIDE
;
41 virtual bool GetKnownCategoryGroupsAsync(TraceSubscriber
* subscriber
)
45 typedef std::set
<scoped_refptr
<TraceMessageFilter
> > FilterMap
;
47 friend struct base::DefaultLazyInstanceTraits
<TraceControllerImpl
>;
48 friend class TraceMessageFilter
;
50 TraceControllerImpl();
51 virtual ~TraceControllerImpl();
53 bool is_tracing_enabled() const {
54 return can_end_tracing();
57 bool can_end_tracing() const {
58 return is_tracing_
&& pending_end_ack_count_
== 0;
61 // Can get Buffer Percent Full
62 bool can_get_buffer_percent_full() const {
64 pending_end_ack_count_
== 0 &&
65 pending_bpf_ack_count_
== 0;
68 bool can_begin_tracing(TraceSubscriber
* subscriber
) const {
69 return !is_tracing_
&&
70 (subscriber_
== NULL
|| subscriber
== subscriber_
);
73 // Methods for use by TraceMessageFilter.
75 void AddFilter(TraceMessageFilter
* filter
);
76 void RemoveFilter(TraceMessageFilter
* filter
);
77 void OnTracingBegan(TraceSubscriber
* subscriber
);
78 void OnEndTracingAck(const std::vector
<std::string
>& known_category_groups
);
79 void OnTraceDataCollected(
80 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
);
81 void OnTraceNotification(int notification
);
82 void OnTraceBufferPercentFullReply(float percent_full
);
84 // Callback of TraceLog::Flush() for the local trace.
85 void OnLocalTraceDataCollected(
86 const scoped_refptr
<base::RefCountedString
>& events_str_ptr
,
87 bool has_more_events
);
90 TraceSubscriber
* subscriber_
;
91 // Pending acks for EndTracingAsync:
92 int pending_end_ack_count_
;
93 // Pending acks for GetTraceBufferPercentFullAsync:
94 int pending_bpf_ack_count_
;
97 bool is_get_category_groups_
;
98 std::set
<std::string
> known_category_groups_
;
99 std::string watch_category_
;
100 std::string watch_name_
;
101 base::debug::TraceLog::Options trace_options_
;
102 base::debug::CategoryFilter category_filter_
;
104 DISALLOW_COPY_AND_ASSIGN(TraceControllerImpl
);
107 } // namespace content
109 #endif // CONTENT_BROWSER_TRACING_TRACE_CONTROLLER_IMPL_H_