summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgarykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-04 03:19:35 +0000
committergarykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-04 03:19:35 +0000
commit82d105ecf3aadbb90e0adf80f857533967e8f383 (patch)
tree4dde11c5e525a813ec2dc847e10c1478c7291453
parent05130153c2e1f772955484f89169e505f809ba43 (diff)
downloadchromium_src-82d105ecf3aadbb90e0adf80f857533967e8f383.zip
chromium_src-82d105ecf3aadbb90e0adf80f857533967e8f383.tar.gz
chromium_src-82d105ecf3aadbb90e0adf80f857533967e8f383.tar.bz2
Modify Chromoting logging to hook into base logging.
BUG=none TEST=none Review URL: http://codereview.chromium.org/7355011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95380 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/base/logger.cc95
-rw-r--r--remoting/base/logger.h51
-rw-r--r--remoting/base/task_thread_proxy.cc34
-rw-r--r--remoting/base/task_thread_proxy.h50
-rw-r--r--remoting/base/util.cc14
-rw-r--r--remoting/base/util.h2
-rw-r--r--remoting/client/chromoting_client.cc11
-rw-r--r--remoting/client/chromoting_client.h3
-rw-r--r--remoting/client/plugin/chromoting_instance.cc99
-rw-r--r--remoting/client/plugin/chromoting_instance.h21
-rw-r--r--remoting/client/plugin/chromoting_scriptable_object.cc26
-rw-r--r--remoting/client/plugin/pepper_client_logger.cc28
-rw-r--r--remoting/client/plugin/pepper_client_logger.h33
-rw-r--r--remoting/client/plugin/pepper_view.cc19
-rw-r--r--remoting/host/chromoting_host.cc30
-rw-r--r--remoting/host/chromoting_host.h8
-rw-r--r--remoting/host/chromoting_host_unittest.cc6
-rw-r--r--remoting/host/plugin/host_plugin_logger.cc22
-rw-r--r--remoting/host/plugin/host_plugin_logger.h29
-rw-r--r--remoting/host/plugin/host_script_object.cc75
-rw-r--r--remoting/host/plugin/host_script_object.h14
-rw-r--r--remoting/host/simple_host_process.cc7
-rw-r--r--remoting/remoting.gyp8
23 files changed, 288 insertions, 397 deletions
diff --git a/remoting/base/logger.cc b/remoting/base/logger.cc
deleted file mode 100644
index 714ad20..0000000
--- a/remoting/base/logger.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/base/logger.h"
-
-#include <stdarg.h> // va_list
-
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/stringprintf.h"
-
-namespace remoting {
-
-// Copied from base/logging.cc.
-const char* const Logger::log_severity_names[logging::LOG_NUM_SEVERITIES] = {
- "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL"
-};
-
-Logger::Logger()
- : message_loop_(NULL) {
-}
-
-Logger::~Logger() {
-}
-
-void Logger::Log(logging::LogSeverity severity, const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- va_Log(severity, format, ap);
- va_end(ap);
-}
-
-void Logger::VLog(int verboselevel, const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- va_VLog(verboselevel, format, ap);
- va_end(ap);
-}
-
-void Logger::va_Log(logging::LogSeverity severity,
- const char* format, va_list ap) {
- DCHECK(severity >= 0 && severity <= logging::LOG_NUM_SEVERITIES);
-
- // Based in LOG_IS_ON macro in base/logging.h.
- if (severity >= ::logging::GetMinLogLevel()) {
- std::string message;
- base::StringAppendV(&message, format, ap);
-
- // Standard logging.
- logging::LogMessage(__FILE__, __LINE__, severity).stream() << message;
-
- // Send log message to the host UI.
- LogToUI_CorrectThread(StringPrintf("LOG(%s) %s",
- log_severity_names[severity],
- message.c_str()));
- }
-
- va_end(ap);
-}
-
-void Logger::va_VLog(int verboselevel,
- const char* format,
- va_list ap) {
- if (VLOG_IS_ON(verboselevel)) {
- std::string message;
- base::StringAppendV(&message, format, ap);
-
- // Standard verbose logging.
- VLOG(verboselevel) << message;
-
- // Send log message to the host UI.
- LogToUI_CorrectThread(StringPrintf("VLOG(%d) %s",
- verboselevel, message.c_str()));
- }
-}
-
-void Logger::LogToUI_CorrectThread(const std::string& message) {
- if (!message_loop_)
- return;
-
- if (message_loop_ != MessageLoop::current()) {
- message_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &Logger::LogToUI_CorrectThread, message));
- return;
- }
-
- LogToUI(message);
-}
-
-void Logger::LogToUI(const std::string& message) {
-}
-
-} // namespace remoting
diff --git a/remoting/base/logger.h b/remoting/base/logger.h
deleted file mode 100644
index 73c41cf..0000000
--- a/remoting/base/logger.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_BASE_LOGGER_H_
-#define REMOTING_BASE_LOGGER_H_
-
-#include "base/basictypes.h"
-#include "base/task.h"
-
-class MessageLoop;
-
-namespace remoting {
-
-class Logger {
- public:
- Logger();
- virtual ~Logger();
-
- void SetThread(MessageLoop* message_loop) {
- message_loop_ = message_loop;
- }
-
- void Log(logging::LogSeverity severity, const char* format, ...);
- void VLog(int verboselevel, const char* format, ...);
-
- void va_Log(logging::LogSeverity severity, const char* format, va_list ap);
- void va_VLog(int verboselevel, const char* format, va_list ap);
-
- protected:
- // Log to the UI after switching to the correct thread.
- void LogToUI_CorrectThread(const std::string& message);
-
- virtual void LogToUI(const std::string& message);
-
- static const char* const log_severity_names[];
-
- // We want all the log messages to be posted to the same thread so that:
- // (1) they are queued up in-order, and
- // (2) we don't try to update the log at the same time from multiple threads.
- MessageLoop* message_loop_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(Logger);
-};
-
-} // namespace remoting
-
-DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::Logger);
-
-#endif // REMOTING_BASE_LOGGER_H_
diff --git a/remoting/base/task_thread_proxy.cc b/remoting/base/task_thread_proxy.cc
new file mode 100644
index 0000000..d379620
--- /dev/null
+++ b/remoting/base/task_thread_proxy.cc
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/base/task_thread_proxy.h"
+
+#include "base/bind.h"
+
+namespace remoting {
+
+TaskThreadProxy::TaskThreadProxy(MessageLoop* loop)
+ : message_loop_(loop) {
+}
+
+TaskThreadProxy::~TaskThreadProxy() {
+}
+
+void TaskThreadProxy::Detach() {
+ message_loop_ = NULL;
+}
+
+void TaskThreadProxy::Call(const base::Closure& closure) {
+ if (message_loop_) {
+ message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &TaskThreadProxy::CallClosure, closure));
+ }
+}
+
+void TaskThreadProxy::CallClosure(const base::Closure& closure) {
+ if (message_loop_)
+ closure.Run();
+}
+
+} // namespace remoting
diff --git a/remoting/base/task_thread_proxy.h b/remoting/base/task_thread_proxy.h
new file mode 100644
index 0000000..67ccc2d
--- /dev/null
+++ b/remoting/base/task_thread_proxy.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_BASE_TASK_THREAD_PROXY_H_
+#define REMOTING_BASE_TASK_THREAD_PROXY_H_
+
+#include "base/message_loop.h"
+
+namespace remoting {
+
+// This is a refcounted class that is used to switch to the appropriate thread
+// before running a task on a target object. It should be used whenever you
+// need to post to an object, but:
+// (1) You don't know when the object might be deleted, and
+// (2) You cannot subclass the target from RefCountedThreadSafe.
+//
+// Example usage:
+// Instead of:
+// MyClass* obj;
+// obj->Method(param);
+// Use:
+// proxy->Call(base::Bind(&MyClass::Method,
+// base::Unretained(obj),
+// param);
+class TaskThreadProxy : public base::RefCountedThreadSafe<TaskThreadProxy> {
+ public:
+ TaskThreadProxy(MessageLoop* loop);
+
+ // Detach should be called when the target of the posted task is being
+ // destroyed.
+ void Detach();
+
+ void Call(const base::Closure& closure);
+
+ private:
+ friend class base::RefCountedThreadSafe<TaskThreadProxy>;
+
+ virtual ~TaskThreadProxy();
+
+ void CallClosure(const base::Closure& closure);
+
+ MessageLoop* message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskThreadProxy);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_TASK_THREAD_PROXY_H_
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index 2e7d7df..8671eeb 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -2,16 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "base/time.h"
#include "media/base/video_frame.h"
#include "media/base/yuv_convert.h"
#include "remoting/base/util.h"
-#include "base/logging.h"
-
using media::VideoFrame;
namespace remoting {
+std::string GetTimestampString() {
+ base::Time t = base::Time::NowFromSystemTime();
+ base::Time::Exploded tex;
+ t.LocalExplode(&tex);
+ return StringPrintf("%02d%02d/%02d%02d%02d:",
+ tex.month, tex.day_of_month,
+ tex.hour, tex.minute, tex.second);
+}
+
int GetBytesPerPixel(VideoFrame::Format format) {
// Note: The order is important here for performance. This is sorted from the
// most common to the less common (PIXEL_FORMAT_ASCII is mostly used
diff --git a/remoting/base/util.h b/remoting/base/util.h
index bd0f95c..d0e0b0d 100644
--- a/remoting/base/util.h
+++ b/remoting/base/util.h
@@ -10,6 +10,8 @@
namespace remoting {
+std::string GetTimestampString();
+
// TODO(sergeyu): Move these methods to media.
int GetBytesPerPixel(media::VideoFrame::Format format);
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
index f7dd7c8..130e398 100644
--- a/remoting/client/chromoting_client.cc
+++ b/remoting/client/chromoting_client.cc
@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/message_loop.h"
-#include "remoting/base/logger.h"
#include "remoting/base/tracer.h"
#include "remoting/client/chromoting_view.h"
#include "remoting/client/client_context.h"
@@ -23,7 +22,6 @@ ChromotingClient::ChromotingClient(const ClientConfig& config,
ChromotingView* view,
RectangleUpdateDecoder* rectangle_decoder,
InputHandler* input_handler,
- Logger* logger,
Task* client_done)
: config_(config),
context_(context),
@@ -31,7 +29,6 @@ ChromotingClient::ChromotingClient(const ClientConfig& config,
view_(view),
rectangle_decoder_(rectangle_decoder),
input_handler_(input_handler),
- logger_(logger),
client_done_(client_done),
state_(CREATED),
packet_being_processed_(false),
@@ -167,18 +164,18 @@ void ChromotingClient::DispatchPacket() {
}
void ChromotingClient::OnConnectionOpened(protocol::ConnectionToHost* conn) {
- logger_->VLog(1, "ChromotingClient::OnConnectionOpened");
+ VLOG(1) << "ChromotingClient::OnConnectionOpened";
Initialize();
SetConnectionState(CONNECTED);
}
void ChromotingClient::OnConnectionClosed(protocol::ConnectionToHost* conn) {
- logger_->VLog(1, "ChromotingClient::OnConnectionClosed");
+ VLOG(1) << "ChromotingClient::OnConnectionClosed";
SetConnectionState(DISCONNECTED);
}
void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) {
- logger_->VLog(1, "ChromotingClient::OnConnectionFailed");
+ VLOG(1) << "ChromotingClient::OnConnectionFailed";
SetConnectionState(FAILED);
}
@@ -262,7 +259,7 @@ void ChromotingClient::BeginSessionResponse(
return;
}
- logger_->Log(logging::LOG_INFO, "BeginSessionResponse received");
+ LOG(INFO) << "BeginSessionResponse received";
// Inform the connection that the client has been authenticated. This will
// enable the communication channels.
diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h
index 8819703..45d103d 100644
--- a/remoting/client/chromoting_client.h
+++ b/remoting/client/chromoting_client.h
@@ -31,7 +31,6 @@ class NotifyResolutionRequest;
class ClientContext;
class InputHandler;
-class Logger;
class RectangleUpdateDecoder;
// TODO(sergeyu): Move VideoStub implementation to RectangleUpdateDecoder.
@@ -46,7 +45,6 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
ChromotingView* view,
RectangleUpdateDecoder* rectangle_decoder,
InputHandler* input_handler,
- Logger* logger,
Task* client_done);
virtual ~ChromotingClient();
@@ -109,7 +107,6 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
ChromotingView* view_;
RectangleUpdateDecoder* rectangle_decoder_;
InputHandler* input_handler_;
- Logger* logger_;
// If non-NULL, this is called when the client is done.
Task* client_done_;
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index a9c1c1e..6fabb24 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -27,11 +27,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"
@@ -63,23 +64,52 @@ PPP_PolicyUpdate_Dev ChromotingInstance::kPolicyUpdatedInterface = {
&ChromotingInstance::PolicyUpdatedThunk,
};
+// 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 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),
enable_client_nat_traversal_(false),
initial_policy_received_(false),
task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
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;
}
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;
+
if (client_.get()) {
base::WaitableEvent done_event(true, false);
client_->Stop(base::Bind(&base::WaitableEvent::Signal,
@@ -100,7 +130,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();
@@ -126,8 +156,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) {
// occurs before the enterprise policy is read. We are guaranteed that the
// enterprise policy is pushed at least once, we we delay the connect call.
if (!initial_policy_received_) {
- logger_.Log(logging::LOG_INFO,
- "Delaying connect until initial policy is read.");
+ LOG(INFO) << "Delaying connect until initial policy is read.";
delayed_connect_.reset(
task_factory_.NewRunnableMethod(&ChromotingInstance::Connect,
config));
@@ -148,7 +177,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) {
// 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);
}
@@ -162,9 +191,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();
@@ -176,7 +205,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);
}
@@ -184,7 +213,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);
@@ -258,14 +287,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;
}
@@ -291,8 +320,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;
}
@@ -300,8 +328,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;
}
@@ -332,18 +359,32 @@ 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) {
+ std::string message = remoting::GetTimestampString();
+ message += (str.c_str() + message_start);
+ g_logging_instance->log_proxy_->Call(
+ 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() {
@@ -400,13 +441,13 @@ bool ChromotingInstance::IsNatTraversalAllowed(
policy_json, true, &error_code, &error_message));
if (!policy.get()) {
- logger_.Log(logging::LOG_ERROR, "Error %d parsing policy: %s.",
- error_code, error_message.c_str());
+ LOG(ERROR) << "Error " << error_code << " parsing policy: "
+ << error_message << ".";
return false;
}
if (!policy->IsType(base::Value::TYPE_DICTIONARY)) {
- logger_.Log(logging::LOG_ERROR, "Policy must be a dictionary");
+ LOG(ERROR) << "Policy must be a dictionary";
return false;
}
diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h
index 787713a..e700893 100644
--- a/remoting/client/plugin/chromoting_instance.h
+++ b/remoting/client/plugin/chromoting_instance.h
@@ -21,11 +21,8 @@
#include "ppapi/cpp/private/instance_private.h"
#include "remoting/client/client_context.h"
#include "remoting/client/plugin/chromoting_scriptable_object.h"
-#include "remoting/client/plugin/pepper_client_logger.h"
#include "remoting/protocol/connection_to_host.h"
-class MessageLoop;
-
namespace base {
class Thread;
} // namespace base
@@ -49,6 +46,7 @@ class JingleThread;
class PepperView;
class PepperViewProxy;
class RectangleUpdateDecoder;
+class TaskThreadProxy;
struct ClientConfig;
@@ -88,9 +86,6 @@ class ChromotingInstance : public pp::InstancePrivate {
// Called by ChromotingScriptableObject to set scale-to-fit.
void SetScaleToFit(bool scale_to_fit);
- void Log(int severity, const char* format, ...);
- void VLog(int verboselevel, const char* format, ...);
-
// Return statistics record by ChromotingClient.
// If no connection is currently active then NULL will be returned.
ChromotingStats* GetStats();
@@ -99,6 +94,11 @@ class ChromotingInstance : public pp::InstancePrivate {
bool DoScaling() const { return scale_to_fit_; }
+ // A Log Message Handler that is called after each LOG message has been
+ // processed. This must be of type LogMessageHandlerFunction defined in
+ // base/logging.h.
+ static bool LogToUI(int severity, const char* file, int line,
+ size_t message_start, const std::string& str);
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
@@ -109,6 +109,8 @@ class ChromotingInstance : public pp::InstancePrivate {
bool IsNatTraversalAllowed(const std::string& policy_json);
void HandlePolicyUpdate(const std::string policy_json);
+ void ProcessLogToUI(const std::string& message);
+
bool initialized_;
ClientContext context_;
@@ -118,13 +120,16 @@ class ChromotingInstance : public pp::InstancePrivate {
// True if scale to fit is enabled.
bool scale_to_fit_;
+ // A refcounted class to perform thread-switching for logging tasks.
+ scoped_refptr<TaskThreadProxy> log_proxy_;
+
// PepperViewProxy is refcounted and used to interface between chromoting
// objects and PepperView and perform thread switching. It wraps around
// |view_| and receives method calls on chromoting threads. These method
// calls are then delegates on the pepper thread. During destruction of
// ChromotingInstance we need to detach PepperViewProxy from PepperView since
// both ChromotingInstance and PepperView are destroyed and there will be
- // outstanding tasks on the pepper message loo.
+ // outstanding tasks on the pepper message loop.
scoped_refptr<PepperViewProxy> view_proxy_;
scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_;
scoped_ptr<InputHandler> input_handler_;
@@ -136,8 +141,6 @@ class ChromotingInstance : public pp::InstancePrivate {
// connection.
scoped_refptr<PepperXmppProxy> xmpp_proxy_;
- PepperClientLogger logger_;
-
// JavaScript interface to control this instance.
// This wraps a ChromotingScriptableObject in a pp::Var.
pp::Var instance_object_;
diff --git a/remoting/client/plugin/chromoting_scriptable_object.cc b/remoting/client/plugin/chromoting_scriptable_object.cc
index 410a4e3..d8a4d6c 100644
--- a/remoting/client/plugin/chromoting_scriptable_object.cc
+++ b/remoting/client/plugin/chromoting_scriptable_object.cc
@@ -5,7 +5,6 @@
#include "remoting/client/plugin/chromoting_scriptable_object.h"
#include "base/logging.h"
-#include "base/stringprintf.h"
// TODO(wez): Remove this when crbug.com/86353 is complete.
#include "ppapi/cpp/private/var_private.h"
#include "remoting/base/auth_token_util.h"
@@ -229,8 +228,7 @@ void ChromotingScriptableObject::SetConnectionInfo(ConnectionStatus status,
int status_index = property_names_[kStatusAttribute];
int quality_index = property_names_[kQualityAttribute];
- LogDebugInfo(
- base::StringPrintf("Connection status is updated: %d.", status));
+ LOG(INFO) << "Connection status is updated: " << status;
if (properties_[status_index].attribute.AsInt() != status ||
properties_[quality_index].attribute.AsInt() != quality) {
@@ -268,8 +266,7 @@ void ChromotingScriptableObject::SetDesktopSize(int width, int height) {
SignalDesktopSizeChange();
}
- LogDebugInfo(base::StringPrintf("Update desktop size to: %d x %d.",
- width, height));
+ LOG(INFO) << "Update desktop size to: " << width << " x " << height;
}
void ChromotingScriptableObject::AddAttribute(const std::string& name,
@@ -293,8 +290,7 @@ void ChromotingScriptableObject::SignalConnectionInfoChange() {
cb.Call(Var(), &exception);
if (!exception.is_undefined())
- LogDebugInfo(
- "Exception when invoking connectionInfoUpdate JS callback.");
+ LOG(ERROR) << "Exception when invoking connectionInfoUpdate JS callback.";
}
void ChromotingScriptableObject::SignalDesktopSizeChange() {
@@ -306,8 +302,8 @@ void ChromotingScriptableObject::SignalDesktopSizeChange() {
cb.Call(Var(), &exception);
if (!exception.is_undefined()) {
- LOG(WARNING) << "Exception when invoking JS callback"
- << exception.DebugString();
+ LOG(ERROR) << "Exception when invoking JS callback"
+ << exception.DebugString();
}
}
@@ -320,7 +316,7 @@ void ChromotingScriptableObject::SignalLoginChallenge() {
cb.Call(Var(), &exception);
if (!exception.is_undefined())
- LogDebugInfo("Exception when invoking loginChallenge JS callback.");
+ LOG(ERROR) << "Exception when invoking loginChallenge JS callback.";
}
void ChromotingScriptableObject::AttachXmppProxy(PepperXmppProxy* xmpp_proxy) {
@@ -336,7 +332,7 @@ void ChromotingScriptableObject::SendIq(const std::string& message_xml) {
cb.Call(Var(), Var(message_xml), &exception);
if (!exception.is_undefined())
- LogDebugInfo("Exception when invoking sendiq JS callback.");
+ LOG(ERROR) << "Exception when invoking sendiq JS callback.";
}
Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args,
@@ -379,7 +375,7 @@ Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args,
return Var();
}
- LogDebugInfo("Connecting to host.");
+ LOG(INFO) << "Connecting to host.";
VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid
<< ", access_code: " << access_code;
ClientConfig config;
@@ -394,7 +390,7 @@ Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args,
Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args,
Var* exception) {
- LogDebugInfo("Disconnecting from host.");
+ LOG(INFO) << "Disconnecting from host.";
instance_->Disconnect();
return Var();
@@ -419,7 +415,7 @@ Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args,
}
std::string password = args[1].AsString();
- LogDebugInfo("Submitting login info to host.");
+ LOG(INFO) << "Submitting login info to host.";
instance_->SubmitLoginInfo(username, password);
return Var();
}
@@ -436,7 +432,7 @@ Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args,
return Var();
}
- LogDebugInfo("Setting scale-to-fit.");
+ LOG(INFO) << "Setting scale-to-fit.";
instance_->SetScaleToFit(args[0].AsBool());
return Var();
}
diff --git a/remoting/client/plugin/pepper_client_logger.cc b/remoting/client/plugin/pepper_client_logger.cc
deleted file mode 100644
index 3e13c70..0000000
--- a/remoting/client/plugin/pepper_client_logger.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/client/plugin/pepper_client_logger.h"
-
-//#include <stdarg.h> // va_list
-
-//#include "base/logging.h"
-#include "base/message_loop.h"
-//#include "base/stringprintf.h"
-#include "remoting/client/plugin/chromoting_instance.h"
-
-namespace remoting {
-
-PepperClientLogger::PepperClientLogger(ChromotingInstance* instance)
- : instance_(instance) {
- SetThread(MessageLoop::current());
-}
-
-PepperClientLogger::~PepperClientLogger() {
-}
-
-void PepperClientLogger::LogToUI(const std::string& message) {
- instance_->GetScriptableObject()->LogDebugInfo(message);
-}
-
-} // namespace remoting
diff --git a/remoting/client/plugin/pepper_client_logger.h b/remoting/client/plugin/pepper_client_logger.h
deleted file mode 100644
index badf4d2..0000000
--- a/remoting/client/plugin/pepper_client_logger.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_CLIENT_LOGGER_H_
-#define REMOTING_CLIENT_PLUGIN_PEPPER_CLIENT_LOGGER_H_
-
-#include "remoting/base/logger.h"
-
-#include "base/task.h"
-
-class MessageLoop;
-
-namespace remoting {
-
-class ChromotingInstance;
-
-class PepperClientLogger : public Logger {
- public:
- explicit PepperClientLogger(ChromotingInstance* instance);
- virtual ~PepperClientLogger();
-
- virtual void LogToUI(const std::string& message);
-
- private:
- ChromotingInstance* instance_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperClientLogger);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_CLIENT_PLUGIN_PEPPER_CLIENT_LOGGER_H_
diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc
index 72cae5b..f85ca71 100644
--- a/remoting/client/plugin/pepper_view.cc
+++ b/remoting/client/plugin/pepper_view.cc
@@ -48,16 +48,15 @@ void PepperView::Paint() {
TraceContext::tracer()->PrintString("Start Paint.");
if (is_static_fill_) {
- instance_->Log(logging::LOG_INFO,
- "Static filling %08x", static_fill_color_);
+ LOG(INFO) << "Static filling " << static_fill_color_;
pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(),
pp::Size(graphics2d_.size().width(),
graphics2d_.size().height()),
false);
if (image.is_null()) {
- instance_->Log(logging::LOG_ERROR,
- "Unable to allocate image of size: %dx%d",
- graphics2d_.size().width(), graphics2d_.size().height());
+ LOG(ERROR) << "Unable to allocate image of size: "
+ << graphics2d_.size().width() << " x "
+ << graphics2d_.size().height();
return;
}
@@ -100,7 +99,7 @@ void PepperView::PaintFrame(media::VideoFrame* frame, UpdatedRects* rects) {
SetHostSize(gfx::Size(frame->width(), frame->height()));
if (!backing_store_.get() || backing_store_->is_null()) {
- instance_->Log(logging::LOG_ERROR, "Backing store is not available.");
+ LOG(ERROR) << "Backing store is not available.";
return;
}
@@ -255,7 +254,7 @@ bool PepperView::SetPluginSize(const gfx::Size& plugin_size) {
graphics2d_ = pp::Graphics2D(instance_, pp_size, true);
if (!instance_->BindGraphics(graphics2d_)) {
- instance_->Log(logging::LOG_ERROR, "Couldn't bind the device context.");
+ LOG(ERROR) << "Couldn't bind the device context.";
return false;
}
@@ -265,8 +264,8 @@ bool PepperView::SetPluginSize(const gfx::Size& plugin_size) {
// Allocate the backing store to save the desktop image.
if ((backing_store_.get() == NULL) ||
(backing_store_->size() != pp_size)) {
- instance_->Log(logging::LOG_INFO, "Allocate backing store: %d x %d",
- plugin_size.width(), plugin_size.height());
+ LOG(INFO) << "Allocate backing store: "
+ << plugin_size.width() << " x " << plugin_size.height();
backing_store_.reset(
new pp::ImageData(instance_, pp::ImageData::GetNativeImageDataFormat(),
pp_size, false));
@@ -314,7 +313,7 @@ void PepperView::ReleaseFrame(media::VideoFrame* frame) {
DCHECK(CurrentlyOnPluginThread());
if (frame) {
- instance_->Log(logging::LOG_WARNING, "Frame released.");
+ LOG(WARNING) << "Frame released.";
frame->Release();
}
}
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 9398d3d..1d42059 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -12,7 +12,6 @@
#include "remoting/base/encoder.h"
#include "remoting/base/encoder_row_based.h"
#include "remoting/base/encoder_vp8.h"
-#include "remoting/base/logger.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/curtain.h"
#include "remoting/host/desktop_environment.h"
@@ -40,23 +39,20 @@ ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger,
bool allow_nat_traversal) {
return new ChromotingHost(context, config, environment, access_verifier,
- logger, allow_nat_traversal);
+ allow_nat_traversal);
}
ChromotingHost::ChromotingHost(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger,
bool allow_nat_traversal)
: context_(context),
desktop_environment_(environment),
config_(config),
access_verifier_(access_verifier),
- logger_(logger),
allow_nat_traversal_(allow_nat_traversal),
state_(kInitial),
protocol_config_(protocol::CandidateSessionConfig::CreateDefault()),
@@ -64,7 +60,6 @@ ChromotingHost::ChromotingHost(ChromotingHostContext* context,
is_it2me_(false) {
DCHECK(desktop_environment_);
desktop_environment_->set_host(this);
- logger_->SetThread(MessageLoop::current());
}
ChromotingHost::~ChromotingHost() {
@@ -77,7 +72,7 @@ void ChromotingHost::Start() {
return;
}
- logger_->Log(logging::LOG_INFO, "Starting host");
+ LOG(INFO) << "Starting host";
DCHECK(!signal_strategy_.get());
DCHECK(access_verifier_.get());
@@ -96,8 +91,7 @@ void ChromotingHost::Start() {
if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) ||
!config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token) ||
!config_->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service)) {
- logger_->Log(logging::LOG_ERROR,
- "XMPP credentials are not defined in the config.");
+ LOG(ERROR) << "XMPP credentials are not defined in the config.";
return;
}
@@ -159,7 +153,7 @@ void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) {
// protocol::ConnectionToClient::EventHandler implementations
void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
- logger_->VLog(1, "Connection to client established.");
+ VLOG(1) << "Connection to client established.";
// TODO(wez): ChromotingHost shouldn't need to know about Me2Mom.
if (is_it2me_) {
context_->main_message_loop()->PostTask(
@@ -171,7 +165,7 @@ void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
- logger_->VLog(1, "Connection to client closed.");
+ VLOG(1) << "Connection to client closed.";
context_->main_message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this,
make_scoped_refptr(connection)));
@@ -180,7 +174,7 @@ void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) {
DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
- logger_->Log(logging::LOG_ERROR, "Connection failed unexpectedly.");
+ LOG(ERROR) << "Connection failed unexpectedly.";
context_->main_message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this,
make_scoped_refptr(connection)));
@@ -207,7 +201,7 @@ void ChromotingHost::OnStateChange(
DCHECK_EQ(MessageLoop::current(), context_->network_message_loop());
if (state == SignalStrategy::StatusObserver::CONNECTED) {
- logger_->Log(logging::LOG_INFO, "Host connected as %s", local_jid_.c_str());
+ LOG(INFO) << "Host connected as " << local_jid_;
// Create and start session manager.
protocol::JingleSessionManager* server =
@@ -231,7 +225,7 @@ void ChromotingHost::OnStateChange(
(*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_);
}
} else if (state == SignalStrategy::StatusObserver::CLOSED) {
- logger_->Log(logging::LOG_INFO, "Host disconnected from talk network.");
+ LOG(INFO) << "Host disconnected from talk network.";
for (StatusObserverList::iterator it = status_observers_.begin();
it != status_observers_.end(); ++it) {
(*it)->OnSignallingDisconnected();
@@ -294,9 +288,8 @@ void ChromotingHost::OnIncomingSession(
session->candidate_config(), true /* force_host_resolution */);
if (!config) {
- logger_->Log(logging::LOG_WARNING,
- "Rejecting connection from %s because no compatible"
- " configuration has been found.", session->jid().c_str());
+ LOG(WARNING) << "Rejecting connection from " << session->jid()
+ << " because no compatible configuration has been found.";
*response = protocol::SessionManager::INCOMPATIBLE;
return;
}
@@ -310,8 +303,7 @@ void ChromotingHost::OnIncomingSession(
*response = protocol::SessionManager::ACCEPT;
- logger_->Log(logging::LOG_INFO, "Client connected: %s",
- session->jid().c_str());
+ LOG(INFO) << "Client connected: " << session->jid();
// We accept the connection, so create a connection object.
ConnectionToClient* connection = new ConnectionToClient(
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 5b45d43..fb26aec 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -36,7 +36,6 @@ class Capturer;
class ChromotingHostContext;
class DesktopEnvironment;
class Encoder;
-class Logger;
class MutableHostConfig;
class ScreenRecorder;
@@ -72,13 +71,12 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// Factory methods that must be used to create ChromotingHost
// instances. Returned instance takes ownership of
// |access_verifier|. It does NOT take ownership of |context|,
- // |environment| and |logger|, but they should not be deleted until
+ // and |environment|, but they should not be deleted until
// returned host is destroyed.
static ChromotingHost* Create(ChromotingHostContext* context,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger,
bool allow_nat_traversal);
// Asynchronously start the host process.
@@ -120,8 +118,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
virtual void LocalLoginFailed(
scoped_refptr<protocol::ConnectionToClient> client);
- Logger* logger() { return logger_; }
-
// SessionManager::Listener implementation.
virtual void OnSessionManagerInitialized() OVERRIDE;
virtual void OnIncomingSession(
@@ -168,7 +164,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
MutableHostConfig* config,
DesktopEnvironment* environment,
AccessVerifier* access_verifier,
- Logger* logger,
bool allow_nat_traversal);
virtual ~ChromotingHost();
@@ -197,7 +192,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
DesktopEnvironment* desktop_environment_;
scoped_refptr<MutableHostConfig> config_;
scoped_ptr<AccessVerifier> access_verifier_;
- Logger* logger_;
bool allow_nat_traversal_;
// Connection objects.
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index 9b77bfe..6fe5db8 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -5,7 +5,6 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
-#include "remoting/base/logger.h"
#include "remoting/host/capturer_fake.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
@@ -87,8 +86,6 @@ class ChromotingHostTest : public testing::Test {
EXPECT_CALL(context_, ui_message_loop())
.Times(AnyNumber());
- logger_.reset(new Logger());
-
context_.SetUITaskPostFunction(base::Bind(
static_cast<void(MessageLoop::*)(
const tracked_objects::Location&,
@@ -109,7 +106,7 @@ class ChromotingHostTest : public testing::Test {
host_ = ChromotingHost::Create(&context_, config_,
desktop_environment_.get(),
- access_verifier, logger_.get(), false);
+ access_verifier, false);
credentials_.set_type(protocol::PASSWORD);
credentials_.set_username("user");
credentials_.set_credential("password");
@@ -214,7 +211,6 @@ class ChromotingHostTest : public testing::Test {
}
protected:
- scoped_ptr<Logger> logger_;
MessageLoop message_loop_;
MockConnectionToClientEventHandler handler_;
scoped_ptr<DesktopEnvironment> desktop_environment_;
diff --git a/remoting/host/plugin/host_plugin_logger.cc b/remoting/host/plugin/host_plugin_logger.cc
deleted file mode 100644
index bf33f66..0000000
--- a/remoting/host/plugin/host_plugin_logger.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/host/plugin/host_plugin_logger.h"
-
-#include "remoting/host/plugin/host_script_object.h"
-
-namespace remoting {
-
-HostPluginLogger::HostPluginLogger(HostNPScriptObject* scriptable)
- : scriptable_object_(scriptable) {
-}
-
-HostPluginLogger::~HostPluginLogger() {
-}
-
-void HostPluginLogger::LogToUI(const std::string& message) {
- scriptable_object_->LogDebugInfo(message);
-}
-
-} // namespace remoting
diff --git a/remoting/host/plugin/host_plugin_logger.h b/remoting/host/plugin/host_plugin_logger.h
deleted file mode 100644
index 69abea5..0000000
--- a/remoting/host/plugin/host_plugin_logger.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_HOST_PLUGIN_HOST_PLUGIN_LOGGER_H_
-#define REMOTING_HOST_PLUGIN_HOST_PLUGIN_LOGGER_H_
-
-#include "remoting/base/logger.h"
-
-namespace remoting {
-
-class HostNPScriptObject;
-
-class HostPluginLogger : public Logger {
- public:
- explicit HostPluginLogger(HostNPScriptObject* scriptable);
- virtual ~HostPluginLogger();
-
- virtual void LogToUI(const std::string& message);
-
- private:
- HostNPScriptObject* scriptable_object_;
-
- DISALLOW_COPY_AND_ASSIGN(HostPluginLogger);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_PLUGIN_HOST_PLUGIN_LOGGER_H_
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 035641f..460458d 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/threading/platform_thread.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"
@@ -66,6 +67,13 @@ 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)
: plugin_(plugin),
parent_(parent),
@@ -75,8 +83,20 @@ HostNPScriptObject::HostNPScriptObject(NPP plugin, NPObject* parent)
np_thread_id_(base::PlatformThread::CurrentId()),
failed_login_attempts_(0),
disconnected_event_(true, false) {
- logger_.reset(new HostPluginLogger(this));
- logger_->VLog(2, "HostNPScriptObject");
+ // 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;
+
+ VLOG(2) << "HostNPScriptObject";
host_context_.SetUITaskPostFunction(base::Bind(
&HostNPScriptObject::PostTaskToNPThread, base::Unretained(this)));
}
@@ -88,6 +108,10 @@ 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;
+
// Disconnect synchronously. We cannot disconnect asynchronously
// here because |host_context_| needs to be stopped on the plugin
// thread, but the plugin thread may not exist after the instance
@@ -109,14 +133,14 @@ HostNPScriptObject::~HostNPScriptObject() {
}
bool HostNPScriptObject::Init() {
- logger_->VLog(2, "Init");
+ VLOG(2) << "Init";
// TODO(wez): This starts a bunch of threads, which might fail.
host_context_.Start();
return true;
}
bool HostNPScriptObject::HasMethod(const std::string& method_name) {
- logger_->VLog(2, "HasMethod %s", method_name.c_str());
+ VLOG(2) << "HasMethod " << method_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
return (method_name == kFuncNameConnect ||
method_name == kFuncNameDisconnect);
@@ -125,7 +149,7 @@ bool HostNPScriptObject::HasMethod(const std::string& method_name) {
bool HostNPScriptObject::InvokeDefault(const NPVariant* args,
uint32_t argCount,
NPVariant* result) {
- logger_->VLog(2, "InvokeDefault");
+ VLOG(2) << "InvokeDefault";
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
SetException("exception during default invocation");
return false;
@@ -135,7 +159,7 @@ bool HostNPScriptObject::Invoke(const std::string& method_name,
const NPVariant* args,
uint32_t argCount,
NPVariant* result) {
- logger_->VLog(2, "Invoke %s", method_name.c_str());
+ VLOG(2) << "Invoke " << method_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
if (method_name == kFuncNameConnect) {
return Connect(args, argCount, result);
@@ -148,7 +172,7 @@ bool HostNPScriptObject::Invoke(const std::string& method_name,
}
bool HostNPScriptObject::HasProperty(const std::string& property_name) {
- logger_->VLog(2, "HasProperty %s", property_name.c_str());
+ VLOG(2) << "HasProperty " << property_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
return (property_name == kAttrNameAccessCode ||
property_name == kAttrNameAccessCodeLifetime ||
@@ -166,7 +190,7 @@ bool HostNPScriptObject::HasProperty(const std::string& property_name) {
bool HostNPScriptObject::GetProperty(const std::string& property_name,
NPVariant* result) {
- logger_->VLog(2, "GetProperty %s", property_name.c_str());
+ VLOG(2) << "GetProperty " << property_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
if (!result) {
SetException("GetProperty: NULL result");
@@ -217,7 +241,7 @@ bool HostNPScriptObject::GetProperty(const std::string& property_name,
bool HostNPScriptObject::SetProperty(const std::string& property_name,
const NPVariant* value) {
- logger_->VLog(2, "SetProperty %s", property_name.c_str());
+ VLOG(2) << "SetProperty " << property_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
if (property_name == kAttrNameOnStateChanged) {
@@ -258,13 +282,13 @@ bool HostNPScriptObject::SetProperty(const std::string& property_name,
}
bool HostNPScriptObject::RemoveProperty(const std::string& property_name) {
- logger_->VLog(2, "RemoveProperty %s", property_name.c_str());
+ VLOG(2) << "RemoveProperty " << property_name;
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
return false;
}
bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) {
- logger_->VLog(2, "Enumerate");
+ VLOG(2) << "Enumerate";
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
const char* entries[] = {
kAttrNameAccessCode,
@@ -330,7 +354,7 @@ bool HostNPScriptObject::Connect(const NPVariant* args,
NPVariant* result) {
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
- LogDebugInfo("Connecting...");
+ LOG(INFO) << "Connecting...";
if (arg_count != 2) {
SetException("connect: bad number of arguments");
@@ -408,7 +432,7 @@ void HostNPScriptObject::ConnectInternal(
// TODO(sergeyu): Use firewall traversal policy settings here.
host_ = ChromotingHost::Create(
&host_context_, host_config_, desktop_environment_.get(),
- access_verifier.release(), logger_.get(), false);
+ access_verifier.release(), false);
host_->AddStatusObserver(this);
host_->AddStatusObserver(register_request_.get());
host_->set_it2me(true);
@@ -500,12 +524,32 @@ void HostNPScriptObject::OnStateChanged(State state) {
}
state_ = state;
if (on_state_changed_func_) {
- logger_->VLog(2, "Calling state changed %s", state);
+ VLOG(2) << "Calling state changed " << state;
bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0);
LOG_IF(ERROR, !is_good) << "OnStateChanged failed";
}
}
+// 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::LogDebugInfo(const std::string& message) {
if (destructing_.IsSet())
return;
@@ -516,6 +560,7 @@ void HostNPScriptObject::LogDebugInfo(const std::string& message) {
base::Unretained(this), message));
return;
}
+
if (log_debug_info_func_) {
NPVariant* arg = new NPVariant();
STRINGZ_TO_NPVARIANT(message.c_str(), *arg);
@@ -527,7 +572,7 @@ void HostNPScriptObject::LogDebugInfo(const std::string& message) {
void HostNPScriptObject::SetException(const std::string& exception_string) {
CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
- LogDebugInfo(exception_string);
+ LOG(INFO) << exception_string;
}
bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h
index ef5b687..03d14c3 100644
--- a/remoting/host/plugin/host_script_object.h
+++ b/remoting/host/plugin/host_script_object.h
@@ -17,7 +17,6 @@
#include "base/time.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/host_status_observer.h"
-#include "remoting/host/plugin/host_plugin_logger.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npfunctions.h"
#include "third_party/npapi/bindings/npruntime.h"
@@ -60,9 +59,6 @@ class HostNPScriptObject : public HostStatusObserver {
bool RemoveProperty(const std::string& property_name);
bool Enumerate(std::vector<std::string>* values);
- // Call LogDebugInfo handler if there is one.
- void LogDebugInfo(const std::string& message);
-
// remoting::HostStatusObserver implementation.
virtual void OnSignallingConnected(remoting::SignalStrategy* signal_strategy,
const std::string& full_jid) OVERRIDE;
@@ -74,6 +70,11 @@ class HostNPScriptObject : public HostStatusObserver {
remoting::protocol::ConnectionToClient* client) OVERRIDE;
virtual void OnShutdown() OVERRIDE;
+ // A Log Message Handler that is called after each LOG message has been
+ // processed. This must be of type LogMessageHandlerFunction defined in
+ // base/logging.h.
+ static bool LogToUI(int severity, const char* file, int line,
+ size_t message_start, const std::string& str);
private:
enum State {
kDisconnected,
@@ -95,6 +96,9 @@ class HostNPScriptObject : public HostStatusObserver {
// Call OnStateChanged handler if there is one.
void OnStateChanged(State state);
+ // Call LogDebugInfo handler if there is one.
+ void LogDebugInfo(const std::string& message);
+
// Callbacks invoked during session setup.
void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier,
bool success,
@@ -137,8 +141,6 @@ class HostNPScriptObject : public HostStatusObserver {
NPObject* on_state_changed_func_;
base::PlatformThreadId np_thread_id_;
- scoped_ptr<HostPluginLogger> logger_;
-
scoped_ptr<RegisterSupportHostRequest> register_request_;
scoped_refptr<MutableHostConfig> host_config_;
ChromotingHostContext host_context_;
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 8e1eab8..3e6000c 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -34,7 +34,6 @@
#include "crypto/nss_util.h"
#include "media/base/media.h"
#include "remoting/base/constants.h"
-#include "remoting/base/logger.h"
#include "remoting/base/tracer.h"
#include "remoting/host/capturer_fake.h"
#include "remoting/host/chromoting_host.h"
@@ -164,7 +163,6 @@ class SimpleHost {
}
// Construct a chromoting host.
- logger_.reset(new remoting::Logger());
scoped_ptr<DesktopEnvironment> desktop_environment;
if (fake_) {
remoting::Capturer* capturer =
@@ -188,8 +186,7 @@ class SimpleHost {
}
host_ = ChromotingHost::Create(&context, config, desktop_environment.get(),
- access_verifier.release(), logger_.get(),
- false);
+ access_verifier.release(), false);
host_->set_it2me(is_it2me_);
if (protocol_config_.get()) {
@@ -262,8 +259,6 @@ class SimpleHost {
return FilePath(home_path).Append(kDefaultConfigPath);
}
- scoped_ptr<remoting::Logger> logger_;
-
FilePath config_path_;
bool fake_;
bool is_it2me_;
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 6d8264a..2369896 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -139,8 +139,6 @@
'client/plugin/chromoting_instance.h',
'client/plugin/chromoting_scriptable_object.cc',
'client/plugin/chromoting_scriptable_object.h',
- 'client/plugin/pepper_client_logger.cc',
- 'client/plugin/pepper_client_logger.h',
'client/plugin/pepper_entrypoints.cc',
'client/plugin/pepper_entrypoints.h',
'client/plugin/pepper_input_handler.cc',
@@ -173,8 +171,6 @@
'host/plugin/host_plugin.cc',
'host/plugin/host_plugin.def',
'host/plugin/host_plugin.rc',
- 'host/plugin/host_plugin_logger.cc',
- 'host/plugin/host_plugin_logger.h',
'host/plugin/host_plugin_resource.h',
'host/plugin/host_plugin_utils.cc',
'host/plugin/host_plugin_utils.h',
@@ -326,12 +322,12 @@
'base/encoder_vp8.h',
'base/encoder_row_based.cc',
'base/encoder_row_based.h',
- 'base/logger.cc',
- 'base/logger.h',
'base/rate_counter.cc',
'base/rate_counter.h',
'base/running_average.cc',
'base/running_average.h',
+ 'base/task_thread_proxy.cc',
+ 'base/task_thread_proxy.h',
'base/tracer.cc',
'base/tracer.h',
'base/types.h',