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

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: address comments, deque for listeners, reentrant test Created 4 years, 4 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 data->SetDouble("maxEncodeLatency", perf_tracker_.video_encode_ms().Max()); 1029 data->SetDouble("maxEncodeLatency", perf_tracker_.video_encode_ms().Max());
1030 data->SetDouble("decodeLatency", perf_tracker_.video_decode_ms().Average()); 1030 data->SetDouble("decodeLatency", perf_tracker_.video_decode_ms().Average());
1031 data->SetDouble("maxDecodeLatency", perf_tracker_.video_decode_ms().Max()); 1031 data->SetDouble("maxDecodeLatency", perf_tracker_.video_decode_ms().Max());
1032 data->SetDouble("renderLatency", perf_tracker_.video_paint_ms().Average()); 1032 data->SetDouble("renderLatency", perf_tracker_.video_paint_ms().Average());
1033 data->SetDouble("maxRenderLatency", perf_tracker_.video_paint_ms().Max()); 1033 data->SetDouble("maxRenderLatency", perf_tracker_.video_paint_ms().Max());
1034 data->SetDouble("roundtripLatency", perf_tracker_.round_trip_ms().Average()); 1034 data->SetDouble("roundtripLatency", perf_tracker_.round_trip_ms().Average());
1035 data->SetDouble("maxRoundtripLatency", perf_tracker_.round_trip_ms().Max()); 1035 data->SetDouble("maxRoundtripLatency", perf_tracker_.round_trip_ms().Max());
1036 PostLegacyJsonMessage("onPerfStats", std::move(data)); 1036 PostLegacyJsonMessage("onPerfStats", std::move(data));
1037 } 1037 }
1038 1038
1039 // static
1040 void ChromotingInstance::RegisterLogMessageHandler() {
1041 base::AutoLock lock(g_logging_lock.Get());
1042
1043 // Set up log message handler.
1044 // This is not thread-safe so we need it within our lock.
1045 logging::SetLogMessageHandler(&LogToUI);
1046 }
1047
1048 void ChromotingInstance::RegisterLoggingInstance() { 1039 void ChromotingInstance::RegisterLoggingInstance() {
1049 base::AutoLock lock(g_logging_lock.Get()); 1040 base::AutoLock lock(g_logging_lock.Get());
1050 g_logging_instance = pp_instance(); 1041 g_logging_instance = pp_instance();
1051 } 1042 }
1052 1043
1053 void ChromotingInstance::UnregisterLoggingInstance() { 1044 void ChromotingInstance::UnregisterLoggingInstance() {
1054 base::AutoLock lock(g_logging_lock.Get()); 1045 base::AutoLock lock(g_logging_lock.Get());
1055 1046
1056 // Don't unregister unless we're the currently registered instance. 1047 // Don't unregister unless we're the currently registered instance.
1057 if (pp_instance() != g_logging_instance) 1048 if (pp_instance() != g_logging_instance)
1058 return; 1049 return;
1059 1050
1060 // Unregister this instance for logging. 1051 // Unregister this instance for logging.
1061 g_logging_instance = 0; 1052 g_logging_instance = 0;
1062 } 1053 }
1063 1054
1064 // static 1055 class LogToUI : logging::LogMessageListener {
1065 bool ChromotingInstance::LogToUI(int severity, const char* file, int line, 1056 public:
1066 size_t message_start, 1057 void OnMessage(int severity,
1067 const std::string& str) { 1058 const char* file,
1059 int line,
1060 size_t message_start,
1061 const std::string& str) override;
1062 };
1063
1064 void LogToUI::OnMessage(int severity,
1065 const char* file,
1066 int line,
1067 size_t message_start,
1068 const std::string& str) {
1068 PP_LogLevel log_level = PP_LOGLEVEL_ERROR; 1069 PP_LogLevel log_level = PP_LOGLEVEL_ERROR;
1069 switch (severity) { 1070 switch (severity) {
1070 case logging::LOG_INFO: 1071 case logging::LOG_INFO:
1071 log_level = PP_LOGLEVEL_TIP; 1072 log_level = PP_LOGLEVEL_TIP;
1072 break; 1073 break;
1073 case logging::LOG_WARNING: 1074 case logging::LOG_WARNING:
1074 log_level = PP_LOGLEVEL_WARNING; 1075 log_level = PP_LOGLEVEL_WARNING;
1075 break; 1076 break;
1076 case logging::LOG_ERROR: 1077 case logging::LOG_ERROR:
1077 case logging::LOG_FATAL: 1078 case logging::LOG_FATAL:
(...skipping 12 matching lines...) Expand all
1090 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); 1091 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
1091 if (console) 1092 if (console)
1092 console->Log(pp_instance, log_level, pp::Var(str).pp_var()); 1093 console->Log(pp_instance, log_level, pp::Var(str).pp_var());
1093 } 1094 }
1094 1095
1095 // If this is a fatal message the log handler is going to crash after this 1096 // If this is a fatal message the log handler is going to crash after this
1096 // function returns. In that case sleep for 1 second, Otherwise the plugin 1097 // function returns. In that case sleep for 1 second, Otherwise the plugin
1097 // may crash before the message is delivered to the console. 1098 // may crash before the message is delivered to the console.
1098 if (severity == logging::LOG_FATAL) 1099 if (severity == logging::LOG_FATAL)
1099 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); 1100 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
1100
1101 return false;
1102 } 1101 }
1103 1102
1104 bool ChromotingInstance::IsConnected() { 1103 bool ChromotingInstance::IsConnected() {
1105 return client_ && 1104 return client_ &&
1106 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); 1105 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED);
1107 } 1106 }
1108 1107
1109 void ChromotingInstance::UpdateUmaEnumHistogram( 1108 void ChromotingInstance::UpdateUmaEnumHistogram(
1110 const std::string& histogram_name, 1109 const std::string& histogram_name,
1111 int64_t value, 1110 int64_t value,
(...skipping 14 matching lines...) Expand all
1126 if (is_custom_counts_histogram) { 1125 if (is_custom_counts_histogram) {
1127 uma.HistogramCustomCounts(histogram_name, value, histogram_min, 1126 uma.HistogramCustomCounts(histogram_name, value, histogram_min,
1128 histogram_max, histogram_buckets); 1127 histogram_max, histogram_buckets);
1129 } else { 1128 } else {
1130 uma.HistogramCustomTimes(histogram_name, value, histogram_min, 1129 uma.HistogramCustomTimes(histogram_name, value, histogram_min,
1131 histogram_max, histogram_buckets); 1130 histogram_max, histogram_buckets);
1132 } 1131 }
1133 } 1132 }
1134 1133
1135 } // namespace remoting 1134 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698