Chromium Code Reviews| Index: remoting/client/plugin/chromoting_instance.cc |
| diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc |
| index 7ec07a49e0edb862c3bef755b55aab79e2618fb9..9df0a7e459e71951504e63d06862ec64ffa52cbd 100644 |
| --- a/remoting/client/plugin/chromoting_instance.cc |
| +++ b/remoting/client/plugin/chromoting_instance.cc |
| @@ -24,11 +24,12 @@ |
| #include "ppapi/cpp/rect.h" |
| // TODO(wez): Remove this when crbug.com/86353 is complete. |
| #include "ppapi/cpp/private/var_private.h" |
| +#include "remoting/base/task_thread_proxy.h" |
| +#include "remoting/base/util.h" |
| #include "remoting/client/client_config.h" |
| #include "remoting/client/chromoting_client.h" |
| #include "remoting/client/rectangle_update_decoder.h" |
| #include "remoting/client/plugin/chromoting_scriptable_object.h" |
| -#include "remoting/client/plugin/pepper_client_logger.h" |
| #include "remoting/client/plugin/pepper_input_handler.h" |
| #include "remoting/client/plugin/pepper_port_allocator_session.h" |
| #include "remoting/client/plugin/pepper_view.h" |
| @@ -49,20 +50,52 @@ |
| namespace remoting { |
| +// This flag blocks LOGs to the UI if we're already in the middle of logging |
| +// to the UI. This prevents a potential infinite loop if we encounter an error |
| +// while sending the log message to the UI. |
| +static bool g_logging_to_plugin = false; |
| +static ChromotingInstance* g_logging_instance = NULL; |
| +static TaskThreadProxy* g_logging_thread_proxy = NULL; |
|
Sergey Ulanov
2011/08/02 01:08:32
Don't need this.
garykac
2011/08/02 02:13:31
Done.
|
| +static logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| + |
| const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting"; |
| ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) |
| : pp::InstancePrivate(pp_instance), |
| initialized_(false), |
| - scale_to_fit_(false), |
| - logger_(this) { |
| + scale_to_fit_(false) { |
| RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
| RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| + |
| + log_proxy_ = new TaskThreadProxy(MessageLoop::current()); |
| + |
| + // Set up log message handler. |
| + // Note that this approach doesn't quite support having multiple instances |
| + // of Chromoting running. In that case, the most recently opened tab will |
| + // grab all the debug log messages, and when any Chromoting tab is closed |
| + // the logging handler will go away. |
| + // Since having multiple Chromoting tabs is not a primary use case, and this |
| + // is just debug logging, we're punting improving debug log support for that |
| + // case. |
| + if (g_logging_old_handler == NULL) |
| + g_logging_old_handler = logging::GetLogMessageHandler(); |
| + logging::SetLogMessageHandler(&LogToUI); |
| + g_logging_instance = this; |
| + g_logging_thread_proxy = log_proxy_.get(); |
| } |
| ChromotingInstance::~ChromotingInstance() { |
| DCHECK(CurrentlyOnPluginThread()); |
| + // Detach the log proxy so we don't log anything else to the UI. |
| + log_proxy_->Detach(); |
| + |
| + // Remove log message handler. |
| + logging::SetLogMessageHandler(g_logging_old_handler); |
| + g_logging_old_handler = NULL; |
| + g_logging_instance = NULL; |
| + g_logging_thread_proxy = NULL; |
| + |
| if (client_.get()) { |
| base::WaitableEvent done_event(true, false); |
| client_->Stop(base::Bind(&base::WaitableEvent::Signal, |
| @@ -83,7 +116,7 @@ bool ChromotingInstance::Init(uint32_t argc, |
| CHECK(!initialized_); |
| initialized_ = true; |
| - logger_.VLog(1, "Started ChromotingInstance::Init"); |
| + VLOG(1) << "Started ChromotingInstance::Init"; |
| // Start all the threads. |
| context_.Start(); |
| @@ -101,7 +134,7 @@ bool ChromotingInstance::Init(uint32_t argc, |
| // If we don't have socket dispatcher for IPC (e.g. P2P API is |
| // disabled), then JingleSessionManager will try to use physical sockets. |
| if (socket_dispatcher) { |
| - logger_.VLog(1, "Creating IpcNetworkManager and IpcPacketSocketFactory."); |
| + VLOG(1) << "Creating IpcNetworkManager and IpcPacketSocketFactory."; |
| network_manager = new IpcNetworkManager(socket_dispatcher); |
| socket_factory = new IpcPacketSocketFactory(socket_dispatcher); |
| } |
| @@ -130,9 +163,9 @@ void ChromotingInstance::Connect(const ClientConfig& config) { |
| client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), |
| view_proxy_, rectangle_decoder_.get(), |
| - input_handler_.get(), &logger_, NULL)); |
| + input_handler_.get(), NULL)); |
| - logger_.Log(logging::LOG_INFO, "Connecting."); |
| + LOG(INFO) << "Connecting."; |
| // Setup the XMPP Proxy. |
| ChromotingScriptableObject* scriptable_object = GetScriptableObject(); |
| @@ -144,7 +177,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) { |
| // Kick off the connection. |
| client_->Start(xmpp_proxy); |
| - logger_.Log(logging::LOG_INFO, "Connection status: Initializing"); |
| + LOG(INFO) << "Connection status: Initializing"; |
| GetScriptableObject()->SetConnectionInfo(STATUS_INITIALIZING, |
| QUALITY_UNKNOWN); |
| } |
| @@ -152,7 +185,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) { |
| void ChromotingInstance::Disconnect() { |
| DCHECK(CurrentlyOnPluginThread()); |
| - logger_.Log(logging::LOG_INFO, "Disconnecting from host."); |
| + LOG(INFO) << "Disconnecting from host."; |
| if (client_.get()) { |
| // TODO(sergeyu): Should we disconnect asynchronously? |
| base::WaitableEvent done_event(true, false); |
| @@ -219,14 +252,14 @@ bool ChromotingInstance::HandleInputEvent(const pp::InputEvent& event) { |
| case PP_INPUTEVENT_TYPE_KEYDOWN: { |
| pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); |
| - logger_.VLog(3, "PP_INPUTEVENT_TYPE_KEYDOWN key=%d", key.GetKeyCode()); |
| + VLOG(3) << "PP_INPUTEVENT_TYPE_KEYDOWN" << " key=" << key.GetKeyCode(); |
| pih->HandleKeyEvent(true, key); |
| return true; |
| } |
| case PP_INPUTEVENT_TYPE_KEYUP: { |
| pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); |
| - logger_.VLog(3, "PP_INPUTEVENT_TYPE_KEYUP key=%d", key.GetKeyCode()); |
| + VLOG(3) << "PP_INPUTEVENT_TYPE_KEYUP" << " key=" << key.GetKeyCode(); |
| pih->HandleKeyEvent(false, key); |
| return true; |
| } |
| @@ -252,8 +285,7 @@ ChromotingScriptableObject* ChromotingInstance::GetScriptableObject() { |
| DCHECK(so != NULL); |
| return static_cast<ChromotingScriptableObject*>(so); |
| } |
| - logger_.Log(logging::LOG_ERROR, |
| - "Unable to get ScriptableObject for Chromoting plugin."); |
| + LOG(ERROR) << "Unable to get ScriptableObject for Chromoting plugin."; |
| return NULL; |
| } |
| @@ -261,8 +293,7 @@ void ChromotingInstance::SubmitLoginInfo(const std::string& username, |
| const std::string& password) { |
| if (host_connection_->state() != |
| protocol::ConnectionToHost::STATE_CONNECTED) { |
| - logger_.Log(logging::LOG_INFO, |
| - "Client not connected or already authenticated."); |
| + LOG(INFO) << "Client not connected or already authenticated."; |
| return; |
| } |
| @@ -293,18 +324,33 @@ void ChromotingInstance::SetScaleToFit(bool scale_to_fit) { |
| rectangle_decoder_->RefreshFullFrame(); |
| } |
| -void ChromotingInstance::Log(int severity, const char* format, ...) { |
| - va_list ap; |
| - va_start(ap, format); |
| - logger_.va_Log(severity, format, ap); |
| - va_end(ap); |
| +// static |
| +bool ChromotingInstance::LogToUI(int severity, const char* file, int line, |
| + size_t message_start, |
| + const std::string& str) { |
| + if (g_logging_instance && g_logging_thread_proxy) { |
|
Sergey Ulanov
2011/08/02 01:08:32
don't need to verify g_logging_thread_proxy
garykac
2011/08/02 02:13:31
Done.
|
| + std::string message = remoting::GetTimestampString(); |
| + message += (str.c_str() + message_start); |
| + //g_logging_instance->LogToUI_CorrectThread(message); |
| + g_logging_thread_proxy->Call( |
|
Sergey Ulanov
2011/08/02 01:08:32
g_logging_instance->log_proxy->Call(...
garykac
2011/08/02 02:13:31
Done.
|
| + base::Bind(&ChromotingInstance::ProcessLogToUI, |
| + base::Unretained(g_logging_instance), message)); |
| + } |
| + |
| + if (g_logging_old_handler) |
| + return (g_logging_old_handler)(severity, file, line, message_start, str); |
| + return false; |
| } |
| -void ChromotingInstance::VLog(int verboselevel, const char* format, ...) { |
| - va_list ap; |
| - va_start(ap, format); |
| - logger_.va_VLog(verboselevel, format, ap); |
| - va_end(ap); |
| +void ChromotingInstance::ProcessLogToUI(const std::string& message) { |
| + if (!g_logging_to_plugin) { |
| + ChromotingScriptableObject* cso = GetScriptableObject(); |
| + if (cso) { |
| + g_logging_to_plugin = true; |
| + cso->LogDebugInfo(message); |
| + g_logging_to_plugin = false; |
| + } |
| + } |
| } |
| pp::Var ChromotingInstance::GetInstanceObject() { |