blob: 567ba84e063b11f068b066f2688e5d4180a75496 [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"
15
[email protected]cee1dfa2008-08-14 09:21:5016class MessageLoop;
17
initial.commit09911bf2008-07-26 23:55:2918namespace IPC {
19
20class Message;
21
22// One instance per process. Needs to be created on the main thread (the UI
23// thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
24// can be called on other threads.
[email protected]cee1dfa2008-08-14 09:21:5025class Logging : public base::ObjectWatcher::Delegate {
initial.commit09911bf2008-07-26 23:55:2926 public:
27 // Implemented by consumers of log messages.
28 class Consumer {
29 public:
30 virtual void Log(const IPC::LogData& data) = 0;
31 };
32
33 void SetConsumer(Consumer* consumer);
34
35 ~Logging();
36 static Logging* current();
37
38 void Enable();
39 void Disable();
40 bool inline Enabled() const;
41
42 // Called by child processes to give the logger object the channel to send
43 // logging data to the browser process.
44 void SetIPCSender(IPC::Message::Sender* sender);
45
46 // Called in the browser process when logging data from a child process is
47 // received.
48 void OnReceivedLoggingMessage(const Message& message);
49
50 void OnSendMessage(Message* message, const std::wstring& channel_id);
51 void OnPreDispatchMessage(const Message& message);
52 void OnPostDispatchMessage(const Message& message,
53 const std::wstring& channel_id);
54
55 // 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 // enabled event, if false, gets the name of the disabled event.
58 static std::wstring GetEventName(bool enabled);
59
60 // 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 // ipc_logging.cc.
63 static void GetMessageText(uint16 type, std::wstring* name,
64 const Message* message, std::wstring* params);
65
[email protected]cee1dfa2008-08-14 09:21:5066 // ObjectWatcher::Delegate implementation
initial.commit09911bf2008-07-26 23:55:2967 void OnObjectSignaled(HANDLE object);
68
69 private:
[email protected]cee1dfa2008-08-14 09:21:5070 friend struct DefaultSingletonTraits<IPC::Logging>;
initial.commit09911bf2008-07-26 23:55:2971 Logging();
72
73 std::wstring GetEventName(int browser_pid, bool enabled);
74 void OnSendLogs();
75 void Log(const LogData& data);
76
77 void RegisterWaitForEvent(bool enabled);
78
[email protected]cee1dfa2008-08-14 09:21:5079 base::ObjectWatcher watcher_;
80
initial.commit09911bf2008-07-26 23:55:2981 HANDLE logging_event_on_;
82 HANDLE logging_event_off_;
83 bool enabled_;
84
85 std::vector<LogData> queued_logs_;
86 bool queue_invoke_later_pending_;
87
88 IPC::Message::Sender* sender_;
89 MessageLoop* main_thread_;
90
91 Consumer* consumer_;
initial.commit09911bf2008-07-26 23:55:2992};
93
[email protected]3178f4e22008-08-05 21:20:4194} // namespace IPC
initial.commit09911bf2008-07-26 23:55:2995
96#endif // IPC_MESSAGE_LOG_ENABLED
97
[email protected]cee1dfa2008-08-14 09:21:5098#endif // CHROME_COMMON_IPC_LOGGING_H_
license.botbf09a502008-08-24 00:55:5599