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 "ipc/ipc_logging.h" | 5 #include "ipc/ipc_logging.h" |
6 | 6 |
7 #ifdef IPC_MESSAGE_LOG_ENABLED | 7 #ifdef IPC_MESSAGE_LOG_ENABLED |
8 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 8 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 // We use a pointer to the function table to avoid any linker dependencies on | 39 // We use a pointer to the function table to avoid any linker dependencies on |
40 // all the traits used as IPC message parameters. | 40 // all the traits used as IPC message parameters. |
41 LogFunctionMap* Logging::log_function_map_; | 41 LogFunctionMap* Logging::log_function_map_; |
42 | 42 |
43 Logging::Logging() | 43 Logging::Logging() |
44 : enabled_(false), | 44 : enabled_(false), |
45 enabled_on_stderr_(false), | 45 enabled_on_stderr_(false), |
46 enabled_color_(false), | 46 enabled_color_(false), |
47 queue_invoke_later_pending_(false), | 47 queue_invoke_later_pending_(false), |
48 sender_(NULL), | 48 sender_(NULL), |
49 main_thread_(MessageLoop::current()), | 49 main_thread_(base::MessageLoop::current()), |
50 consumer_(NULL) { | 50 consumer_(NULL) { |
51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
52 // getenv triggers an unsafe warning. Simply check how big of a buffer | 52 // getenv triggers an unsafe warning. Simply check how big of a buffer |
53 // would be needed to fetch the value to see if the enviornment variable is | 53 // would be needed to fetch the value to see if the enviornment variable is |
54 // set. | 54 // set. |
55 size_t requiredSize = 0; | 55 size_t requiredSize = 0; |
56 getenv_s(&requiredSize, NULL, 0, "CHROME_IPC_LOGGING"); | 56 getenv_s(&requiredSize, NULL, 0, "CHROME_IPC_LOGGING"); |
57 bool logging_env_var_set = (requiredSize != 0); | 57 bool logging_env_var_set = (requiredSize != 0); |
58 if (requiredSize <= 6) { | 58 if (requiredSize <= 6) { |
59 char buffer[6]; | 59 char buffer[6]; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const std::string& channel_id) { | 152 const std::string& channel_id) { |
153 if (!Enabled() || | 153 if (!Enabled() || |
154 !message.sent_time() || | 154 !message.sent_time() || |
155 !message.received_time() || | 155 !message.received_time() || |
156 message.dont_log()) | 156 message.dont_log()) |
157 return; | 157 return; |
158 | 158 |
159 LogData data; | 159 LogData data; |
160 GenerateLogData(channel_id, message, &data, true); | 160 GenerateLogData(channel_id, message, &data, true); |
161 | 161 |
162 if (MessageLoop::current() == main_thread_) { | 162 if (base::MessageLoop::current() == main_thread_) { |
163 Log(data); | 163 Log(data); |
164 } else { | 164 } else { |
165 main_thread_->PostTask( | 165 main_thread_->PostTask( |
166 FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data)); | 166 FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data)); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void Logging::GetMessageText(uint32 type, std::string* name, | 170 void Logging::GetMessageText(uint32 type, std::string* name, |
171 const Message* message, | 171 const Message* message, |
172 std::string* params) { | 172 std::string* params) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void Logging::Log(const LogData& data) { | 225 void Logging::Log(const LogData& data) { |
226 if (consumer_) { | 226 if (consumer_) { |
227 // We're in the browser process. | 227 // We're in the browser process. |
228 consumer_->Log(data); | 228 consumer_->Log(data); |
229 } else { | 229 } else { |
230 // We're in the renderer or plugin processes. | 230 // We're in the renderer or plugin processes. |
231 if (sender_) { | 231 if (sender_) { |
232 queued_logs_.push_back(data); | 232 queued_logs_.push_back(data); |
233 if (!queue_invoke_later_pending_) { | 233 if (!queue_invoke_later_pending_) { |
234 queue_invoke_later_pending_ = true; | 234 queue_invoke_later_pending_ = true; |
235 MessageLoop::current()->PostDelayedTask( | 235 base::MessageLoop::current()->PostDelayedTask( |
236 FROM_HERE, base::Bind(&Logging::OnSendLogs, base::Unretained(this)), | 236 FROM_HERE, |
| 237 base::Bind(&Logging::OnSendLogs, base::Unretained(this)), |
237 base::TimeDelta::FromMilliseconds(kLogSendDelayMs)); | 238 base::TimeDelta::FromMilliseconds(kLogSendDelayMs)); |
238 } | 239 } |
239 } | 240 } |
240 } | 241 } |
241 if (enabled_on_stderr_) { | 242 if (enabled_on_stderr_) { |
242 std::string message_name; | 243 std::string message_name; |
243 if (data.message_name.empty()) { | 244 if (data.message_name.empty()) { |
244 message_name = base::StringPrintf("[unknown type %d]", data.type); | 245 message_name = base::StringPrintf("[unknown type %d]", data.type); |
245 } else { | 246 } else { |
246 message_name = data.message_name; | 247 message_name = data.message_name; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 data->receive = message.received_time(); | 307 data->receive = message.received_time(); |
307 data->dispatch = Time::Now().ToInternalValue(); | 308 data->dispatch = Time::Now().ToInternalValue(); |
308 data->params = params; | 309 data->params = params; |
309 data->message_name = message_name; | 310 data->message_name = message_name; |
310 } | 311 } |
311 } | 312 } |
312 | 313 |
313 } | 314 } |
314 | 315 |
315 #endif // IPC_MESSAGE_LOG_ENABLED | 316 #endif // IPC_MESSAGE_LOG_ENABLED |
OLD | NEW |