blob: e3bc33ec414564b837091df40598c170fc0cc336 [file] [log] [blame]
[email protected]5a3b9142009-08-28 21:03:171// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]946d1b22009-07-22 23:57:215#ifndef IPC_IPC_LOGGING_H_
6#define IPC_IPC_LOGGING_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]946d1b22009-07-22 23:57:218#include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
initial.commit09911bf2008-07-26 23:55:299
10#ifdef IPC_MESSAGE_LOG_ENABLED
11
[email protected]7bf730952009-05-29 09:31:1512#include <vector>
13
[email protected]100897a2009-02-26 02:27:1114#include "base/message_loop.h"
[email protected]7bf730952009-05-29 09:31:1515#include "base/scoped_ptr.h"
[email protected]1c4947f2009-01-15 22:25:1116#include "base/singleton.h"
[email protected]e707d5e62009-02-12 04:00:0817#include "base/waitable_event_watcher.h"
[email protected]cee1dfa2008-08-14 09:21:5018
initial.commit09911bf2008-07-26 23:55:2919namespace IPC {
20
21class 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]d55aaa132009-09-28 21:08:0426class Logging {
initial.commit09911bf2008-07-26 23:55:2927 public:
28 // Implemented by consumers of log messages.
29 class Consumer {
30 public:
[email protected]f91cb992009-02-04 20:10:1231 virtual void Log(const LogData& data) = 0;
initial.commit09911bf2008-07-26 23:55:2932 };
33
34 void SetConsumer(Consumer* consumer);
35
36 ~Logging();
37 static Logging* current();
38
[email protected]d55aaa132009-09-28 21:08:0439 // 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.commit09911bf2008-07-26 23:55:2943 void Enable();
44 void Disable();
[email protected]e707d5e62009-02-12 04:00:0845 bool Enabled() const { return enabled_; }
initial.commit09911bf2008-07-26 23:55:2946
47 // Called by child processes to give the logger object the channel to send
48 // logging data to the browser process.
[email protected]f91cb992009-02-04 20:10:1249 void SetIPCSender(Message::Sender* sender);
initial.commit09911bf2008-07-26 23:55:2950
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]9a3a293b2009-06-04 22:28:1655 void OnSendMessage(Message* message, const std::string& channel_id);
initial.commit09911bf2008-07-26 23:55:2956 void OnPreDispatchMessage(const Message& message);
57 void OnPostDispatchMessage(const Message& message,
[email protected]9a3a293b2009-06-04 22:28:1658 const std::string& channel_id);
initial.commit09911bf2008-07-26 23:55:2959
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]3335d872009-02-11 05:38:4171 typedef void (*LogFunction)(uint16 type,
[email protected]82e5ee82009-04-03 02:29:4572 std::wstring* name,
73 const Message* msg,
74 std::wstring* params);
[email protected]3335d872009-02-11 05:38:4175
76 static void SetLoggerFunctions(LogFunction *functions);
[email protected]d5dfa5a2009-02-10 19:38:5577
initial.commit09911bf2008-07-26 23:55:2978 private:
[email protected]f91cb992009-02-04 20:10:1279 friend struct DefaultSingletonTraits<Logging>;
initial.commit09911bf2008-07-26 23:55:2980 Logging();
81
initial.commit09911bf2008-07-26 23:55:2982 void OnSendLogs();
83 void Log(const LogData& data);
84
initial.commit09911bf2008-07-26 23:55:2985 bool enabled_;
[email protected]d55aaa132009-09-28 21:08:0486 bool enabled_on_stderr_; // only used on POSIX for now
initial.commit09911bf2008-07-26 23:55:2987
88 std::vector<LogData> queued_logs_;
89 bool queue_invoke_later_pending_;
90
[email protected]f91cb992009-02-04 20:10:1291 Message::Sender* sender_;
initial.commit09911bf2008-07-26 23:55:2992 MessageLoop* main_thread_;
93
94 Consumer* consumer_;
[email protected]d5dfa5a2009-02-10 19:38:5595
[email protected]3335d872009-02-11 05:38:4196 static LogFunction *log_function_mapping_;
initial.commit09911bf2008-07-26 23:55:2997};
98
[email protected]3178f4e22008-08-05 21:20:4199} // namespace IPC
initial.commit09911bf2008-07-26 23:55:29100
101#endif // IPC_MESSAGE_LOG_ENABLED
102
[email protected]946d1b22009-07-22 23:57:21103#endif // IPC_IPC_LOGGING_H_