diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 05:38:41 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 05:38:41 +0000 |
commit | 3335d879a364867309a93749cc9e4805bd92d114 (patch) | |
tree | c974aab1fd40e1d4f91e9eb768697a8286ea0dc8 /chrome/common | |
parent | b0a604b351995345bcf9f17ae403495e30fe4cdc (diff) | |
download | chromium_src-3335d879a364867309a93749cc9e4805bd92d114.zip chromium_src-3335d879a364867309a93749cc9e4805bd92d114.tar.gz chromium_src-3335d879a364867309a93749cc9e4805bd92d114.tar.bz2 |
Redo my IPC change, undoing the linker dependency.
Review URL: http://codereview.chromium.org/21225
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/ipc_logging.cc | 23 | ||||
-rw-r--r-- | chrome/common/ipc_logging.h | 7 | ||||
-rw-r--r-- | chrome/common/ipc_message_macros.h | 20 |
3 files changed, 34 insertions, 16 deletions
diff --git a/chrome/common/ipc_logging.cc b/chrome/common/ipc_logging.cc index fef4734..c9874b7 100644 --- a/chrome/common/ipc_logging.cc +++ b/chrome/common/ipc_logging.cc @@ -33,6 +33,10 @@ 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 +// all the traits used as IPC message parameters. +Logging::LogFunction *Logging::log_function_mapping_; + Logging::Logging() : logging_event_on_(NULL), logging_event_off_(NULL), @@ -41,8 +45,6 @@ Logging::Logging() consumer_(NULL), queue_invoke_later_pending_(false), main_thread_(MessageLoop::current()) { - memset(log_function_mapping_, 0, sizeof(log_function_mapping_)); - // 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; @@ -90,14 +92,8 @@ void Logging::OnObjectSignaled(HANDLE object) { RegisterWaitForEvent(!enabled_); } -void Logging::RegisterMessageLogger(int msg_start, LogFunction* func) { - int msg_class = msg_start >> 12; - if (msg_class > arraysize(log_function_mapping_)) { - NOTREACHED(); - return; - } - - log_function_mapping_[msg_class] = func; +void Logging::SetLoggerFunctions(LogFunction *functions) { + log_function_mapping_ = functions; } std::wstring Logging::GetEventName(bool enabled) { @@ -203,9 +199,12 @@ void Logging::OnPostDispatchMessage(const Message& message, void Logging::GetMessageText(uint16 type, std::wstring* name, const Message* message, std::wstring* params) { + if (!log_function_mapping_) + return; + int message_class = type >> 12; - if (current()->log_function_mapping_[message_class] != NULL) { - current()->log_function_mapping_[message_class](type, name, message, params); + if (log_function_mapping_[message_class] != NULL) { + log_function_mapping_[message_class](type, name, message, params); } else { DLOG(INFO) << "No logger function associated with message class " << message_class; diff --git a/chrome/common/ipc_logging.h b/chrome/common/ipc_logging.h index bf49595..5d4016d 100644 --- a/chrome/common/ipc_logging.h +++ b/chrome/common/ipc_logging.h @@ -67,11 +67,12 @@ class Logging : public base::ObjectWatcher::Delegate { // ObjectWatcher::Delegate implementation void OnObjectSignaled(HANDLE object); - typedef void (LogFunction)(uint16 type, + typedef void (*LogFunction)(uint16 type, std::wstring* name, const Message* msg, std::wstring* params); - void RegisterMessageLogger(int msg_start, LogFunction* func); + + static void SetLoggerFunctions(LogFunction *functions); private: friend struct DefaultSingletonTraits<Logging>; @@ -97,7 +98,7 @@ class Logging : public base::ObjectWatcher::Delegate { Consumer* consumer_; - LogFunction* log_function_mapping_[LastMsgIndex]; + static LogFunction *log_function_mapping_; }; } // namespace IPC diff --git a/chrome/common/ipc_message_macros.h b/chrome/common/ipc_message_macros.h index fe39efa..411752f 100644 --- a/chrome/common/ipc_message_macros.h +++ b/chrome/common/ipc_message_macros.h @@ -365,6 +365,17 @@ void class_name::OnMessageReceived(const IPC::Message& msg) \ #elif defined(IPC_MESSAGE_MACROS_LOG) #undef IPC_MESSAGE_MACROS_LOG +#ifndef IPC_LOG_TABLE_CREATED +#define IPC_LOG_TABLE_CREATED +typedef void (*LogFunction)(uint16 type, + std::wstring* name, + const IPC::Message* msg, + std::wstring* params); + +LogFunction g_log_function_mapping[LastMsgIndex]; +#endif + + #define IPC_BEGIN_MESSAGES(label) \ void label##MsgLog(uint16 type, std::wstring* name, const IPC::Message* msg, std::wstring* params) { \ switch (type) { @@ -374,7 +385,14 @@ void class_name::OnMessageReceived(const IPC::Message& msg) \ if (name) \ *name = L"[UNKNOWN " L ## #label L" MSG"; \ } \ - } + } \ + class LoggerRegisterHelper##label { \ + public: \ + LoggerRegisterHelper##label() { \ + g_log_function_mapping[label##MsgStart] = label##MsgLog; \ + } \ + }; \ + LoggerRegisterHelper##label g_LoggerRegisterHelper##label; #define IPC_MESSAGE_LOG(msg_class) \ case msg_class##__ID: \ |