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

Unified Diff: remoting/client/plugin/chromoting_instance.cc

Issue 7355011: Modify Chromoting logging to hook into base logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add timestamp Created 9 years, 5 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/client/plugin/chromoting_instance.cc
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index af21adc170c4e161b539f2bd9e1e616fc84aa36b..b81448807e63c046c383ab8976c72e662e278187 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -24,11 +24,11 @@
#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/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,19 +49,35 @@
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 logging_to_plugin_ = false;
dmac 2011/07/21 23:37:07 should these be marked with a g in front of them?
garykac 2011/08/02 00:15:37 Done.
+static ChromotingInstance* logging_instance_ = NULL;
+static MessageLoop* logging_message_loop_ = NULL;
+static logging::LogMessageHandlerFunction logging_old_handler_ = NULL;
+
const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting";
ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
: pp::InstancePrivate(pp_instance),
- initialized_(false),
- logger_(this) {
+ initialized_(false) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
+ logging_old_handler_ = logging::GetLogMessageHandler();
+ logging::SetLogMessageHandler(&LogToUI);
+ logging_instance_ = this;
+ logging_message_loop_ = MessageLoop::current();
}
ChromotingInstance::~ChromotingInstance() {
DCHECK(CurrentlyOnPluginThread());
+ logging::SetLogMessageHandler(logging_old_handler_);
+ logging_old_handler_ = NULL;
+ logging_instance_ = NULL;
+ logging_message_loop_ = NULL;
+
if (client_.get()) {
base::WaitableEvent done_event(true, false);
client_->Stop(base::Bind(&base::WaitableEvent::Signal,
@@ -82,7 +98,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();
@@ -100,7 +116,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);
}
@@ -128,9 +144,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();
@@ -142,7 +158,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);
}
@@ -150,7 +166,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);
@@ -203,14 +219,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;
}
@@ -236,8 +252,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;
}
@@ -245,8 +260,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;
}
@@ -265,18 +279,39 @@ void ChromotingInstance::SetScaleToFit(bool scale_to_fit) {
view_proxy_->SetScaleToFit(scale_to_fit);
}
-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 (logging_instance_ && !logging_to_plugin_) {
+ logging_to_plugin_ = true;
dmac 2011/07/21 23:37:07 logging_to_plugin_ race conditions about the globa
garykac 2011/08/02 00:15:37 True. I pushed the check down into the "CorrectThr
+ std::string message = remoting::GetTimestampString();
+ message += (str.c_str() + message_start);
+ logging_instance_->LogToUI_CorrectThread(message);
+ logging_to_plugin_ = false;
+ }
+
+ if (logging_old_handler_)
+ return (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::LogToUI_CorrectThread(const std::string& message) {
+ if (!logging_message_loop_)
+ return;
+
+ if (logging_message_loop_ != MessageLoop::current()) {
+ logging_message_loop_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this,
+ &ChromotingInstance::LogToUI_CorrectThread, message));
+ return;
+ }
+
+ ChromotingScriptableObject* cso = GetScriptableObject();
+ if (cso) {
+ cso->LogDebugInfo(message);
+ }
}
pp::Var ChromotingInstance::GetInstanceObject() {

Powered by Google App Engine
This is Rietveld 408576698