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 | |
46 // Create an event for this browser instance that's set when logging is | 44 // Create an event for this browser instance that's set when logging is |
47 // enabled, so child processes can know when logging is enabled. | 45 // enabled, so child processes can know when logging is enabled. |
48 int browser_pid; | 46 int browser_pid; |
49 | 47 |
50 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 48 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
51 std::wstring process_type = | 49 std::wstring process_type = |
52 parsed_command_line.GetSwitchValue(switches::kProcessType); | 50 parsed_command_line.GetSwitchValue(switches::kProcessType); |
53 if (process_type.empty()) { | 51 if (process_type.empty()) { |
54 browser_pid = GetCurrentProcessId(); | 52 browser_pid = GetCurrentProcessId(); |
55 } else { | 53 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
83 watcher_.StopWatching(); | 81 watcher_.StopWatching(); |
84 watcher_.StartWatching( | 82 watcher_.StartWatching( |
85 enabled ? logging_event_on_ : logging_event_off_, this); | 83 enabled ? logging_event_on_ : logging_event_off_, this); |
86 } | 84 } |
87 | 85 |
88 void Logging::OnObjectSignaled(HANDLE object) { | 86 void Logging::OnObjectSignaled(HANDLE object) { |
89 enabled_ = object == logging_event_on_; | 87 enabled_ = object == logging_event_on_; |
90 RegisterWaitForEvent(!enabled_); | 88 RegisterWaitForEvent(!enabled_); |
91 } | 89 } |
92 | 90 |
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 | |
103 std::wstring Logging::GetEventName(bool enabled) { | 91 std::wstring Logging::GetEventName(bool enabled) { |
104 return current()->GetEventName(GetCurrentProcessId(), enabled); | 92 return Logging::current()->GetEventName(GetCurrentProcessId(), enabled); |
105 } | 93 } |
106 | 94 |
107 std::wstring Logging::GetEventName(int browser_pid, bool enabled) { | 95 std::wstring Logging::GetEventName(int browser_pid, bool enabled) { |
108 std::wstring result = StringPrintf(kLoggingEventName, browser_pid); | 96 std::wstring result = StringPrintf(kLoggingEventName, browser_pid); |
109 result += enabled ? L"on" : L"off"; | 97 result += enabled ? L"on" : L"off"; |
110 return result; | 98 return result; |
111 } | 99 } |
112 | 100 |
113 void Logging::SetConsumer(Consumer* consumer) { | 101 void Logging::SetConsumer(Consumer* consumer) { |
114 consumer_ = consumer; | 102 consumer_ = consumer; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 GenerateLogData(channel_id, message, &data); | 181 GenerateLogData(channel_id, message, &data); |
194 | 182 |
195 if (MessageLoop::current() == main_thread_) { | 183 if (MessageLoop::current() == main_thread_) { |
196 Log(data); | 184 Log(data); |
197 } else { | 185 } else { |
198 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( | 186 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( |
199 this, &Logging::Log, data)); | 187 this, &Logging::Log, data)); |
200 } | 188 } |
201 } | 189 } |
202 | 190 |
| 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 (current()->log_function_mapping_[message_class] != NULL) { | 207 if (g_log_function_mapping[message_class] != NULL) { |
208 current()->log_function_mapping_[message_class](type, name, message, params)
; | 208 g_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 |