Index: chrome/common/ipc_logging.cc |
diff --git a/chrome/common/ipc_logging.cc b/chrome/common/ipc_logging.cc |
index c9874b7ee48ae36926fef884e3f199ec0bc5a74c..851ea1f8fb3bbc398c054396aa14982196f2b7f3 100644 |
--- a/chrome/common/ipc_logging.cc |
+++ b/chrome/common/ipc_logging.cc |
@@ -4,17 +4,34 @@ |
#include "chrome/common/ipc_logging.h" |
+#if defined(OS_POSIX) |
+#ifdef IPC_MESSAGE_LOG_ENABLED |
+// This will cause render_messages.h etc to define ViewMsgLog and friends. |
+#define IPC_MESSAGE_MACROS_LOG_ENABLED |
+#endif |
+#endif |
+ |
#include "base/command_line.h" |
#include "base/logging.h" |
#include "base/message_loop.h" |
#include "base/string_util.h" |
#include "base/thread.h" |
#include "base/time.h" |
+#include "base/waitable_event.h" |
+#include "base/waitable_event_watcher.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/ipc_sync_message.h" |
#include "chrome/common/ipc_message_utils.h" |
#include "chrome/common/render_messages.h" |
+#if defined(OS_WIN) |
+// TODO(port): These messages will need to be ported at some point |
#include "chrome/common/plugin_messages.h" |
+#endif |
+ |
+#if defined(OS_POSIX) |
+#include "base/string_util.h" |
+#include <unistd.h> |
+#endif |
#ifdef IPC_MESSAGE_LOG_ENABLED |
@@ -41,14 +58,15 @@ Logging::Logging() |
: logging_event_on_(NULL), |
logging_event_off_(NULL), |
enabled_(false), |
- sender_(NULL), |
- consumer_(NULL), |
queue_invoke_later_pending_(false), |
main_thread_(MessageLoop::current()) { |
// Create an event for this browser instance that's set when logging is |
// enabled, so child processes can know when logging is enabled. |
- int browser_pid; |
+#if defined(OS_WIN) |
+ // On Windows we have a couple of named events which switch logging on and |
+ // off. |
+ int browser_pid; |
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
std::wstring process_type = |
parsed_command_line.GetSwitchValue(switches::kProcessType); |
@@ -63,18 +81,23 @@ Logging::Logging() |
} |
std::wstring event_name = GetEventName(browser_pid, true); |
- logging_event_on_ = CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); |
+ logging_event_on_ = new base::WaitableEvent( |
+ CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); |
event_name = GetEventName(browser_pid, false); |
- logging_event_off_ = CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); |
+ logging_event_off_ = new base::WaitableEvent( |
+ CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); |
RegisterWaitForEvent(true); |
+#elif defined(OS_POSIX) |
+ if (getenv("CHROME_IPC_LOGGING")) |
+ enabled_ = true; |
+ SetLoggerFunctions(g_log_function_mapping); |
+#endif |
} |
Logging::~Logging() { |
watcher_.StopWatching(); |
- CloseHandle(logging_event_on_); |
- CloseHandle(logging_event_off_); |
} |
Logging* Logging::current() { |
@@ -84,11 +107,11 @@ Logging* Logging::current() { |
void Logging::RegisterWaitForEvent(bool enabled) { |
watcher_.StopWatching(); |
watcher_.StartWatching( |
- enabled ? logging_event_on_ : logging_event_off_, this); |
+ enabled ? logging_event_on_.get() : logging_event_off_.get(), this); |
} |
-void Logging::OnObjectSignaled(HANDLE object) { |
- enabled_ = object == logging_event_on_; |
+void Logging::OnWaitableEventSignaled(base::WaitableEvent* event) { |
+ enabled_ = event == logging_event_on_.get(); |
RegisterWaitForEvent(!enabled_); |
} |
@@ -96,9 +119,11 @@ void Logging::SetLoggerFunctions(LogFunction *functions) { |
log_function_mapping_ = functions; |
} |
+#if defined(OS_WIN) |
std::wstring Logging::GetEventName(bool enabled) { |
return current()->GetEventName(GetCurrentProcessId(), enabled); |
} |
+#endif |
std::wstring Logging::GetEventName(int browser_pid, bool enabled) { |
std::wstring result = StringPrintf(kLoggingEventName, browser_pid); |
@@ -111,17 +136,13 @@ void Logging::SetConsumer(Consumer* consumer) { |
} |
void Logging::Enable() { |
- ResetEvent(logging_event_off_); |
- SetEvent(logging_event_on_); |
+ logging_event_off_->Reset(); |
+ logging_event_on_->Signal(); |
} |
void Logging::Disable() { |
- ResetEvent(logging_event_on_); |
- SetEvent(logging_event_off_); |
-} |
- |
-inline bool Logging::Enabled() const { |
- return enabled_; |
+ logging_event_on_->Reset(); |
+ logging_event_off_->Signal(); |
} |
void Logging::OnSendLogs() { |
@@ -182,7 +203,7 @@ void Logging::OnPreDispatchMessage(const Message& message) { |
void Logging::OnPostDispatchMessage(const Message& message, |
const std::wstring& channel_id) { |
- if (!Enabled() || !message.sent_time() || message.dont_log()) |
+ if (!Enabled() || message.dont_log()) |
return; |
LogData data; |
@@ -212,6 +233,7 @@ void Logging::GetMessageText(uint16 type, std::wstring* name, |
} |
void Logging::Log(const LogData& data) { |
+#if defined(OS_WIN) |
if (consumer_) { |
// We're in the browser process. |
consumer_->Log(data); |
@@ -226,6 +248,15 @@ void Logging::Log(const LogData& data) { |
} |
} |
} |
+#elif defined(OS_POSIX) |
+ // On POSIX, for now, we just dump the log to stderr |
+ fprintf(stderr, "ipc %s %d %s %s %s\n", |
+ WideToUTF8(data.channel).c_str(), |
+ data.type, |
+ WideToUTF8(data.flags).c_str(), |
+ WideToUTF8(data.message_name).c_str(), |
+ WideToUTF8(data.params).c_str()); |
+#endif |
} |
void GenerateLogData(const std::wstring& channel, const Message& message, |
@@ -252,8 +283,8 @@ void GenerateLogData(const std::wstring& channel, const Message& message, |
if (message.is_reply_error()) |
flags += L"E"; |
- std::wstring params; |
- Logging::GetMessageText(message.type(), NULL, &message, ¶ms); |
+ std::wstring params, message_name; |
+ Logging::GetMessageText(message.type(), &message_name, &message, ¶ms); |
data->channel = channel; |
data->type = message.type(); |
@@ -262,6 +293,7 @@ void GenerateLogData(const std::wstring& channel, const Message& message, |
data->receive = message.received_time(); |
data->dispatch = Time::Now().ToInternalValue(); |
data->params = params; |
+ data->message_name = message_name; |
} |
} |