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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/ipc_logging.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef CHROME_COMMON_IPC_LOGGING_H_
     1.9 +#define CHROME_COMMON_IPC_LOGGING_H_
    1.10 +
    1.11 +#include "chrome/common/ipc_message.h"  // For IPC_MESSAGE_LOG_ENABLED.
    1.12 +
    1.13 +#ifdef IPC_MESSAGE_LOG_ENABLED
    1.14 +
    1.15 +#include "base/lock.h"
    1.16 +#include "base/message_loop.h"
    1.17 +#include "base/singleton.h"
    1.18 +#include "base/waitable_event_watcher.h"
    1.19 +#include "chrome/common/ipc_message_utils.h"
    1.20 +
    1.21 +class MessageLoop;
    1.22 +
    1.23 +namespace IPC {
    1.24 +
    1.25 +class Message;
    1.26 +
    1.27 +// One instance per process.  Needs to be created on the main thread (the UI
    1.28 +// thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
    1.29 +// can be called on other threads.
    1.30 +class Logging : public base::WaitableEventWatcher::Delegate,
    1.31 +                public MessageLoop::DestructionObserver {
    1.32 + public:
    1.33 +  // Implemented by consumers of log messages.
    1.34 +  class Consumer {
    1.35 +   public:
    1.36 +    virtual void Log(const LogData& data) = 0;
    1.37 +  };
    1.38 +
    1.39 +  void SetConsumer(Consumer* consumer);
    1.40 +
    1.41 +  ~Logging();
    1.42 +  static Logging* current();
    1.43 +
    1.44 +  void Enable();
    1.45 +  void Disable();
    1.46 +  bool Enabled() const { return enabled_; }
    1.47 +
    1.48 +  // Called by child processes to give the logger object the channel to send
    1.49 +  // logging data to the browser process.
    1.50 +  void SetIPCSender(Message::Sender* sender);
    1.51 +
    1.52 +  // Called in the browser process when logging data from a child process is
    1.53 +  // received.
    1.54 +  void OnReceivedLoggingMessage(const Message& message);
    1.55 +
    1.56 +  void OnSendMessage(Message* message, const std::wstring& channel_id);
    1.57 +  void OnPreDispatchMessage(const Message& message);
    1.58 +  void OnPostDispatchMessage(const Message& message,
    1.59 +                             const std::wstring& channel_id);
    1.60 +
    1.61 +  // Returns the name of the logging enabled/disabled events so that the
    1.62 +  // sandbox can add them to to the policy.  If true, gets the name of the
    1.63 +  // enabled event, if false, gets the name of the disabled event.
    1.64 +  static std::wstring GetEventName(bool enabled);
    1.65 +
    1.66 +  // Like the *MsgLog functions declared for each message class, except this
    1.67 +  // calls the correct one based on the message type automatically.  Defined in
    1.68 +  // ipc_logging.cc.
    1.69 +  static void GetMessageText(uint16_t type, std::wstring* name,
    1.70 +                             const Message* message, std::wstring* params);
    1.71 +
    1.72 +  // WaitableEventWatcher::Delegate implementation
    1.73 +  void OnWaitableEventSignaled(base::WaitableEvent* event);
    1.74 +
    1.75 +  // MessageLoop::DestructionObserver implementation
    1.76 +  void WillDestroyCurrentMessageLoop();
    1.77 +
    1.78 +  typedef void (*LogFunction)(uint16_t type,
    1.79 +                             std::wstring* name,
    1.80 +                             const Message* msg,
    1.81 +                             std::wstring* params);
    1.82 +
    1.83 +  static void SetLoggerFunctions(LogFunction *functions);
    1.84 +
    1.85 + private:
    1.86 +  friend struct DefaultSingletonTraits<Logging>;
    1.87 +  Logging();
    1.88 +
    1.89 +  std::wstring GetEventName(int browser_pid, bool enabled);
    1.90 +  void OnSendLogs();
    1.91 +  void Log(const LogData& data);
    1.92 +
    1.93 +  void RegisterWaitForEvent(bool enabled);
    1.94 +
    1.95 +  base::WaitableEventWatcher watcher_;
    1.96 +
    1.97 +  scoped_ptr<base::WaitableEvent> logging_event_on_;
    1.98 +  scoped_ptr<base::WaitableEvent> logging_event_off_;
    1.99 +  bool enabled_;
   1.100 +
   1.101 +  std::vector<LogData> queued_logs_;
   1.102 +  bool queue_invoke_later_pending_;
   1.103 +
   1.104 +  Message::Sender* sender_;
   1.105 +  MessageLoop* main_thread_;
   1.106 +
   1.107 +  Consumer* consumer_;
   1.108 +
   1.109 +  static LogFunction *log_function_mapping_;
   1.110 +};
   1.111 +
   1.112 +}  // namespace IPC
   1.113 +
   1.114 +#endif // IPC_MESSAGE_LOG_ENABLED
   1.115 +
   1.116 +#endif  // CHROME_COMMON_IPC_LOGGING_H_

mercurial