diff options
author | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-04 03:19:35 +0000 |
---|---|---|
committer | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-04 03:19:35 +0000 |
commit | 82d105ecf3aadbb90e0adf80f857533967e8f383 (patch) | |
tree | 4dde11c5e525a813ec2dc847e10c1478c7291453 /remoting/base | |
parent | 05130153c2e1f772955484f89169e505f809ba43 (diff) | |
download | chromium_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
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/logger.cc | 95 | ||||
-rw-r--r-- | remoting/base/logger.h | 51 | ||||
-rw-r--r-- | remoting/base/task_thread_proxy.cc | 34 | ||||
-rw-r--r-- | remoting/base/task_thread_proxy.h | 50 | ||||
-rw-r--r-- | remoting/base/util.cc | 14 | ||||
-rw-r--r-- | remoting/base/util.h | 2 |
6 files changed, 98 insertions, 148 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); |