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