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

Side by Side Diff: remoting/client/plugin/chromoting_instance.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 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
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 "remoting/client/plugin/chromoting_instance.h" 5 #include "remoting/client/plugin/chromoting_instance.h"
6 6
7 #include <nacl_io/nacl_io.h> 7 #include <nacl_io/nacl_io.h>
8 #include <sys/mount.h> 8 #include <sys/mount.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 text_input_controller_(this), 163 text_input_controller_(this),
164 use_async_pin_dialog_(false), 164 use_async_pin_dialog_(false),
165 weak_factory_(this) { 165 weak_factory_(this) {
166 // In NaCl global resources need to be initialized differently because they 166 // In NaCl global resources need to be initialized differently because they
167 // are not shared with Chrome. 167 // are not shared with Chrome.
168 thread_task_runner_handle_.reset( 168 thread_task_runner_handle_.reset(
169 new base::ThreadTaskRunnerHandle(plugin_task_runner_)); 169 new base::ThreadTaskRunnerHandle(plugin_task_runner_));
170 thread_wrapper_ = 170 thread_wrapper_ =
171 jingle_glue::JingleThreadWrapper::WrapTaskRunner(plugin_task_runner_); 171 jingle_glue::JingleThreadWrapper::WrapTaskRunner(plugin_task_runner_);
172 172
173 // Register a global log handler. 173 // Register a log listener.
174 ChromotingInstance::RegisterLogMessageHandler(); 174 log_to_ui_ = base::MakeUnique<LogToUI>();
175 175
176 nacl_io_init_ppapi(pp_instance, pp::Module::Get()->get_browser_interface()); 176 nacl_io_init_ppapi(pp_instance, pp::Module::Get()->get_browser_interface());
177 mount("", "/etc", "memfs", 0, ""); 177 mount("", "/etc", "memfs", 0, "");
178 mount("", "/usr", "memfs", 0, ""); 178 mount("", "/usr", "memfs", 0, "");
179 179
180 // Register for mouse, wheel and keyboard events. 180 // Register for mouse, wheel and keyboard events.
181 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); 181 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
182 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 182 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
183 183
184 // Disable the client-side IME in Chrome. 184 // Disable the client-side IME in Chrome.
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 data->SetDouble("maxEncodeLatency", perf_tracker_.video_encode_ms().Max()); 1030 data->SetDouble("maxEncodeLatency", perf_tracker_.video_encode_ms().Max());
1031 data->SetDouble("decodeLatency", perf_tracker_.video_decode_ms().Average()); 1031 data->SetDouble("decodeLatency", perf_tracker_.video_decode_ms().Average());
1032 data->SetDouble("maxDecodeLatency", perf_tracker_.video_decode_ms().Max()); 1032 data->SetDouble("maxDecodeLatency", perf_tracker_.video_decode_ms().Max());
1033 data->SetDouble("renderLatency", perf_tracker_.video_paint_ms().Average()); 1033 data->SetDouble("renderLatency", perf_tracker_.video_paint_ms().Average());
1034 data->SetDouble("maxRenderLatency", perf_tracker_.video_paint_ms().Max()); 1034 data->SetDouble("maxRenderLatency", perf_tracker_.video_paint_ms().Max());
1035 data->SetDouble("roundtripLatency", perf_tracker_.round_trip_ms().Average()); 1035 data->SetDouble("roundtripLatency", perf_tracker_.round_trip_ms().Average());
1036 data->SetDouble("maxRoundtripLatency", perf_tracker_.round_trip_ms().Max()); 1036 data->SetDouble("maxRoundtripLatency", perf_tracker_.round_trip_ms().Max());
1037 PostLegacyJsonMessage("onPerfStats", std::move(data)); 1037 PostLegacyJsonMessage("onPerfStats", std::move(data));
1038 } 1038 }
1039 1039
1040 // static
1041 void ChromotingInstance::RegisterLogMessageHandler() {
1042 base::AutoLock lock(g_logging_lock.Get());
1043
1044 // Set up log message handler.
1045 // This is not thread-safe so we need it within our lock.
1046 logging::SetLogMessageHandler(&LogToUI);
1047 }
1048
1049 void ChromotingInstance::RegisterLoggingInstance() { 1040 void ChromotingInstance::RegisterLoggingInstance() {
1050 base::AutoLock lock(g_logging_lock.Get()); 1041 base::AutoLock lock(g_logging_lock.Get());
1051 g_logging_instance = pp_instance(); 1042 g_logging_instance = pp_instance();
1052 } 1043 }
1053 1044
1054 void ChromotingInstance::UnregisterLoggingInstance() { 1045 void ChromotingInstance::UnregisterLoggingInstance() {
1055 base::AutoLock lock(g_logging_lock.Get()); 1046 base::AutoLock lock(g_logging_lock.Get());
1056 1047
1057 // Don't unregister unless we're the currently registered instance. 1048 // Don't unregister unless we're the currently registered instance.
1058 if (pp_instance() != g_logging_instance) 1049 if (pp_instance() != g_logging_instance)
1059 return; 1050 return;
1060 1051
1061 // Unregister this instance for logging. 1052 // Unregister this instance for logging.
1062 g_logging_instance = 0; 1053 g_logging_instance = 0;
1063 } 1054 }
1064 1055
1065 // static 1056 class LogToUI : logging::LogMessageListener {
1066 bool ChromotingInstance::LogToUI(int severity, const char* file, int line, 1057 public:
1067 size_t message_start, 1058 void OnMessage(int severity,
1068 const std::string& str) { 1059 const char* file,
1060 int line,
1061 size_t message_start,
1062 const std::string& str) override;
1063 };
1064
1065 void LogToUI::OnMessage(int severity,
1066 const char* file,
1067 int line,
1068 size_t message_start,
1069 const std::string& str) {
1069 PP_LogLevel log_level = PP_LOGLEVEL_ERROR; 1070 PP_LogLevel log_level = PP_LOGLEVEL_ERROR;
1070 switch (severity) { 1071 switch (severity) {
1071 case logging::LOG_INFO: 1072 case logging::LOG_INFO:
1072 log_level = PP_LOGLEVEL_TIP; 1073 log_level = PP_LOGLEVEL_TIP;
1073 break; 1074 break;
1074 case logging::LOG_WARNING: 1075 case logging::LOG_WARNING:
1075 log_level = PP_LOGLEVEL_WARNING; 1076 log_level = PP_LOGLEVEL_WARNING;
1076 break; 1077 break;
1077 case logging::LOG_ERROR: 1078 case logging::LOG_ERROR:
1078 case logging::LOG_FATAL: 1079 case logging::LOG_FATAL:
(...skipping 12 matching lines...) Expand all
1091 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); 1092 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
1092 if (console) 1093 if (console)
1093 console->Log(pp_instance, log_level, pp::Var(str).pp_var()); 1094 console->Log(pp_instance, log_level, pp::Var(str).pp_var());
1094 } 1095 }
1095 1096
1096 // If this is a fatal message the log handler is going to crash after this 1097 // If this is a fatal message the log handler is going to crash after this
1097 // function returns. In that case sleep for 1 second, Otherwise the plugin 1098 // function returns. In that case sleep for 1 second, Otherwise the plugin
1098 // may crash before the message is delivered to the console. 1099 // may crash before the message is delivered to the console.
1099 if (severity == logging::LOG_FATAL) 1100 if (severity == logging::LOG_FATAL)
1100 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 1101 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
1101
1102 return false;
1103 } 1102 }
1104 1103
1105 bool ChromotingInstance::IsConnected() { 1104 bool ChromotingInstance::IsConnected() {
1106 return client_ && 1105 return client_ &&
1107 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); 1106 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED);
1108 } 1107 }
1109 1108
1110 void ChromotingInstance::UpdateUmaEnumHistogram( 1109 void ChromotingInstance::UpdateUmaEnumHistogram(
1111 const std::string& histogram_name, 1110 const std::string& histogram_name,
1112 int64_t value, 1111 int64_t value,
(...skipping 14 matching lines...) Expand all
1127 if (is_custom_counts_histogram) { 1126 if (is_custom_counts_histogram) {
1128 uma.HistogramCustomCounts(histogram_name, value, histogram_min, 1127 uma.HistogramCustomCounts(histogram_name, value, histogram_min,
1129 histogram_max, histogram_buckets); 1128 histogram_max, histogram_buckets);
1130 } else { 1129 } else {
1131 uma.HistogramCustomTimes(histogram_name, value, histogram_min, 1130 uma.HistogramCustomTimes(histogram_name, value, histogram_min,
1132 histogram_max, histogram_buckets); 1131 histogram_max, histogram_buckets);
1133 } 1132 }
1134 } 1133 }
1135 1134
1136 } // namespace remoting 1135 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/chromoting_instance.h ('k') | remoting/host/it2me/it2me_native_messaging_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698