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

Side by Side Diff: ipc/ipc_logging.cc

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_logging.h ('k') | ipc/ipc_message.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "ipc/ipc_logging.h" 5 #include "ipc/ipc_logging.h"
6 6
7 #ifdef IPC_MESSAGE_LOG_ENABLED 7 #ifdef IPC_MESSAGE_LOG_ENABLED
8 // This will cause render_messages.h etc to define ViewMsgLog and friends.
9 #define IPC_MESSAGE_MACROS_LOG_ENABLED 8 #define IPC_MESSAGE_MACROS_LOG_ENABLED
10 #endif 9 #endif
11 10
12 #include "base/command_line.h" 11 #include "base/command_line.h"
13 #include "base/logging.h" 12 #include "base/logging.h"
14 #include "base/message_loop.h" 13 #include "base/message_loop.h"
15 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/string_number_conversions.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/thread.h" 17 #include "base/thread.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "ipc/ipc_switches.h" 19 #include "ipc/ipc_switches.h"
20 #include "ipc/ipc_sync_message.h" 20 #include "ipc/ipc_sync_message.h"
21 #include "ipc/ipc_message_utils.h" 21 #include "ipc/ipc_message_utils.h"
22 22
23 #if defined(OS_POSIX) 23 #if defined(OS_POSIX)
24 #include <unistd.h> 24 #include <unistd.h>
25 #endif 25 #endif
26 26
27 #ifdef IPC_MESSAGE_LOG_ENABLED 27 #ifdef IPC_MESSAGE_LOG_ENABLED
28 28
29 using base::Time; 29 using base::Time;
30 30
31 // IPC::Logging is allocated as a singleton, so we don't need any kind of 31 // IPC::Logging is allocated as a singleton, so we don't need any kind of
32 // special retention program. 32 // special retention program.
33 DISABLE_RUNNABLE_METHOD_REFCOUNT(IPC::Logging); 33 DISABLE_RUNNABLE_METHOD_REFCOUNT(IPC::Logging);
34 34
35 namespace IPC { 35 namespace IPC {
36 36
37 const int kLogSendDelayMs = 100; 37 const int kLogSendDelayMs = 100;
38 38
39 // We use a pointer to the function table to avoid any linker dependencies on 39 // We use a pointer to the function table to avoid any linker dependencies on
40 // all the traits used as IPC message parameters. 40 // all the traits used as IPC message parameters.
41 Logging::LogFunction *Logging::log_function_mapping_; 41 LogFunctionMap* Logging::log_function_map_;
42 42
43 Logging::Logging() 43 Logging::Logging()
44 : enabled_(false), 44 : enabled_(false),
45 enabled_on_stderr_(false), 45 enabled_on_stderr_(false),
46 queue_invoke_later_pending_(false), 46 queue_invoke_later_pending_(false),
47 sender_(NULL), 47 sender_(NULL),
48 main_thread_(MessageLoop::current()), 48 main_thread_(MessageLoop::current()),
49 consumer_(NULL) { 49 consumer_(NULL) {
50 #if defined(OS_WIN) 50 #if defined(OS_WIN)
51 // getenv triggers an unsafe warning. Simply check how big of a buffer 51 // getenv triggers an unsafe warning. Simply check how big of a buffer
(...skipping 11 matching lines...) Expand all
63 } 63 }
64 } 64 }
65 65
66 Logging::~Logging() { 66 Logging::~Logging() {
67 } 67 }
68 68
69 Logging* Logging::current() { 69 Logging* Logging::current() {
70 return Singleton<Logging>::get(); 70 return Singleton<Logging>::get();
71 } 71 }
72 72
73 void Logging::SetLoggerFunctions(LogFunction *functions) {
74 log_function_mapping_ = functions;
75 }
76
77 void Logging::SetConsumer(Consumer* consumer) { 73 void Logging::SetConsumer(Consumer* consumer) {
78 consumer_ = consumer; 74 consumer_ = consumer;
79 } 75 }
80 76
81 void Logging::Enable() { 77 void Logging::Enable() {
82 enabled_ = true; 78 enabled_ = true;
83 } 79 }
84 80
85 void Logging::Disable() { 81 void Logging::Disable() {
86 enabled_ = false; 82 enabled_ = false;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 Log(data); 153 Log(data);
158 } else { 154 } else {
159 main_thread_->PostTask(FROM_HERE, NewRunnableMethod( 155 main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
160 this, &Logging::Log, data)); 156 this, &Logging::Log, data));
161 } 157 }
162 } 158 }
163 159
164 void Logging::GetMessageText(uint32 type, std::string* name, 160 void Logging::GetMessageText(uint32 type, std::string* name,
165 const Message* message, 161 const Message* message,
166 std::string* params) { 162 std::string* params) {
167 if (!log_function_mapping_) 163 if (!log_function_map_)
168 return; 164 return;
169 165
170 int message_class = type >> 16; 166 LogFunctionMap::iterator it = log_function_map_->find(type);
171 if (log_function_mapping_[message_class] != NULL) { 167 if (it == log_function_map_->end()) {
172 log_function_mapping_[message_class](type, name, message, params); 168 if (name) {
173 } else { 169 *name = "[UNKNOWN MSG ";
174 DVLOG(1) << "No logger function associated with message class " 170 *name += base::IntToString(type);
175 << message_class; 171 *name += " ]";
172 }
173 return;
176 } 174 }
175
176 (*it->second)(name, message, params);
177 } 177 }
178 178
179 void Logging::Log(const LogData& data) { 179 void Logging::Log(const LogData& data) {
180 if (consumer_) { 180 if (consumer_) {
181 // We're in the browser process. 181 // We're in the browser process.
182 consumer_->Log(data); 182 consumer_->Log(data);
183 } else { 183 } else {
184 // We're in the renderer or plugin processes. 184 // We're in the renderer or plugin processes.
185 if (sender_) { 185 if (sender_) {
186 queued_logs_.push_back(data); 186 queued_logs_.push_back(data);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 data->receive = message.received_time(); 242 data->receive = message.received_time();
243 data->dispatch = Time::Now().ToInternalValue(); 243 data->dispatch = Time::Now().ToInternalValue();
244 data->params = params; 244 data->params = params;
245 data->message_name = message_name; 245 data->message_name = message_name;
246 } 246 }
247 } 247 }
248 248
249 } 249 }
250 250
251 #endif // IPC_MESSAGE_LOG_ENABLED 251 #endif // IPC_MESSAGE_LOG_ENABLED
OLDNEW
« no previous file with comments | « ipc/ipc_logging.h ('k') | ipc/ipc_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698