OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/tracing/child_trace_message_filter.h" | 5 #include "components/tracing/child_trace_message_filter.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "components/tracing/tracing_messages.h" | 9 #include "components/tracing/tracing_messages.h" |
10 #include "ipc/ipc_channel.h" | 10 #include "ipc/ipc_channel.h" |
11 | 11 |
12 using base::debug::TraceLog; | 12 using base::debug::TraceLog; |
13 | 13 |
14 namespace tracing { | 14 namespace tracing { |
15 | 15 |
16 ChildTraceMessageFilter::ChildTraceMessageFilter( | 16 ChildTraceMessageFilter::ChildTraceMessageFilter( |
17 base::MessageLoopProxy* ipc_message_loop) | 17 base::MessageLoopProxy* ipc_message_loop) |
18 : channel_(NULL), | 18 : sender_(NULL), |
19 ipc_message_loop_(ipc_message_loop) {} | 19 ipc_message_loop_(ipc_message_loop) {} |
20 | 20 |
21 void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 21 void ChildTraceMessageFilter::OnFilterAdded(IPC::Sender* sender) { |
22 channel_ = channel; | 22 sender_ = sender; |
23 channel_->Send(new TracingHostMsg_ChildSupportsTracing()); | 23 sender_->Send(new TracingHostMsg_ChildSupportsTracing()); |
24 } | 24 } |
25 | 25 |
26 void ChildTraceMessageFilter::OnFilterRemoved() { | 26 void ChildTraceMessageFilter::OnFilterRemoved() { |
27 channel_ = NULL; | 27 sender_ = NULL; |
28 } | 28 } |
29 | 29 |
30 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { | 30 bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { |
31 bool handled = true; | 31 bool handled = true; |
32 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) | 32 IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) |
33 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing) | 33 IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing) |
34 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing) | 34 IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing) |
35 IPC_MESSAGE_HANDLER(TracingMsg_EnableMonitoring, OnEnableMonitoring) | 35 IPC_MESSAGE_HANDLER(TracingMsg_EnableMonitoring, OnEnableMonitoring) |
36 IPC_MESSAGE_HANDLER(TracingMsg_DisableMonitoring, OnDisableMonitoring) | 36 IPC_MESSAGE_HANDLER(TracingMsg_DisableMonitoring, OnDisableMonitoring) |
37 IPC_MESSAGE_HANDLER(TracingMsg_CaptureMonitoringSnapshot, | 37 IPC_MESSAGE_HANDLER(TracingMsg_CaptureMonitoringSnapshot, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // CaptureMonitoringSnapshotAck below. We are already on the IO thread, | 98 // CaptureMonitoringSnapshotAck below. We are already on the IO thread, |
99 // so the OnMonitoringTraceDataCollected calls will not be deferred. | 99 // so the OnMonitoringTraceDataCollected calls will not be deferred. |
100 TraceLog::GetInstance()->FlushButLeaveBufferIntact( | 100 TraceLog::GetInstance()->FlushButLeaveBufferIntact( |
101 base::Bind(&ChildTraceMessageFilter::OnMonitoringTraceDataCollected, | 101 base::Bind(&ChildTraceMessageFilter::OnMonitoringTraceDataCollected, |
102 this)); | 102 this)); |
103 } | 103 } |
104 | 104 |
105 void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { | 105 void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { |
106 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 106 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
107 | 107 |
108 channel_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf)); | 108 sender_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf)); |
109 } | 109 } |
110 | 110 |
111 void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, | 111 void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, |
112 const std::string& event_name) { | 112 const std::string& event_name) { |
113 TraceLog::GetInstance()->SetWatchEvent( | 113 TraceLog::GetInstance()->SetWatchEvent( |
114 category_name, event_name, | 114 category_name, event_name, |
115 base::Bind(&ChildTraceMessageFilter::OnWatchEventMatched, this)); | 115 base::Bind(&ChildTraceMessageFilter::OnWatchEventMatched, this)); |
116 } | 116 } |
117 | 117 |
118 void ChildTraceMessageFilter::OnCancelWatchEvent() { | 118 void ChildTraceMessageFilter::OnCancelWatchEvent() { |
119 TraceLog::GetInstance()->CancelWatchEvent(); | 119 TraceLog::GetInstance()->CancelWatchEvent(); |
120 } | 120 } |
121 | 121 |
122 void ChildTraceMessageFilter::OnWatchEventMatched() { | 122 void ChildTraceMessageFilter::OnWatchEventMatched() { |
123 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 123 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
124 ipc_message_loop_->PostTask(FROM_HERE, | 124 ipc_message_loop_->PostTask(FROM_HERE, |
125 base::Bind(&ChildTraceMessageFilter::OnWatchEventMatched, this)); | 125 base::Bind(&ChildTraceMessageFilter::OnWatchEventMatched, this)); |
126 return; | 126 return; |
127 } | 127 } |
128 channel_->Send(new TracingHostMsg_WatchEventMatched); | 128 sender_->Send(new TracingHostMsg_WatchEventMatched); |
129 } | 129 } |
130 | 130 |
131 void ChildTraceMessageFilter::OnTraceDataCollected( | 131 void ChildTraceMessageFilter::OnTraceDataCollected( |
132 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 132 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
133 bool has_more_events) { | 133 bool has_more_events) { |
134 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 134 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
135 ipc_message_loop_->PostTask(FROM_HERE, | 135 ipc_message_loop_->PostTask(FROM_HERE, |
136 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this, | 136 base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this, |
137 events_str_ptr, has_more_events)); | 137 events_str_ptr, has_more_events)); |
138 return; | 138 return; |
139 } | 139 } |
140 if (events_str_ptr->data().size()) { | 140 if (events_str_ptr->data().size()) { |
141 channel_->Send(new TracingHostMsg_TraceDataCollected( | 141 sender_->Send(new TracingHostMsg_TraceDataCollected( |
142 events_str_ptr->data())); | 142 events_str_ptr->data())); |
143 } | 143 } |
144 if (!has_more_events) { | 144 if (!has_more_events) { |
145 std::vector<std::string> category_groups; | 145 std::vector<std::string> category_groups; |
146 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups); | 146 TraceLog::GetInstance()->GetKnownCategoryGroups(&category_groups); |
147 channel_->Send(new TracingHostMsg_EndTracingAck(category_groups)); | 147 sender_->Send(new TracingHostMsg_EndTracingAck(category_groups)); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void ChildTraceMessageFilter::OnMonitoringTraceDataCollected( | 151 void ChildTraceMessageFilter::OnMonitoringTraceDataCollected( |
152 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 152 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
153 bool has_more_events) { | 153 bool has_more_events) { |
154 if (!ipc_message_loop_->BelongsToCurrentThread()) { | 154 if (!ipc_message_loop_->BelongsToCurrentThread()) { |
155 ipc_message_loop_->PostTask(FROM_HERE, | 155 ipc_message_loop_->PostTask(FROM_HERE, |
156 base::Bind(&ChildTraceMessageFilter:: | 156 base::Bind(&ChildTraceMessageFilter:: |
157 OnMonitoringTraceDataCollected, | 157 OnMonitoringTraceDataCollected, |
158 this, | 158 this, |
159 events_str_ptr, | 159 events_str_ptr, |
160 has_more_events)); | 160 has_more_events)); |
161 return; | 161 return; |
162 } | 162 } |
163 channel_->Send(new TracingHostMsg_MonitoringTraceDataCollected( | 163 sender_->Send(new TracingHostMsg_MonitoringTraceDataCollected( |
164 events_str_ptr->data())); | 164 events_str_ptr->data())); |
165 | 165 |
166 if (!has_more_events) | 166 if (!has_more_events) |
167 channel_->Send(new TracingHostMsg_CaptureMonitoringSnapshotAck()); | 167 sender_->Send(new TracingHostMsg_CaptureMonitoringSnapshotAck()); |
168 } | 168 } |
169 | 169 |
170 } // namespace tracing | 170 } // namespace tracing |
OLD | NEW |