By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / trace_controller_impl.h
blob2144b54c504b99b0b048380fab9aa627184511e3
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_TRACE_CONTROLLER_IMPL_H_
6 #define CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/debug/trace_event.h"
13 #include "base/lazy_instance.h"
14 #include "content/public/browser/trace_controller.h"
16 class CommandLine;
18 namespace content {
19 class TraceMessageFilter;
21 class TraceControllerImpl : public TraceController {
22 public:
23 static TraceControllerImpl* GetInstance();
25 // Called on the main thread of the browser process to initialize
26 // startup tracing.
27 void InitStartupTracing(const CommandLine& command_line);
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);
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);
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;
55 private:
56 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap;
58 friend struct base::DefaultLazyInstanceTraits<TraceControllerImpl>;
59 friend class TraceMessageFilter;
61 TraceControllerImpl();
62 virtual ~TraceControllerImpl();
64 bool is_tracing_enabled() const {
65 return can_end_tracing();
68 bool can_end_tracing() const {
69 return is_tracing_ && pending_end_ack_count_ == 0;
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;
79 bool can_begin_tracing(TraceSubscriber* subscriber) const {
80 return !is_tracing_ &&
81 (subscriber_ == NULL || subscriber == subscriber_);
84 // Methods for use by TraceMessageFilter.
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);
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_;
110 DISALLOW_COPY_AND_ASSIGN(TraceControllerImpl);
113 } // namespace content
115 #endif // CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_