blob: bf49595d64b46802f56e526edb0594b2632127bb [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
[email protected]cee1dfa2008-08-14 09:21:505#ifndef CHROME_COMMON_IPC_LOGGING_H_
6#define CHROME_COMMON_IPC_LOGGING_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]3178f4e22008-08-05 21:20:418#include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
initial.commit09911bf2008-07-26 23:55:299
10#ifdef IPC_MESSAGE_LOG_ENABLED
11
[email protected]1c4947f2009-01-15 22:25:1112#include "base/lock.h"
13#include "base/object_watcher.h"
14#include "base/singleton.h"
[email protected]f91cb992009-02-04 20:10:1215#include "chrome/common/ipc_message_utils.h"
[email protected]1c4947f2009-01-15 22:25:1116
[email protected]cee1dfa2008-08-14 09:21:5017class MessageLoop;
18
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]cee1dfa2008-08-14 09:21:5026class Logging : public base::ObjectWatcher::Delegate {
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
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]f91cb992009-02-04 20:10:1245 void SetIPCSender(Message::Sender* sender);
initial.commit09911bf2008-07-26 23:55:2946
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]cee1dfa2008-08-14 09:21:5067 // ObjectWatcher::Delegate implementation
initial.commit09911bf2008-07-26 23:55:2968 void OnObjectSignaled(HANDLE object);
69
[email protected]d5dfa5a2009-02-10 19:38:5570 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.commit09911bf2008-07-26 23:55:2976 private:
[email protected]f91cb992009-02-04 20:10:1277 friend struct DefaultSingletonTraits<Logging>;
initial.commit09911bf2008-07-26 23:55:2978 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]cee1dfa2008-08-14 09:21:5086 base::ObjectWatcher watcher_;
87
initial.commit09911bf2008-07-26 23:55:2988 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]f91cb992009-02-04 20:10:1295 Message::Sender* sender_;
initial.commit09911bf2008-07-26 23:55:2996 MessageLoop* main_thread_;
97
98 Consumer* consumer_;
[email protected]d5dfa5a2009-02-10 19:38:5599
100 LogFunction* log_function_mapping_[LastMsgIndex];
initial.commit09911bf2008-07-26 23:55:29101};
102
[email protected]3178f4e22008-08-05 21:20:41103} // namespace IPC
initial.commit09911bf2008-07-26 23:55:29104
105#endif // IPC_MESSAGE_LOG_ENABLED
106
[email protected]cee1dfa2008-08-14 09:21:50107#endif // CHROME_COMMON_IPC_LOGGING_H_
license.botbf09a502008-08-24 00:55:55108