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