ipc/chromium/src/chrome/common/ipc_logging.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef CHROME_COMMON_IPC_LOGGING_H_
michael@0 6 #define CHROME_COMMON_IPC_LOGGING_H_
michael@0 7
michael@0 8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
michael@0 9
michael@0 10 #ifdef IPC_MESSAGE_LOG_ENABLED
michael@0 11
michael@0 12 #include "base/lock.h"
michael@0 13 #include "base/message_loop.h"
michael@0 14 #include "base/singleton.h"
michael@0 15 #include "base/waitable_event_watcher.h"
michael@0 16 #include "chrome/common/ipc_message_utils.h"
michael@0 17
michael@0 18 class MessageLoop;
michael@0 19
michael@0 20 namespace IPC {
michael@0 21
michael@0 22 class Message;
michael@0 23
michael@0 24 // One instance per process. Needs to be created on the main thread (the UI
michael@0 25 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
michael@0 26 // can be called on other threads.
michael@0 27 class Logging : public base::WaitableEventWatcher::Delegate,
michael@0 28 public MessageLoop::DestructionObserver {
michael@0 29 public:
michael@0 30 // Implemented by consumers of log messages.
michael@0 31 class Consumer {
michael@0 32 public:
michael@0 33 virtual void Log(const LogData& data) = 0;
michael@0 34 };
michael@0 35
michael@0 36 void SetConsumer(Consumer* consumer);
michael@0 37
michael@0 38 ~Logging();
michael@0 39 static Logging* current();
michael@0 40
michael@0 41 void Enable();
michael@0 42 void Disable();
michael@0 43 bool Enabled() const { return enabled_; }
michael@0 44
michael@0 45 // Called by child processes to give the logger object the channel to send
michael@0 46 // logging data to the browser process.
michael@0 47 void SetIPCSender(Message::Sender* sender);
michael@0 48
michael@0 49 // Called in the browser process when logging data from a child process is
michael@0 50 // received.
michael@0 51 void OnReceivedLoggingMessage(const Message& message);
michael@0 52
michael@0 53 void OnSendMessage(Message* message, const std::wstring& channel_id);
michael@0 54 void OnPreDispatchMessage(const Message& message);
michael@0 55 void OnPostDispatchMessage(const Message& message,
michael@0 56 const std::wstring& channel_id);
michael@0 57
michael@0 58 // Returns the name of the logging enabled/disabled events so that the
michael@0 59 // sandbox can add them to to the policy. If true, gets the name of the
michael@0 60 // enabled event, if false, gets the name of the disabled event.
michael@0 61 static std::wstring GetEventName(bool enabled);
michael@0 62
michael@0 63 // Like the *MsgLog functions declared for each message class, except this
michael@0 64 // calls the correct one based on the message type automatically. Defined in
michael@0 65 // ipc_logging.cc.
michael@0 66 static void GetMessageText(uint16_t type, std::wstring* name,
michael@0 67 const Message* message, std::wstring* params);
michael@0 68
michael@0 69 // WaitableEventWatcher::Delegate implementation
michael@0 70 void OnWaitableEventSignaled(base::WaitableEvent* event);
michael@0 71
michael@0 72 // MessageLoop::DestructionObserver implementation
michael@0 73 void WillDestroyCurrentMessageLoop();
michael@0 74
michael@0 75 typedef void (*LogFunction)(uint16_t type,
michael@0 76 std::wstring* name,
michael@0 77 const Message* msg,
michael@0 78 std::wstring* params);
michael@0 79
michael@0 80 static void SetLoggerFunctions(LogFunction *functions);
michael@0 81
michael@0 82 private:
michael@0 83 friend struct DefaultSingletonTraits<Logging>;
michael@0 84 Logging();
michael@0 85
michael@0 86 std::wstring GetEventName(int browser_pid, bool enabled);
michael@0 87 void OnSendLogs();
michael@0 88 void Log(const LogData& data);
michael@0 89
michael@0 90 void RegisterWaitForEvent(bool enabled);
michael@0 91
michael@0 92 base::WaitableEventWatcher watcher_;
michael@0 93
michael@0 94 scoped_ptr<base::WaitableEvent> logging_event_on_;
michael@0 95 scoped_ptr<base::WaitableEvent> logging_event_off_;
michael@0 96 bool enabled_;
michael@0 97
michael@0 98 std::vector<LogData> queued_logs_;
michael@0 99 bool queue_invoke_later_pending_;
michael@0 100
michael@0 101 Message::Sender* sender_;
michael@0 102 MessageLoop* main_thread_;
michael@0 103
michael@0 104 Consumer* consumer_;
michael@0 105
michael@0 106 static LogFunction *log_function_mapping_;
michael@0 107 };
michael@0 108
michael@0 109 } // namespace IPC
michael@0 110
michael@0 111 #endif // IPC_MESSAGE_LOG_ENABLED
michael@0 112
michael@0 113 #endif // CHROME_COMMON_IPC_LOGGING_H_

mercurial