Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: content/browser/trace_message_filter.cc

Issue 12149003: Move tracing code in content\browser to content\browser\tracing now that there's a separate directo… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix android and sync Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/trace_message_filter.h ('k') | content/browser/trace_subscriber_stdio.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "content/browser/trace_message_filter.h"
6
7 #include "components/tracing/tracing_messages.h"
8 #include "content/browser/trace_controller_impl.h"
9
10 namespace content {
11
12 TraceMessageFilter::TraceMessageFilter() :
13 has_child_(false),
14 is_awaiting_end_ack_(false),
15 is_awaiting_buffer_percent_full_ack_(false) {
16 }
17
18 void TraceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
19 // Always on IO thread (BrowserMessageFilter guarantee).
20 BrowserMessageFilter::OnFilterAdded(channel);
21 }
22
23 void TraceMessageFilter::OnChannelClosing() {
24 // Always on IO thread (BrowserMessageFilter guarantee).
25 BrowserMessageFilter::OnChannelClosing();
26
27 if (has_child_) {
28 if (is_awaiting_end_ack_)
29 OnEndTracingAck(std::vector<std::string>());
30
31 if (is_awaiting_buffer_percent_full_ack_)
32 OnTraceBufferPercentFullReply(0.0f);
33
34 TraceControllerImpl::GetInstance()->RemoveFilter(this);
35 }
36 }
37
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;
55 }
56
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()));
64 }
65
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);
71 }
72
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);
78 }
79
80 void TraceMessageFilter::SendSetWatchEvent(const std::string& category_name,
81 const std::string& event_name) {
82 Send(new TracingMsg_SetWatchEvent(category_name, event_name));
83 }
84
85 void TraceMessageFilter::SendCancelWatchEvent() {
86 Send(new TracingMsg_CancelWatchEvent);
87 }
88
89 TraceMessageFilter::~TraceMessageFilter() {}
90
91 void TraceMessageFilter::OnChildSupportsTracing() {
92 has_child_ = true;
93 TraceControllerImpl::GetInstance()->AddFilter(this);
94 }
95
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();
105 }
106 }
107
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);
112 }
113
114 void TraceMessageFilter::OnTraceNotification(int notification) {
115 TraceControllerImpl::GetInstance()->OnTraceNotification(notification);
116 }
117
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();
125 }
126 }
127
128 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/trace_message_filter.h ('k') | content/browser/trace_subscriber_stdio.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698