| 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 #ifndef CHROME_COMMON_IPC_LOGGING_H_ | 5 #ifndef CHROME_COMMON_IPC_LOGGING_H_ |
| 6 #define CHROME_COMMON_IPC_LOGGING_H_ | 6 #define CHROME_COMMON_IPC_LOGGING_H_ |
| 7 | 7 |
| 8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. | 8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. |
| 9 | 9 |
| 10 #ifdef IPC_MESSAGE_LOG_ENABLED | 10 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 11 | 11 |
| 12 #include "base/lock.h" | 12 #include "base/lock.h" |
| 13 #include "base/object_watcher.h" | 13 #include "base/object_watcher.h" |
| 14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
| 15 #include "chrome/common/ipc_message_utils.h" |
| 15 | 16 |
| 16 class MessageLoop; | 17 class MessageLoop; |
| 17 | 18 |
| 18 namespace IPC { | 19 namespace IPC { |
| 19 | 20 |
| 20 class Message; | 21 class Message; |
| 21 | 22 |
| 22 // One instance per process. Needs to be created on the main thread (the UI | 23 // One instance per process. Needs to be created on the main thread (the UI |
| 23 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage | 24 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage |
| 24 // can be called on other threads. | 25 // can be called on other threads. |
| 25 class Logging : public base::ObjectWatcher::Delegate { | 26 class Logging : public base::ObjectWatcher::Delegate { |
| 26 public: | 27 public: |
| 27 // Implemented by consumers of log messages. | 28 // Implemented by consumers of log messages. |
| 28 class Consumer { | 29 class Consumer { |
| 29 public: | 30 public: |
| 30 virtual void Log(const IPC::LogData& data) = 0; | 31 virtual void Log(const LogData& data) = 0; |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 void SetConsumer(Consumer* consumer); | 34 void SetConsumer(Consumer* consumer); |
| 34 | 35 |
| 35 ~Logging(); | 36 ~Logging(); |
| 36 static Logging* current(); | 37 static Logging* current(); |
| 37 | 38 |
| 38 void Enable(); | 39 void Enable(); |
| 39 void Disable(); | 40 void Disable(); |
| 40 bool inline Enabled() const; | 41 bool inline Enabled() const; |
| 41 | 42 |
| 42 // Called by child processes to give the logger object the channel to send | 43 // Called by child processes to give the logger object the channel to send |
| 43 // logging data to the browser process. | 44 // logging data to the browser process. |
| 44 void SetIPCSender(IPC::Message::Sender* sender); | 45 void SetIPCSender(Message::Sender* sender); |
| 45 | 46 |
| 46 // Called in the browser process when logging data from a child process is | 47 // Called in the browser process when logging data from a child process is |
| 47 // received. | 48 // received. |
| 48 void OnReceivedLoggingMessage(const Message& message); | 49 void OnReceivedLoggingMessage(const Message& message); |
| 49 | 50 |
| 50 void OnSendMessage(Message* message, const std::wstring& channel_id); | 51 void OnSendMessage(Message* message, const std::wstring& channel_id); |
| 51 void OnPreDispatchMessage(const Message& message); | 52 void OnPreDispatchMessage(const Message& message); |
| 52 void OnPostDispatchMessage(const Message& message, | 53 void OnPostDispatchMessage(const Message& message, |
| 53 const std::wstring& channel_id); | 54 const std::wstring& channel_id); |
| 54 | 55 |
| 55 // Returns the name of the logging enabled/disabled events so that the | 56 // Returns the name of the logging enabled/disabled events so that the |
| 56 // sandbox can add them to to the policy. If true, gets the name of the | 57 // sandbox can add them to to the policy. If true, gets the name of the |
| 57 // enabled event, if false, gets the name of the disabled event. | 58 // enabled event, if false, gets the name of the disabled event. |
| 58 static std::wstring GetEventName(bool enabled); | 59 static std::wstring GetEventName(bool enabled); |
| 59 | 60 |
| 60 // Like the *MsgLog functions declared for each message class, except this | 61 // Like the *MsgLog functions declared for each message class, except this |
| 61 // calls the correct one based on the message type automatically. Defined in | 62 // calls the correct one based on the message type automatically. Defined in |
| 62 // ipc_logging.cc. | 63 // ipc_logging.cc. |
| 63 static void GetMessageText(uint16 type, std::wstring* name, | 64 static void GetMessageText(uint16 type, std::wstring* name, |
| 64 const Message* message, std::wstring* params); | 65 const Message* message, std::wstring* params); |
| 65 | 66 |
| 66 // ObjectWatcher::Delegate implementation | 67 // ObjectWatcher::Delegate implementation |
| 67 void OnObjectSignaled(HANDLE object); | 68 void OnObjectSignaled(HANDLE object); |
| 68 | 69 |
| 70 typedef void (LogFunction)(uint16 type, |
| 71 std::wstring* name, |
| 72 const Message* msg, |
| 73 std::wstring* params); |
| 74 void RegisterMessageLogger(int msg_start, LogFunction* func); |
| 75 |
| 69 private: | 76 private: |
| 70 friend struct DefaultSingletonTraits<IPC::Logging>; | 77 friend struct DefaultSingletonTraits<Logging>; |
| 71 Logging(); | 78 Logging(); |
| 72 | 79 |
| 73 std::wstring GetEventName(int browser_pid, bool enabled); | 80 std::wstring GetEventName(int browser_pid, bool enabled); |
| 74 void OnSendLogs(); | 81 void OnSendLogs(); |
| 75 void Log(const LogData& data); | 82 void Log(const LogData& data); |
| 76 | 83 |
| 77 void RegisterWaitForEvent(bool enabled); | 84 void RegisterWaitForEvent(bool enabled); |
| 78 | 85 |
| 79 base::ObjectWatcher watcher_; | 86 base::ObjectWatcher watcher_; |
| 80 | 87 |
| 81 HANDLE logging_event_on_; | 88 HANDLE logging_event_on_; |
| 82 HANDLE logging_event_off_; | 89 HANDLE logging_event_off_; |
| 83 bool enabled_; | 90 bool enabled_; |
| 84 | 91 |
| 85 std::vector<LogData> queued_logs_; | 92 std::vector<LogData> queued_logs_; |
| 86 bool queue_invoke_later_pending_; | 93 bool queue_invoke_later_pending_; |
| 87 | 94 |
| 88 IPC::Message::Sender* sender_; | 95 Message::Sender* sender_; |
| 89 MessageLoop* main_thread_; | 96 MessageLoop* main_thread_; |
| 90 | 97 |
| 91 Consumer* consumer_; | 98 Consumer* consumer_; |
| 99 |
| 100 LogFunction* log_function_mapping_[LastMsgIndex]; |
| 92 }; | 101 }; |
| 93 | 102 |
| 94 } // namespace IPC | 103 } // namespace IPC |
| 95 | 104 |
| 96 #endif // IPC_MESSAGE_LOG_ENABLED | 105 #endif // IPC_MESSAGE_LOG_ENABLED |
| 97 | 106 |
| 98 #endif // CHROME_COMMON_IPC_LOGGING_H_ | 107 #endif // CHROME_COMMON_IPC_LOGGING_H_ |
| 99 | 108 |
| OLD | NEW |