Chromium Code Reviews| Index: remoting/host/plugin/host_script_object.cc |
| diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc |
| index 5357cfb65a59e5dc8f04c41ee3bc403709f88eac..da4e9a53f983978a73910afb10c72404af9eda43 100644 |
| --- a/remoting/host/plugin/host_script_object.cc |
| +++ b/remoting/host/plugin/host_script_object.cc |
| @@ -72,6 +72,7 @@ const int kMaxLoginAttempts = 5; |
| // 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 bool g_has_registered_log_handler = false; |
| static HostNPScriptObject* g_logging_scriptable_object = NULL; |
| static logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| @@ -84,17 +85,10 @@ HostNPScriptObject::HostNPScriptObject(NPP plugin, NPObject* parent) |
| np_thread_id_(base::PlatformThread::CurrentId()), |
| failed_login_attempts_(0), |
| disconnected_event_(true, false) { |
| - // 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); |
| + // Register this script object as the one that will handle all logging calls |
| + // and display them to the user. |
| + // If multiple plugins are run, then the last one registered will handle all |
| + // logging for all instances. |
| g_logging_scriptable_object = this; |
| VLOG(2) << "HostNPScriptObject"; |
| @@ -109,8 +103,9 @@ HostNPScriptObject::~HostNPScriptObject() { |
| // tasks on the UI thread while we are stopping the host. |
| desktop_environment_->Shutdown(); |
| - logging::SetLogMessageHandler(g_logging_old_handler); |
| - g_logging_old_handler = NULL; |
| + // Unregister this script object for logging. |
| + // If there are multiple instances and this is the one that was registered |
| + // last, then all logging to the UI will be stopped. |
| g_logging_scriptable_object = NULL; |
| // Disconnect synchronously. We cannot disconnect asynchronously |
| @@ -532,6 +527,33 @@ void HostNPScriptObject::OnStateChanged(State state) { |
| } |
| // static |
| +void HostNPScriptObject::RegisterLogger() { |
| + DCHECK(!g_has_registered_log_handler); |
| + |
| + LOG(INFO) << "Registering global log handler"; |
| + |
| + // Record previous handler so we can call it in a chain. |
| + g_logging_old_handler = logging::GetLogMessageHandler(); |
| + |
| + // Set up log message handler. |
| + // Note that this will not log anything until a scriptable object instance |
| + // has been created to handle the log message display. |
| + logging::SetLogMessageHandler(&LogToUI); |
| + |
| + g_has_registered_log_handler = true; |
| +} |
| + |
| +// static |
| +void HostNPScriptObject::UnregisterLogger() { |
| + // Restore previous handler. |
| + logging::SetLogMessageHandler(g_logging_old_handler); |
| + g_logging_old_handler = NULL; |
| + g_has_registered_log_handler = false; |
| + |
| + LOG(INFO) << "Unregistering global log handler"; |
|
Wez
2011/08/16 00:05:45
Why not have these in host_plugin.cc, since that's
garykac
2011/08/16 00:19:40
Because having it here keeps all of the logic (and
Wez
2011/08/16 00:30:52
Could they live in their own code file? The only
garykac
2011/08/29 23:27:15
Done.
|
| +} |
| + |
| +// static |
| bool HostNPScriptObject::LogToUI(int severity, const char* file, int line, |
| size_t message_start, |
| const std::string& str) { |