OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/ipc_logging.h" | 5 #include "chrome/common/ipc_logging.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 const int kLogSendDelayMs = 100; | 34 const int kLogSendDelayMs = 100; |
35 | 35 |
36 Logging::Logging() | 36 Logging::Logging() |
37 : logging_event_on_(NULL), | 37 : logging_event_on_(NULL), |
38 logging_event_off_(NULL), | 38 logging_event_off_(NULL), |
39 enabled_(false), | 39 enabled_(false), |
40 sender_(NULL), | 40 sender_(NULL), |
41 consumer_(NULL), | 41 consumer_(NULL), |
42 queue_invoke_later_pending_(false), | 42 queue_invoke_later_pending_(false), |
43 main_thread_(MessageLoop::current()) { | 43 main_thread_(MessageLoop::current()) { |
| 44 memset(log_function_mapping_, sizeof(log_function_mapping_), 0); |
| 45 |
44 // Create an event for this browser instance that's set when logging is | 46 // Create an event for this browser instance that's set when logging is |
45 // enabled, so child processes can know when logging is enabled. | 47 // enabled, so child processes can know when logging is enabled. |
46 int browser_pid; | 48 int browser_pid; |
47 | 49 |
48 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 50 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
49 std::wstring process_type = | 51 std::wstring process_type = |
50 parsed_command_line.GetSwitchValue(switches::kProcessType); | 52 parsed_command_line.GetSwitchValue(switches::kProcessType); |
51 if (process_type.empty()) { | 53 if (process_type.empty()) { |
52 browser_pid = GetCurrentProcessId(); | 54 browser_pid = GetCurrentProcessId(); |
53 } else { | 55 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
81 watcher_.StopWatching(); | 83 watcher_.StopWatching(); |
82 watcher_.StartWatching( | 84 watcher_.StartWatching( |
83 enabled ? logging_event_on_ : logging_event_off_, this); | 85 enabled ? logging_event_on_ : logging_event_off_, this); |
84 } | 86 } |
85 | 87 |
86 void Logging::OnObjectSignaled(HANDLE object) { | 88 void Logging::OnObjectSignaled(HANDLE object) { |
87 enabled_ = object == logging_event_on_; | 89 enabled_ = object == logging_event_on_; |
88 RegisterWaitForEvent(!enabled_); | 90 RegisterWaitForEvent(!enabled_); |
89 } | 91 } |
90 | 92 |
| 93 void Logging::RegisterMessageLogger(int msg_start, LogFunction* func) { |
| 94 int msg_class = msg_start >> 12; |
| 95 if (msg_class > arraysize(log_function_mapping_)) { |
| 96 NOTREACHED(); |
| 97 return; |
| 98 } |
| 99 |
| 100 log_function_mapping_[msg_class] = func; |
| 101 } |
| 102 |
91 std::wstring Logging::GetEventName(bool enabled) { | 103 std::wstring Logging::GetEventName(bool enabled) { |
92 return Logging::current()->GetEventName(GetCurrentProcessId(), enabled); | 104 return current()->GetEventName(GetCurrentProcessId(), enabled); |
93 } | 105 } |
94 | 106 |
95 std::wstring Logging::GetEventName(int browser_pid, bool enabled) { | 107 std::wstring Logging::GetEventName(int browser_pid, bool enabled) { |
96 std::wstring result = StringPrintf(kLoggingEventName, browser_pid); | 108 std::wstring result = StringPrintf(kLoggingEventName, browser_pid); |
97 result += enabled ? L"on" : L"off"; | 109 result += enabled ? L"on" : L"off"; |
98 return result; | 110 return result; |
99 } | 111 } |
100 | 112 |
101 void Logging::SetConsumer(Consumer* consumer) { | 113 void Logging::SetConsumer(Consumer* consumer) { |
102 consumer_ = consumer; | 114 consumer_ = consumer; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 GenerateLogData(channel_id, message, &data); | 193 GenerateLogData(channel_id, message, &data); |
182 | 194 |
183 if (MessageLoop::current() == main_thread_) { | 195 if (MessageLoop::current() == main_thread_) { |
184 Log(data); | 196 Log(data); |
185 } else { | 197 } else { |
186 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 198 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( |
187 this, &Logging::Log, data)); | 199 this, &Logging::Log, data)); |
188 } | 200 } |
189 } | 201 } |
190 | 202 |
191 // static | |
192 LogFunction* g_log_function_mapping[16]; | |
193 void RegisterMessageLogger(int msg_start, LogFunction* func) { | |
194 int msg_class = msg_start >> 12; | |
195 if (msg_class > arraysize(g_log_function_mapping)) { | |
196 NOTREACHED(); | |
197 return; | |
198 } | |
199 | |
200 g_log_function_mapping[msg_class] = func; | |
201 } | |
202 | |
203 void Logging::GetMessageText(uint16 type, std::wstring* name, | 203 void Logging::GetMessageText(uint16 type, std::wstring* name, |
204 const Message* message, | 204 const Message* message, |
205 std::wstring* params) { | 205 std::wstring* params) { |
206 int message_class = type >> 12; | 206 int message_class = type >> 12; |
207 if (g_log_function_mapping[message_class] != NULL) { | 207 if (current()->log_function_mapping_[message_class] != NULL) { |
208 g_log_function_mapping[message_class](type, name, message, params); | 208 current()->log_function_mapping_[message_class](type, name, message, params)
; |
209 } else { | 209 } else { |
210 DLOG(INFO) << "No logger function associated with message class " << | 210 DLOG(INFO) << "No logger function associated with message class " << |
211 message_class; | 211 message_class; |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 void Logging::Log(const LogData& data) { | 215 void Logging::Log(const LogData& data) { |
216 if (consumer_) { | 216 if (consumer_) { |
217 // We're in the browser process. | 217 // We're in the browser process. |
218 consumer_->Log(data); | 218 consumer_->Log(data); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 data->sent = message.sent_time(); | 262 data->sent = message.sent_time(); |
263 data->receive = message.received_time(); | 263 data->receive = message.received_time(); |
264 data->dispatch = Time::Now().ToInternalValue(); | 264 data->dispatch = Time::Now().ToInternalValue(); |
265 data->params = params; | 265 data->params = params; |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 } | 269 } |
270 | 270 |
271 #endif // IPC_MESSAGE_LOG_ENABLED | 271 #endif // IPC_MESSAGE_LOG_ENABLED |
OLD | NEW |