Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2276)

Side by Side Diff: chrome/common/ipc_logging.h

Issue 20156: POSIX: basic IPC logging (Closed)
Patch Set: Merge jrg's xcode changes Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/ipc_channel_proxy.cc ('k') | chrome/common/ipc_logging.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_COMMON_IPC_LOGGING_H_ 5 #ifndef CHROME_COMMON_IPC_LOGGING_H_
6 #define CHROME_COMMON_IPC_LOGGING_H_ 6 #define CHROME_COMMON_IPC_LOGGING_H_
7 7
8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. 8 #include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
9 9
10 #ifdef IPC_MESSAGE_LOG_ENABLED 10 #ifdef IPC_MESSAGE_LOG_ENABLED
11 11
12 #include "base/lock.h" 12 #include "base/lock.h"
13 #include "base/object_watcher.h"
14 #include "base/singleton.h" 13 #include "base/singleton.h"
14 #include "base/waitable_event_watcher.h"
15 #include "chrome/common/ipc_message_utils.h" 15 #include "chrome/common/ipc_message_utils.h"
16 16
17 class MessageLoop; 17 class MessageLoop;
18 18
19 namespace IPC { 19 namespace IPC {
20 20
21 class Message; 21 class Message;
22 22
23 // One instance per process. Needs to be created on the main thread (the UI 23 // One instance per process. Needs to be created on the main thread (the UI
24 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage 24 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
25 // can be called on other threads. 25 // can be called on other threads.
26 class Logging : public base::ObjectWatcher::Delegate { 26 class Logging : public base::WaitableEventWatcher::Delegate {
27 public: 27 public:
28 // Implemented by consumers of log messages. 28 // Implemented by consumers of log messages.
29 class Consumer { 29 class Consumer {
30 public: 30 public:
31 virtual void Log(const LogData& data) = 0; 31 virtual void Log(const LogData& data) = 0;
32 }; 32 };
33 33
34 void SetConsumer(Consumer* consumer); 34 void SetConsumer(Consumer* consumer);
35 35
36 ~Logging(); 36 ~Logging();
37 static Logging* current(); 37 static Logging* current();
38 38
39 void Enable(); 39 void Enable();
40 void Disable(); 40 void Disable();
41 bool inline Enabled() const; 41 bool Enabled() const { return enabled_; }
42 42
43 // Called by child processes to give the logger object the channel to send 43 // Called by child processes to give the logger object the channel to send
44 // logging data to the browser process. 44 // logging data to the browser process.
45 void SetIPCSender(Message::Sender* sender); 45 void SetIPCSender(Message::Sender* sender);
46 46
47 // Called in the browser process when logging data from a child process is 47 // Called in the browser process when logging data from a child process is
48 // received. 48 // received.
49 void OnReceivedLoggingMessage(const Message& message); 49 void OnReceivedLoggingMessage(const Message& message);
50 50
51 void OnSendMessage(Message* message, const std::wstring& channel_id); 51 void OnSendMessage(Message* message, const std::wstring& channel_id);
52 void OnPreDispatchMessage(const Message& message); 52 void OnPreDispatchMessage(const Message& message);
53 void OnPostDispatchMessage(const Message& message, 53 void OnPostDispatchMessage(const Message& message,
54 const std::wstring& channel_id); 54 const std::wstring& channel_id);
55 55
56 // Returns the name of the logging enabled/disabled events so that the 56 // Returns the name of the logging enabled/disabled events so that the
57 // sandbox can add them to to the policy. If true, gets the name of the 57 // sandbox can add them to to the policy. If true, gets the name of the
58 // enabled event, if false, gets the name of the disabled event. 58 // enabled event, if false, gets the name of the disabled event.
59 static std::wstring GetEventName(bool enabled); 59 static std::wstring GetEventName(bool enabled);
60 60
61 // Like the *MsgLog functions declared for each message class, except this 61 // Like the *MsgLog functions declared for each message class, except this
62 // calls the correct one based on the message type automatically. Defined in 62 // calls the correct one based on the message type automatically. Defined in
63 // ipc_logging.cc. 63 // ipc_logging.cc.
64 static void GetMessageText(uint16 type, std::wstring* name, 64 static void GetMessageText(uint16 type, std::wstring* name,
65 const Message* message, std::wstring* params); 65 const Message* message, std::wstring* params);
66 66
67 // ObjectWatcher::Delegate implementation 67 // WaitableEventWatcher::Delegate implementation
68 void OnObjectSignaled(HANDLE object); 68 void OnWaitableEventSignaled(base::WaitableEvent* event);
69 69
70 typedef void (*LogFunction)(uint16 type, 70 typedef void (*LogFunction)(uint16 type,
71 std::wstring* name, 71 std::wstring* name,
72 const Message* msg, 72 const Message* msg,
73 std::wstring* params); 73 std::wstring* params);
74 74
75 static void SetLoggerFunctions(LogFunction *functions); 75 static void SetLoggerFunctions(LogFunction *functions);
76 76
77 private: 77 private:
78 friend struct DefaultSingletonTraits<Logging>; 78 friend struct DefaultSingletonTraits<Logging>;
79 Logging(); 79 Logging();
80 80
81 std::wstring GetEventName(int browser_pid, bool enabled); 81 std::wstring GetEventName(int browser_pid, bool enabled);
82 void OnSendLogs(); 82 void OnSendLogs();
83 void Log(const LogData& data); 83 void Log(const LogData& data);
84 84
85 void RegisterWaitForEvent(bool enabled); 85 void RegisterWaitForEvent(bool enabled);
86 86
87 base::ObjectWatcher watcher_; 87 base::WaitableEventWatcher watcher_;
88 88
89 HANDLE logging_event_on_; 89 scoped_ptr<base::WaitableEvent> logging_event_on_;
90 HANDLE logging_event_off_; 90 scoped_ptr<base::WaitableEvent> logging_event_off_;
91 bool enabled_; 91 bool enabled_;
92 92
93 std::vector<LogData> queued_logs_; 93 std::vector<LogData> queued_logs_;
94 bool queue_invoke_later_pending_; 94 bool queue_invoke_later_pending_;
95 95
96 Message::Sender* sender_; 96 Message::Sender* sender_;
97 MessageLoop* main_thread_; 97 MessageLoop* main_thread_;
98 98
99 Consumer* consumer_; 99 Consumer* consumer_;
100 100
101 static LogFunction *log_function_mapping_; 101 static LogFunction *log_function_mapping_;
102 }; 102 };
103 103
104 } // namespace IPC 104 } // namespace IPC
105 105
106 #endif // IPC_MESSAGE_LOG_ENABLED 106 #endif // IPC_MESSAGE_LOG_ENABLED
107 107
108 #endif // CHROME_COMMON_IPC_LOGGING_H_ 108 #endif // CHROME_COMMON_IPC_LOGGING_H_
109 109
OLDNEW
« no previous file with comments | « chrome/common/ipc_channel_proxy.cc ('k') | chrome/common/ipc_logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698