By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / trace_message_filter.cc
blobd37ce12760cf0cf56c4e68505529a5374e1bf341
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 #include "content/browser/trace_message_filter.h"
7 #include "components/tracing/tracing_messages.h"
8 #include "content/browser/trace_controller_impl.h"
10 namespace content {
12 TraceMessageFilter::TraceMessageFilter() :
13 has_child_(false),
14 is_awaiting_end_ack_(false),
15 is_awaiting_buffer_percent_full_ack_(false) {
18 void TraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
19 // Always on IO thread (BrowserMessageFilter guarantee).
20 BrowserMessageFilter::OnFilterAdded(channel);
23 void TraceMessageFilter::OnChannelClosing() {
24 // Always on IO thread (BrowserMessageFilter guarantee).
25 BrowserMessageFilter::OnChannelClosing();
27 if (has_child_) {
28 if (is_awaiting_end_ack_)
29 OnEndTracingAck(std::vector<std::string>());
31 if (is_awaiting_buffer_percent_full_ack_)
32 OnTraceBufferPercentFullReply(0.0f);
34 TraceControllerImpl::GetInstance()->RemoveFilter(this);
38 bool TraceMessageFilter::OnMessageReceived(const IPC::Message& message,
39 bool* message_was_ok) {
40 // Always on IO thread (BrowserMessageFilter guarantee).
41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP_EX(TraceMessageFilter, message, *message_was_ok)
43 IPC_MESSAGE_HANDLER(TracingHostMsg_ChildSupportsTracing,
44 OnChildSupportsTracing)
45 IPC_MESSAGE_HANDLER(TracingHostMsg_EndTracingAck, OnEndTracingAck)
46 IPC_MESSAGE_HANDLER(TracingHostMsg_TraceDataCollected,
47 OnTraceDataCollected)
48 IPC_MESSAGE_HANDLER(TracingHostMsg_TraceNotification,
49 OnTraceNotification)
50 IPC_MESSAGE_HANDLER(TracingHostMsg_TraceBufferPercentFullReply,
51 OnTraceBufferPercentFullReply)
52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP_EX()
54 return handled;
57 void TraceMessageFilter::SendBeginTracing(
58 const std::vector<std::string>& included_categories,
59 const std::vector<std::string>& excluded_categories) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61 Send(new TracingMsg_BeginTracing(included_categories,
62 excluded_categories,
63 base::TimeTicks::NowFromSystemTraceTime()));
66 void TraceMessageFilter::SendEndTracing() {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
68 DCHECK(!is_awaiting_end_ack_);
69 is_awaiting_end_ack_ = true;
70 Send(new TracingMsg_EndTracing);
73 void TraceMessageFilter::SendGetTraceBufferPercentFull() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 DCHECK(!is_awaiting_buffer_percent_full_ack_);
76 is_awaiting_buffer_percent_full_ack_ = true;
77 Send(new TracingMsg_GetTraceBufferPercentFull);
80 void TraceMessageFilter::SendSetWatchEvent(const std::string& category_name,
81 const std::string& event_name) {
82 Send(new TracingMsg_SetWatchEvent(category_name, event_name));
85 void TraceMessageFilter::SendCancelWatchEvent() {
86 Send(new TracingMsg_CancelWatchEvent);
89 TraceMessageFilter::~TraceMessageFilter() {}
91 void TraceMessageFilter::OnChildSupportsTracing() {
92 has_child_ = true;
93 TraceControllerImpl::GetInstance()->AddFilter(this);
96 void TraceMessageFilter::OnEndTracingAck(
97 const std::vector<std::string>& known_categories) {
98 // is_awaiting_end_ack_ should always be true here, but check in case the
99 // child process is compromised.
100 if (is_awaiting_end_ack_) {
101 is_awaiting_end_ack_ = false;
102 TraceControllerImpl::GetInstance()->OnEndTracingAck(known_categories);
103 } else {
104 NOTREACHED();
108 void TraceMessageFilter::OnTraceDataCollected(const std::string& data) {
109 scoped_refptr<base::RefCountedString> data_ptr(new base::RefCountedString());
110 data_ptr->data() = data;
111 TraceControllerImpl::GetInstance()->OnTraceDataCollected(data_ptr);
114 void TraceMessageFilter::OnTraceNotification(int notification) {
115 TraceControllerImpl::GetInstance()->OnTraceNotification(notification);
118 void TraceMessageFilter::OnTraceBufferPercentFullReply(float percent_full) {
119 if (is_awaiting_buffer_percent_full_ack_) {
120 is_awaiting_buffer_percent_full_ack_ = false;
121 TraceControllerImpl::GetInstance()->OnTraceBufferPercentFullReply(
122 percent_full);
123 } else {
124 NOTREACHED();
128 } // namespace content