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

Side by Side Diff: ipc/ipc_logging.cc

Issue 2080423002: Remove calls to MessageLoop::current() in ipc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « ipc/ipc_logging.h ('k') | ipc/ipc_sync_channel_unittest.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #define IPC_MESSAGE_MACROS_LOG_ENABLED 8 #define IPC_MESSAGE_MACROS_LOG_ENABLED
9 #endif 9 #endif
10 10
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
22 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
23 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/threading/thread_task_runner_handle.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "ipc/ipc_message_utils.h" 26 #include "ipc/ipc_message_utils.h"
27 #include "ipc/ipc_sender.h" 27 #include "ipc/ipc_sender.h"
28 #include "ipc/ipc_switches.h" 28 #include "ipc/ipc_switches.h"
29 #include "ipc/ipc_sync_message.h" 29 #include "ipc/ipc_sync_message.h"
30 30
31 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
32 #include <unistd.h> 32 #include <unistd.h>
33 #endif 33 #endif
34 34
35 #ifdef IPC_MESSAGE_LOG_ENABLED 35 #ifdef IPC_MESSAGE_LOG_ENABLED
36 36
37 using base::Time; 37 using base::Time;
38 38
39 namespace IPC { 39 namespace IPC {
40 40
41 const int kLogSendDelayMs = 100; 41 const int kLogSendDelayMs = 100;
42 42
43 // We use a pointer to the function table to avoid any linker dependencies on 43 // We use a pointer to the function table to avoid any linker dependencies on
44 // all the traits used as IPC message parameters. 44 // all the traits used as IPC message parameters.
45 LogFunctionMap* Logging::log_function_map_; 45 LogFunctionMap* Logging::log_function_map_;
46 46
47 Logging::Logging() 47 Logging::Logging()
48 : enabled_(false), 48 : enabled_(false),
49 enabled_on_stderr_(false), 49 enabled_on_stderr_(false),
50 enabled_color_(false), 50 enabled_color_(false),
51 queue_invoke_later_pending_(false), 51 queue_invoke_later_pending_(false),
52 sender_(NULL), 52 sender_(NULL),
53 main_thread_(base::MessageLoop::current()), 53 main_thread_(base::ThreadTaskRunnerHandle::Get()),
54 consumer_(NULL) { 54 consumer_(NULL) {
55 #if defined(OS_WIN) 55 #if defined(OS_WIN)
56 // getenv triggers an unsafe warning. Simply check how big of a buffer 56 // getenv triggers an unsafe warning. Simply check how big of a buffer
57 // would be needed to fetch the value to see if the enviornment variable is 57 // would be needed to fetch the value to see if the enviornment variable is
58 // set. 58 // set.
59 size_t requiredSize = 0; 59 size_t requiredSize = 0;
60 getenv_s(&requiredSize, NULL, 0, "CHROME_IPC_LOGGING"); 60 getenv_s(&requiredSize, NULL, 0, "CHROME_IPC_LOGGING");
61 bool logging_env_var_set = (requiredSize != 0); 61 bool logging_env_var_set = (requiredSize != 0);
62 if (requiredSize <= 6) { 62 if (requiredSize <= 6) {
63 char buffer[6]; 63 char buffer[6];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 const std::string& channel_id) { 156 const std::string& channel_id) {
157 if (!Enabled() || 157 if (!Enabled() ||
158 !message.sent_time() || 158 !message.sent_time() ||
159 !message.received_time() || 159 !message.received_time() ||
160 message.dont_log()) 160 message.dont_log())
161 return; 161 return;
162 162
163 LogData data; 163 LogData data;
164 GenerateLogData(channel_id, message, &data, true); 164 GenerateLogData(channel_id, message, &data, true);
165 165
166 if (base::MessageLoop::current() == main_thread_) { 166 if (main_thread_->BelongsToCurrentThread()) {
167 Log(data); 167 Log(data);
168 } else { 168 } else {
169 main_thread_->task_runner()->PostTask( 169 main_thread_->PostTask(
170 FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data)); 170 FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data));
171 } 171 }
172 } 172 }
173 173
174 void Logging::GetMessageText(uint32_t type, std::string* name, 174 void Logging::GetMessageText(uint32_t type, std::string* name,
175 const Message* message, 175 const Message* message,
176 std::string* params) { 176 std::string* params) {
177 if (!log_function_map_) 177 if (!log_function_map_)
178 return; 178 return;
179 179
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 data->receive = message.received_time(); 310 data->receive = message.received_time();
311 data->dispatch = Time::Now().ToInternalValue(); 311 data->dispatch = Time::Now().ToInternalValue();
312 data->params = params; 312 data->params = params;
313 data->message_name = message_name; 313 data->message_name = message_name;
314 } 314 }
315 } 315 }
316 316
317 } 317 }
318 318
319 #endif // IPC_MESSAGE_LOG_ENABLED 319 #endif // IPC_MESSAGE_LOG_ENABLED
OLDNEW
« no previous file with comments | « ipc/ipc_logging.h ('k') | ipc/ipc_sync_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698