Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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.
5 #ifndef CHROME_COMMON_IPC_LOGGING_H_
6 #define CHROME_COMMON_IPC_LOGGING_H_
8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
10 #ifdef IPC_MESSAGE_LOG_ENABLED
12 #include "base/lock.h"
13 #include "base/message_loop.h"
14 #include "base/singleton.h"
15 #include "base/waitable_event_watcher.h"
16 #include "chrome/common/ipc_message_utils.h"
18 class MessageLoop;
20 namespace IPC {
22 class Message;
24 // One instance per process. Needs to be created on the main thread (the UI
25 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
26 // can be called on other threads.
27 class Logging : public base::WaitableEventWatcher::Delegate,
28 public MessageLoop::DestructionObserver {
29 public:
30 // Implemented by consumers of log messages.
31 class Consumer {
32 public:
33 virtual void Log(const LogData& data) = 0;
34 };
36 void SetConsumer(Consumer* consumer);
38 ~Logging();
39 static Logging* current();
41 void Enable();
42 void Disable();
43 bool Enabled() const { return enabled_; }
45 // Called by child processes to give the logger object the channel to send
46 // logging data to the browser process.
47 void SetIPCSender(Message::Sender* sender);
49 // Called in the browser process when logging data from a child process is
50 // received.
51 void OnReceivedLoggingMessage(const Message& message);
53 void OnSendMessage(Message* message, const std::wstring& channel_id);
54 void OnPreDispatchMessage(const Message& message);
55 void OnPostDispatchMessage(const Message& message,
56 const std::wstring& channel_id);
58 // Returns the name of the logging enabled/disabled events so that the
59 // sandbox can add them to to the policy. If true, gets the name of the
60 // enabled event, if false, gets the name of the disabled event.
61 static std::wstring GetEventName(bool enabled);
63 // Like the *MsgLog functions declared for each message class, except this
64 // calls the correct one based on the message type automatically. Defined in
65 // ipc_logging.cc.
66 static void GetMessageText(uint16_t type, std::wstring* name,
67 const Message* message, std::wstring* params);
69 // WaitableEventWatcher::Delegate implementation
70 void OnWaitableEventSignaled(base::WaitableEvent* event);
72 // MessageLoop::DestructionObserver implementation
73 void WillDestroyCurrentMessageLoop();
75 typedef void (*LogFunction)(uint16_t type,
76 std::wstring* name,
77 const Message* msg,
78 std::wstring* params);
80 static void SetLoggerFunctions(LogFunction *functions);
82 private:
83 friend struct DefaultSingletonTraits<Logging>;
84 Logging();
86 std::wstring GetEventName(int browser_pid, bool enabled);
87 void OnSendLogs();
88 void Log(const LogData& data);
90 void RegisterWaitForEvent(bool enabled);
92 base::WaitableEventWatcher watcher_;
94 scoped_ptr<base::WaitableEvent> logging_event_on_;
95 scoped_ptr<base::WaitableEvent> logging_event_off_;
96 bool enabled_;
98 std::vector<LogData> queued_logs_;
99 bool queue_invoke_later_pending_;
101 Message::Sender* sender_;
102 MessageLoop* main_thread_;
104 Consumer* consumer_;
106 static LogFunction *log_function_mapping_;
107 };
109 } // namespace IPC
111 #endif // IPC_MESSAGE_LOG_ENABLED
113 #endif // CHROME_COMMON_IPC_LOGGING_H_