[Mac] Fixes a bug where instant suggest text would disappear on every other keystroke.
[chromium-blink-merge.git] / ipc / ipc_logging.h
blob36e584a8af938b794f8da4ee0db3eb66ccf80356
1 // Copyright (c) 2009 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 IPC_IPC_LOGGING_H_
6 #define IPC_IPC_LOGGING_H_
7 #pragma once
9 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
11 #ifdef IPC_MESSAGE_LOG_ENABLED
13 #include <vector>
15 #include "base/message_loop.h"
16 #include "base/scoped_ptr.h"
17 #include "base/singleton.h"
19 namespace IPC {
21 class Message;
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.
26 class Logging {
27 public:
28 // Implemented by consumers of log messages.
29 class Consumer {
30 public:
31 virtual void Log(const LogData& data) = 0;
33 protected:
34 virtual ~Consumer() {}
37 void SetConsumer(Consumer* consumer);
39 ~Logging();
40 static Logging* current();
42 // Enable and Disable are NOT cross-process; they only affect the
43 // current thread/process. If you want to modify the value for all
44 // processes, perhaps your intent is to call
45 // g_browser_process->SetIPCLoggingEnabled().
46 void Enable();
47 void Disable();
48 bool Enabled() const { return enabled_; }
50 // Called by child processes to give the logger object the channel to send
51 // logging data to the browser process.
52 void SetIPCSender(Message::Sender* sender);
54 // Called in the browser process when logging data from a child process is
55 // received.
56 void OnReceivedLoggingMessage(const Message& message);
58 void OnSendMessage(Message* message, const std::string& channel_id);
59 void OnPreDispatchMessage(const Message& message);
60 void OnPostDispatchMessage(const Message& message,
61 const std::string& channel_id);
63 // Returns the name of the logging enabled/disabled events so that the
64 // sandbox can add them to to the policy. If true, gets the name of the
65 // enabled event, if false, gets the name of the disabled event.
66 static std::wstring GetEventName(bool enabled);
68 // Like the *MsgLog functions declared for each message class, except this
69 // calls the correct one based on the message type automatically. Defined in
70 // ipc_logging.cc.
71 static void GetMessageText(uint32 type, std::string* name,
72 const Message* message, std::string* params);
74 // Logging function. |name| is a string in ASCII and |params| is a string in
75 // UTF-8.
76 typedef void (*LogFunction)(uint32 type,
77 std::string* name,
78 const Message* msg,
79 std::string* params);
81 static void SetLoggerFunctions(LogFunction *functions);
83 private:
84 friend struct DefaultSingletonTraits<Logging>;
85 Logging();
87 void OnSendLogs();
88 void Log(const LogData& data);
90 bool enabled_;
91 bool enabled_on_stderr_; // only used on POSIX for now
93 std::vector<LogData> queued_logs_;
94 bool queue_invoke_later_pending_;
96 Message::Sender* sender_;
97 MessageLoop* main_thread_;
99 Consumer* consumer_;
101 static LogFunction *log_function_mapping_;
104 } // namespace IPC
106 #endif // IPC_MESSAGE_LOG_ENABLED
108 #endif // IPC_IPC_LOGGING_H_