diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 21:08:04 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 21:08:04 +0000 |
commit | d55aaa139da94452ebd6812bfa9241ba050978d9 (patch) | |
tree | c5fd3ad94b96114b9109fc92610cae3b9688014b /ipc | |
parent | 50e8299eb26f3a289c35badb7e740eb109981cd1 (diff) | |
download | chromium_src-d55aaa139da94452ebd6812bfa9241ba050978d9.zip chromium_src-d55aaa139da94452ebd6812bfa9241ba050978d9.tar.gz chromium_src-d55aaa139da94452ebd6812bfa9241ba050978d9.tar.bz2 |
Implement about:ipc dialog for Mac.
Convert IPC logging trigger from x-process waitable event to a messages
sent to all processes.
Review URL: http://codereview.chromium.org/192070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_logging.cc | 112 | ||||
-rw-r--r-- | ipc/ipc_logging.h | 21 |
2 files changed, 28 insertions, 105 deletions
diff --git a/ipc/ipc_logging.cc b/ipc/ipc_logging.cc index 9d4f4bb..4232a19 100644 --- a/ipc/ipc_logging.cc +++ b/ipc/ipc_logging.cc @@ -4,16 +4,15 @@ #include "ipc/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/process_util.h" #include "base/string_util.h" #include "base/thread.h" #include "base/time.h" @@ -24,7 +23,6 @@ #include "ipc/ipc_message_utils.h" #if defined(OS_POSIX) -#include "base/string_util.h" #include <unistd.h> #endif @@ -42,7 +40,6 @@ struct RunnableMethodTraits<IPC::Logging> { namespace IPC { -const wchar_t kLoggingEventName[] = L"ChromeIPCLog.%d"; const int kLogSendDelayMs = 100; // We use a pointer to the function table to avoid any linker dependencies on @@ -50,48 +47,16 @@ const int kLogSendDelayMs = 100; Logging::LogFunction *Logging::log_function_mapping_; Logging::Logging() - : logging_event_on_(NULL), - logging_event_off_(NULL), - enabled_(false), + : enabled_(false), + enabled_on_stderr_(false), queue_invoke_later_pending_(false), sender_(NULL), main_thread_(MessageLoop::current()), consumer_(NULL) { - // Create an event for this browser instance that's set when logging is - // enabled, so child processes can know when logging is enabled. - -#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); - if (process_type.empty()) { - browser_pid = GetCurrentProcessId(); - } else { - std::wstring channel_name = - parsed_command_line.GetSwitchValue(switches::kProcessChannelID); - - browser_pid = _wtoi(channel_name.c_str()); - DCHECK(browser_pid != 0); - } - - std::wstring event_name = GetEventName(browser_pid, true); - logging_event_on_.reset(new base::WaitableEvent( - CreateEvent(NULL, TRUE, FALSE, event_name.c_str()))); - - event_name = GetEventName(browser_pid, false); - logging_event_off_.reset(new base::WaitableEvent( - CreateEvent(NULL, TRUE, FALSE, event_name.c_str()))); - - RegisterWaitForEvent(true); -#elif defined(OS_POSIX) - if (getenv("CHROME_IPC_LOGGING")) + if (getenv("CHROME_IPC_LOGGING")) { enabled_ = true; -#endif - - MessageLoop::current()->AddDestructionObserver(this); + enabled_on_stderr_ = true; + } } Logging::~Logging() { @@ -101,49 +66,20 @@ Logging* Logging::current() { return Singleton<Logging>::get(); } -void Logging::RegisterWaitForEvent(bool enabled) { - watcher_.StopWatching(); - watcher_.StartWatching( - enabled ? logging_event_on_.get() : logging_event_off_.get(), this); -} - -void Logging::OnWaitableEventSignaled(base::WaitableEvent* event) { - enabled_ = event == logging_event_on_.get(); - RegisterWaitForEvent(!enabled_); -} - -void Logging::WillDestroyCurrentMessageLoop() { - watcher_.StopWatching(); -} - 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); - result += enabled ? L"on" : L"off"; - return result; -} - void Logging::SetConsumer(Consumer* consumer) { consumer_ = consumer; } void Logging::Enable() { - logging_event_off_->Reset(); - logging_event_on_->Signal(); + enabled_ = true; } void Logging::Disable() { - logging_event_on_->Reset(); - logging_event_off_->Signal(); + enabled_ = false; } void Logging::OnSendLogs() { @@ -205,9 +141,8 @@ void Logging::OnPreDispatchMessage(const Message& message) { void Logging::OnPostDispatchMessage(const Message& message, const std::string& channel_id) { if (!Enabled() || -#if defined(OS_WIN) !message.sent_time() || -#endif + !message.received_time() || message.dont_log()) return; @@ -238,7 +173,6 @@ 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); @@ -253,22 +187,20 @@ void Logging::Log(const LogData& data) { } } } -#elif defined(OS_POSIX) - std::string message_name; - if (data.message_name.empty()) { - message_name = StringPrintf("[unknown type %d]", data.type); - } else { - message_name = WideToASCII(data.message_name); + if (enabled_on_stderr_) { + std::string message_name; + if (data.message_name.empty()) { + message_name = StringPrintf("[unknown type %d]", data.type); + } else { + message_name = WideToASCII(data.message_name); + } + fprintf(stderr, "ipc %s %d %s %s %s\n", + data.channel.c_str(), + data.routing_id, + WideToASCII(data.flags).c_str(), + message_name.c_str(), + WideToUTF8(data.params).c_str()); } - - // On POSIX, for now, we just dump the log to stderr - fprintf(stderr, "ipc %s %d %s %s %s\n", - data.channel.c_str(), - data.routing_id, - WideToASCII(data.flags).c_str(), - message_name.c_str(), - WideToUTF8(data.params).c_str()); -#endif } void GenerateLogData(const std::string& channel, const Message& message, diff --git a/ipc/ipc_logging.h b/ipc/ipc_logging.h index 364ad79..e3bc33e 100644 --- a/ipc/ipc_logging.h +++ b/ipc/ipc_logging.h @@ -23,8 +23,7 @@ class Message; // One instance per process. Needs to be created on the main thread (the UI // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage // can be called on other threads. -class Logging : public base::WaitableEventWatcher::Delegate, - public MessageLoop::DestructionObserver { +class Logging { public: // Implemented by consumers of log messages. class Consumer { @@ -37,6 +36,10 @@ class Logging : public base::WaitableEventWatcher::Delegate, ~Logging(); static Logging* current(); + // Enable and Disable are NOT cross-process; they only affect the + // current thread/process. If you want to modify the value for all + // processes, perhaps your intent is to call + // g_browser_process->SetIPCLoggingEnabled(). void Enable(); void Disable(); bool Enabled() const { return enabled_; } @@ -65,12 +68,6 @@ class Logging : public base::WaitableEventWatcher::Delegate, static void GetMessageText(uint16 type, std::wstring* name, const Message* message, std::wstring* params); - // WaitableEventWatcher::Delegate implementation - void OnWaitableEventSignaled(base::WaitableEvent* event); - - // MessageLoop::DestructionObserver implementation - void WillDestroyCurrentMessageLoop(); - typedef void (*LogFunction)(uint16 type, std::wstring* name, const Message* msg, @@ -82,17 +79,11 @@ class Logging : public base::WaitableEventWatcher::Delegate, friend struct DefaultSingletonTraits<Logging>; Logging(); - std::wstring GetEventName(int browser_pid, bool enabled); void OnSendLogs(); void Log(const LogData& data); - void RegisterWaitForEvent(bool enabled); - - base::WaitableEventWatcher watcher_; - - scoped_ptr<base::WaitableEvent> logging_event_on_; - scoped_ptr<base::WaitableEvent> logging_event_off_; bool enabled_; + bool enabled_on_stderr_; // only used on POSIX for now std::vector<LogData> queued_logs_; bool queue_invoke_later_pending_; |