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

Unified Diff: remoting/host/plugin/host_script_object.cc

Issue 7648042: Change Chromoting logger to be setup in plugin's NP_Initialize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove comment Created 9 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 side-by-side diff with in-line comments
Download patch
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 d1f65af2b9e86fd0e1b00ea324e6a3b63ca4fbf0..a4b05c04bf227728bb7e666c7f77b4212c02e239 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -11,13 +11,13 @@
#include "base/threading/platform_thread.h"
#include "base/utf_string_conversions.h"
#include "remoting/base/auth_token_util.h"
-#include "remoting/base/util.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/in_memory_host_config.h"
+#include "remoting/host/plugin/host_log_handler.h"
#include "remoting/host/plugin/policy_hack/nat_policy.h"
#include "remoting/host/register_support_host_request.h"
#include "remoting/host/support_access_verifier.h"
@@ -73,13 +73,6 @@ const int kMaxLoginAttempts = 5;
} // namespace
-// 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 HostNPScriptObject* g_logging_scriptable_object = NULL;
-static logging::LogMessageHandlerFunction g_logging_old_handler = NULL;
-
HostNPScriptObject::HostNPScriptObject(
NPP plugin,
NPObject* parent,
@@ -95,18 +88,6 @@ HostNPScriptObject::HostNPScriptObject(
disconnected_event_(true, false),
nat_traversal_enabled_(false),
policy_received_(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);
- g_logging_scriptable_object = this;
}
HostNPScriptObject::~HostNPScriptObject() {
@@ -116,9 +97,7 @@ 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;
- g_logging_scriptable_object = NULL;
+ HostLogHandler::UnregisterLoggingScriptObject(this);
plugin_message_loop_proxy_->Detach();
@@ -288,6 +267,7 @@ bool HostNPScriptObject::SetProperty(const std::string& property_name,
if (property_name == kAttrNameLogDebugInfo) {
if (NPVARIANT_IS_OBJECT(*value)) {
log_debug_info_func_ = NPVARIANT_TO_OBJECT(*value);
+ HostLogHandler::RegisterLoggingScriptObject(this);
return true;
} else {
SetException("SetProperty: unexpected type for property " +
@@ -602,40 +582,25 @@ void HostNPScriptObject::OnStateChanged(State state) {
}
}
-// static
-bool HostNPScriptObject::LogToUI(int severity, const char* file, int line,
- size_t message_start,
- const std::string& str) {
- // The |g_logging_to_plugin| check is to prevent logging to the scriptable
- // object if we're already in the middle of logging.
- // This can occur if we try to log an error while we're in the scriptable
- // object logging code.
- if (g_logging_scriptable_object && !g_logging_to_plugin) {
- g_logging_to_plugin = true;
- std::string message = remoting::GetTimestampString();
- message += (str.c_str() + message_start);
- g_logging_scriptable_object->LogDebugInfo(message);
- g_logging_to_plugin = false;
- }
- if (g_logging_old_handler)
- return (g_logging_old_handler)(severity, file, line, message_start, str);
- return false;
+void HostNPScriptObject::PostLogDebugInfo(const std::string& message) {
+ // Always post (even if we're already on the correct thread) so that debug
+ // log messages aren't shown out of order.
+ plugin_message_loop_proxy_->PostTask(
+ FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo,
+ base::Unretained(this), message));
}
void HostNPScriptObject::LogDebugInfo(const std::string& message) {
- if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) {
- plugin_message_loop_proxy_->PostTask(
- FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo,
- base::Unretained(this), message));
- return;
- }
-
if (log_debug_info_func_.get()) {
NPVariant log_message;
STRINGZ_TO_NPVARIANT(message.c_str(), log_message);
bool is_good = InvokeAndIgnoreResult(log_debug_info_func_.get(),
&log_message, 1);
- LOG_IF(ERROR, !is_good) << "LogDebugInfo failed";
+ if (!is_good) {
+ // Note that we can't use LOG here because we're currently in the middle
+ // of handling a LOG message.
+ printf("ERROR - LogDebugInfo failed\n");
Wez 2011/08/30 05:20:02 If we place a check around the invokation to prote
garykac 2011/08/31 00:59:00 Our log message handler is asynchronous, so any fl
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698