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 "content/browser/trace_message_filter.h" | 5 #include "content/browser/trace_message_filter.h" |
6 | 6 |
7 #include "content/browser/trace_controller_impl.h" | 7 #include "content/browser/trace_controller_impl.h" |
8 #include "content/common/child_process_messages.h" | 8 #include "content/common/child_process_messages.h" |
9 | 9 |
10 using content::BrowserMessageFilter; | 10 using content::BrowserMessageFilter; |
(...skipping 29 matching lines...) Expand all Loading... |
40 bool TraceMessageFilter::OnMessageReceived(const IPC::Message& message, | 40 bool TraceMessageFilter::OnMessageReceived(const IPC::Message& message, |
41 bool* message_was_ok) { | 41 bool* message_was_ok) { |
42 // Always on IO thread (BrowserMessageFilter guarantee). | 42 // Always on IO thread (BrowserMessageFilter guarantee). |
43 bool handled = true; | 43 bool handled = true; |
44 IPC_BEGIN_MESSAGE_MAP_EX(TraceMessageFilter, message, *message_was_ok) | 44 IPC_BEGIN_MESSAGE_MAP_EX(TraceMessageFilter, message, *message_was_ok) |
45 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildSupportsTracing, | 45 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildSupportsTracing, |
46 OnChildSupportsTracing) | 46 OnChildSupportsTracing) |
47 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_EndTracingAck, OnEndTracingAck) | 47 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_EndTracingAck, OnEndTracingAck) |
48 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceDataCollected, | 48 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceDataCollected, |
49 OnTraceDataCollected) | 49 OnTraceDataCollected) |
50 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceBufferFull, | 50 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceNotification, |
51 OnTraceBufferFull) | 51 OnTraceNotification) |
52 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceBufferPercentFullReply, | 52 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_TraceBufferPercentFullReply, |
53 OnTraceBufferPercentFullReply) | 53 OnTraceBufferPercentFullReply) |
54 IPC_MESSAGE_UNHANDLED(handled = false) | 54 IPC_MESSAGE_UNHANDLED(handled = false) |
55 IPC_END_MESSAGE_MAP_EX() | 55 IPC_END_MESSAGE_MAP_EX() |
56 return handled; | 56 return handled; |
57 } | 57 } |
58 | 58 |
59 void TraceMessageFilter::SendBeginTracing( | 59 void TraceMessageFilter::SendBeginTracing( |
60 const std::vector<std::string>& included_categories, | 60 const std::vector<std::string>& included_categories, |
61 const std::vector<std::string>& excluded_categories) { | 61 const std::vector<std::string>& excluded_categories) { |
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
63 Send(new ChildProcessMsg_BeginTracing(included_categories, | 63 Send(new ChildProcessMsg_BeginTracing(included_categories, |
64 excluded_categories)); | 64 excluded_categories)); |
65 } | 65 } |
66 | 66 |
67 void TraceMessageFilter::SendEndTracing() { | 67 void TraceMessageFilter::SendEndTracing() { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
69 DCHECK(!is_awaiting_end_ack_); | 69 DCHECK(!is_awaiting_end_ack_); |
70 is_awaiting_end_ack_ = true; | 70 is_awaiting_end_ack_ = true; |
71 Send(new ChildProcessMsg_EndTracing); | 71 Send(new ChildProcessMsg_EndTracing); |
72 } | 72 } |
73 | 73 |
74 void TraceMessageFilter::SendGetTraceBufferPercentFull() { | 74 void TraceMessageFilter::SendGetTraceBufferPercentFull() { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 DCHECK(!is_awaiting_buffer_percent_full_ack_); | 76 DCHECK(!is_awaiting_buffer_percent_full_ack_); |
77 is_awaiting_buffer_percent_full_ack_ = true; | 77 is_awaiting_buffer_percent_full_ack_ = true; |
78 Send(new ChildProcessMsg_GetTraceBufferPercentFull); | 78 Send(new ChildProcessMsg_GetTraceBufferPercentFull); |
79 } | 79 } |
80 | 80 |
| 81 void TraceMessageFilter::SendSetWatchEvent(const std::string& category_name, |
| 82 const std::string& event_name, |
| 83 int num_occurrences) { |
| 84 Send(new ChildProcessMsg_SetWatchEvent(category_name, |
| 85 event_name, |
| 86 num_occurrences)); |
| 87 } |
| 88 |
| 89 void TraceMessageFilter::SendCancelWatchEvent() { |
| 90 Send(new ChildProcessMsg_CancelWatchEvent); |
| 91 } |
| 92 |
81 TraceMessageFilter::~TraceMessageFilter() {} | 93 TraceMessageFilter::~TraceMessageFilter() {} |
82 | 94 |
83 void TraceMessageFilter::OnChildSupportsTracing() { | 95 void TraceMessageFilter::OnChildSupportsTracing() { |
84 has_child_ = true; | 96 has_child_ = true; |
85 TraceControllerImpl::GetInstance()->AddFilter(this); | 97 TraceControllerImpl::GetInstance()->AddFilter(this); |
86 } | 98 } |
87 | 99 |
88 void TraceMessageFilter::OnEndTracingAck( | 100 void TraceMessageFilter::OnEndTracingAck( |
89 const std::vector<std::string>& known_categories) { | 101 const std::vector<std::string>& known_categories) { |
90 // is_awaiting_end_ack_ should always be true here, but check in case the | 102 // is_awaiting_end_ack_ should always be true here, but check in case the |
91 // child process is compromised. | 103 // child process is compromised. |
92 if (is_awaiting_end_ack_) { | 104 if (is_awaiting_end_ack_) { |
93 is_awaiting_end_ack_ = false; | 105 is_awaiting_end_ack_ = false; |
94 TraceControllerImpl::GetInstance()->OnEndTracingAck(known_categories); | 106 TraceControllerImpl::GetInstance()->OnEndTracingAck(known_categories); |
95 } else { | 107 } else { |
96 NOTREACHED(); | 108 NOTREACHED(); |
97 } | 109 } |
98 } | 110 } |
99 | 111 |
100 void TraceMessageFilter::OnTraceDataCollected(const std::string& data) { | 112 void TraceMessageFilter::OnTraceDataCollected(const std::string& data) { |
101 scoped_refptr<base::RefCountedString> data_ptr(new base::RefCountedString()); | 113 scoped_refptr<base::RefCountedString> data_ptr(new base::RefCountedString()); |
102 data_ptr->data() = data; | 114 data_ptr->data() = data; |
103 TraceControllerImpl::GetInstance()->OnTraceDataCollected(data_ptr); | 115 TraceControllerImpl::GetInstance()->OnTraceDataCollected(data_ptr); |
104 } | 116 } |
105 | 117 |
106 void TraceMessageFilter::OnTraceBufferFull() { | 118 void TraceMessageFilter::OnTraceNotification(int notification) { |
107 TraceControllerImpl::GetInstance()->OnTraceBufferFull(); | 119 TraceControllerImpl::GetInstance()->OnTraceNotification(notification); |
108 } | 120 } |
109 | 121 |
110 void TraceMessageFilter::OnTraceBufferPercentFullReply(float percent_full) { | 122 void TraceMessageFilter::OnTraceBufferPercentFullReply(float percent_full) { |
111 if (is_awaiting_buffer_percent_full_ack_) { | 123 if (is_awaiting_buffer_percent_full_ack_) { |
112 is_awaiting_buffer_percent_full_ack_ = false; | 124 is_awaiting_buffer_percent_full_ack_ = false; |
113 TraceControllerImpl::GetInstance()->OnTraceBufferPercentFullReply( | 125 TraceControllerImpl::GetInstance()->OnTraceBufferPercentFullReply( |
114 percent_full); | 126 percent_full); |
115 } else { | 127 } else { |
116 NOTREACHED(); | 128 NOTREACHED(); |
117 } | 129 } |
118 } | 130 } |
119 | 131 |
OLD | NEW |