[email protected] | 5a3b914 | 2009-08-28 21:03:17 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 5 | #ifndef IPC_IPC_LOGGING_H_ |
| 6 | #define IPC_IPC_LOGGING_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 8 | #include "ipc/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] | 7bf73095 | 2009-05-29 09:31:15 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
[email protected] | 100897a | 2009-02-26 02:27:11 | [diff] [blame] | 14 | #include "base/message_loop.h" |
[email protected] | 7bf73095 | 2009-05-29 09:31:15 | [diff] [blame] | 15 | #include "base/scoped_ptr.h" |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 16 | #include "base/singleton.h" |
[email protected] | e707d5e6 | 2009-02-12 04:00:08 | [diff] [blame] | 17 | #include "base/waitable_event_watcher.h" |
[email protected] | cee1dfa | 2008-08-14 09:21:50 | [diff] [blame] | 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] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame^] | 26 | class Logging { |
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 | |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame^] | 39 | // Enable and Disable are NOT cross-process; they only affect the |
| 40 | // current thread/process. If you want to modify the value for all |
| 41 | // processes, perhaps your intent is to call |
| 42 | // g_browser_process->SetIPCLoggingEnabled(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | void Enable(); |
| 44 | void Disable(); |
[email protected] | e707d5e6 | 2009-02-12 04:00:08 | [diff] [blame] | 45 | bool Enabled() const { return enabled_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | |
| 47 | // Called by child processes to give the logger object the channel to send |
| 48 | // logging data to the browser process. |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 49 | void SetIPCSender(Message::Sender* sender); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | |
| 51 | // Called in the browser process when logging data from a child process is |
| 52 | // received. |
| 53 | void OnReceivedLoggingMessage(const Message& message); |
| 54 | |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 55 | void OnSendMessage(Message* message, const std::string& channel_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | void OnPreDispatchMessage(const Message& message); |
| 57 | void OnPostDispatchMessage(const Message& message, |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 58 | const std::string& channel_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | |
| 60 | // Returns the name of the logging enabled/disabled events so that the |
| 61 | // sandbox can add them to to the policy. If true, gets the name of the |
| 62 | // enabled event, if false, gets the name of the disabled event. |
| 63 | static std::wstring GetEventName(bool enabled); |
| 64 | |
| 65 | // Like the *MsgLog functions declared for each message class, except this |
| 66 | // calls the correct one based on the message type automatically. Defined in |
| 67 | // ipc_logging.cc. |
| 68 | static void GetMessageText(uint16 type, std::wstring* name, |
| 69 | const Message* message, std::wstring* params); |
| 70 | |
[email protected] | 3335d87 | 2009-02-11 05:38:41 | [diff] [blame] | 71 | typedef void (*LogFunction)(uint16 type, |
[email protected] | 82e5ee8 | 2009-04-03 02:29:45 | [diff] [blame] | 72 | std::wstring* name, |
| 73 | const Message* msg, |
| 74 | std::wstring* params); |
[email protected] | 3335d87 | 2009-02-11 05:38:41 | [diff] [blame] | 75 | |
| 76 | static void SetLoggerFunctions(LogFunction *functions); |
[email protected] | d5dfa5a | 2009-02-10 19:38:55 | [diff] [blame] | 77 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | private: |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 79 | friend struct DefaultSingletonTraits<Logging>; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | Logging(); |
| 81 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 82 | void OnSendLogs(); |
| 83 | void Log(const LogData& data); |
| 84 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | bool enabled_; |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame^] | 86 | bool enabled_on_stderr_; // only used on POSIX for now |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | |
| 88 | std::vector<LogData> queued_logs_; |
| 89 | bool queue_invoke_later_pending_; |
| 90 | |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 91 | Message::Sender* sender_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | MessageLoop* main_thread_; |
| 93 | |
| 94 | Consumer* consumer_; |
[email protected] | d5dfa5a | 2009-02-10 19:38:55 | [diff] [blame] | 95 | |
[email protected] | 3335d87 | 2009-02-11 05:38:41 | [diff] [blame] | 96 | static LogFunction *log_function_mapping_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | }; |
| 98 | |
[email protected] | 3178f4e2 | 2008-08-05 21:20:41 | [diff] [blame] | 99 | } // namespace IPC |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | |
| 101 | #endif // IPC_MESSAGE_LOG_ENABLED |
| 102 | |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 103 | #endif // IPC_IPC_LOGGING_H_ |