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

Side by Side Diff: ipc/ipc_logging.h

Issue 5526008: Simplify the magic required to create IPC message headers a bit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_fuzzing_tests.cc ('k') | ipc/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) 2009 The Chromium Authors. All rights reserved. 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 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 IPC_IPC_LOGGING_H_ 5 #ifndef IPC_IPC_LOGGING_H_
6 #define IPC_IPC_LOGGING_H_ 6 #define IPC_IPC_LOGGING_H_
7 #pragma once 7 #pragma once
8 8
9 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. 9 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
10 10
11 #ifdef IPC_MESSAGE_LOG_ENABLED 11 #ifdef IPC_MESSAGE_LOG_ENABLED
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/hash_tables.h"
15 #include "base/message_loop.h" 16 #include "base/message_loop.h"
16 #include "base/scoped_ptr.h" 17 #include "base/scoped_ptr.h"
17 #include "base/singleton.h" 18 #include "base/singleton.h"
18 19
20 // Logging function. |name| is a string in ASCII and |params| is a string in
21 // UTF-8.
22 typedef void (*LogFunction)(std::string* name,
23 const IPC::Message* msg,
24 std::string* params);
25
26 typedef base::hash_map<uint32, LogFunction > LogFunctionMap;
27
19 namespace IPC { 28 namespace IPC {
20 29
21 class Message; 30 class Message;
22 31
23 // One instance per process. Needs to be created on the main thread (the UI 32 // One instance per process. Needs to be created on the main thread (the UI
24 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage 33 // thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
25 // can be called on other threads. 34 // can be called on other threads.
26 class Logging { 35 class Logging {
27 public: 36 public:
28 // Implemented by consumers of log messages. 37 // Implemented by consumers of log messages.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // sandbox can add them to to the policy. If true, gets the name of the 73 // 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. 74 // enabled event, if false, gets the name of the disabled event.
66 static std::wstring GetEventName(bool enabled); 75 static std::wstring GetEventName(bool enabled);
67 76
68 // Like the *MsgLog functions declared for each message class, except this 77 // Like the *MsgLog functions declared for each message class, except this
69 // calls the correct one based on the message type automatically. Defined in 78 // calls the correct one based on the message type automatically. Defined in
70 // ipc_logging.cc. 79 // ipc_logging.cc.
71 static void GetMessageText(uint32 type, std::string* name, 80 static void GetMessageText(uint32 type, std::string* name,
72 const Message* message, std::string* params); 81 const Message* message, std::string* params);
73 82
74 // Logging function. |name| is a string in ASCII and |params| is a string in 83 static void set_log_function_map(LogFunctionMap* functions) {
75 // UTF-8. 84 log_function_map_ = functions;
76 typedef void (*LogFunction)(uint32 type, 85 }
77 std::string* name,
78 const Message* msg,
79 std::string* params);
80 86
81 static void SetLoggerFunctions(LogFunction *functions); 87 static LogFunctionMap* log_function_map() {
88 return log_function_map_;
89 }
82 90
83 private: 91 private:
84 friend struct DefaultSingletonTraits<Logging>; 92 friend struct DefaultSingletonTraits<Logging>;
85 Logging(); 93 Logging();
86 94
87 void OnSendLogs(); 95 void OnSendLogs();
88 void Log(const LogData& data); 96 void Log(const LogData& data);
89 97
90 bool enabled_; 98 bool enabled_;
91 bool enabled_on_stderr_; // only used on POSIX for now 99 bool enabled_on_stderr_; // only used on POSIX for now
92 100
93 std::vector<LogData> queued_logs_; 101 std::vector<LogData> queued_logs_;
94 bool queue_invoke_later_pending_; 102 bool queue_invoke_later_pending_;
95 103
96 Message::Sender* sender_; 104 Message::Sender* sender_;
97 MessageLoop* main_thread_; 105 MessageLoop* main_thread_;
98 106
99 Consumer* consumer_; 107 Consumer* consumer_;
100 108
101 static LogFunction *log_function_mapping_; 109 static LogFunctionMap* log_function_map_;
102 }; 110 };
103 111
104 } // namespace IPC 112 } // namespace IPC
105 113
106 #endif // IPC_MESSAGE_LOG_ENABLED 114 #endif // IPC_MESSAGE_LOG_ENABLED
107 115
108 #endif // IPC_IPC_LOGGING_H_ 116 #endif // IPC_IPC_LOGGING_H_
OLDNEW
« no previous file with comments | « ipc/ipc_fuzzing_tests.cc ('k') | ipc/ipc_logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698