From b54528f124d6679673e15d92bfbf34cf931e230f Mon Sep 17 00:00:00 2001 From: sebmarchand Date: Fri, 14 Nov 2014 12:47:17 -0800 Subject: [PATCH] Remove the references to the media::CdmLogMessage methods on Release builds. Also remove an "#include " from cdm_logging.h as it's discouraged by the style guide, move it to the *.cc file. We should get rid of this include entirely, but for now it's at least hidden behind a "#if !defined(NDEBUG)". BUG=336542, 94794 Review URL: https://codereview.chromium.org/717383002 Cr-Commit-Position: refs/heads/master@{#304262} --- media/cdm/ppapi/cdm_logging.cc | 12 +++++++++--- media/cdm/ppapi/cdm_logging.h | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/media/cdm/ppapi/cdm_logging.cc b/media/cdm/ppapi/cdm_logging.cc index ff05930d9c73..02383fc893dc 100644 --- a/media/cdm/ppapi/cdm_logging.cc +++ b/media/cdm/ppapi/cdm_logging.cc @@ -6,7 +6,6 @@ // protection that if the linker tries to link in strings/symbols appended to // "DLOG() <<" in release build (which it shouldn't), we'll get "undefined // reference" errors. -#if !defined(NDEBUG) #include "media/cdm/ppapi/cdm_logging.h" @@ -34,10 +33,13 @@ #endif #include +#include #include namespace media { +#if !defined(NDEBUG) + namespace { // Helper functions to wrap platform differences. @@ -132,6 +134,10 @@ CdmLogMessage::~CdmLogMessage() { std::cout << std::endl; } -} // namespace media - #endif // !defined(NDEBUG) + +std::ostream& CdmLogStream::stream() { + return std::cout; +} + +} // namespace media diff --git a/media/cdm/ppapi/cdm_logging.h b/media/cdm/ppapi/cdm_logging.h index a7059182ff75..63961f2b78a6 100644 --- a/media/cdm/ppapi/cdm_logging.h +++ b/media/cdm/ppapi/cdm_logging.h @@ -7,7 +7,7 @@ #ifndef MEDIA_CDM_PPAPI_CDM_LOGGING_H_ #define MEDIA_CDM_PPAPI_CDM_LOGGING_H_ -#include +#include #include #include @@ -30,6 +30,17 @@ class LogMessageVoidify { } // namespace +// This class is used to avoid having to include in this file. +class CdmLogStream { + public: + CdmLogStream() {} + + // Retrieves the stream that we write to. This header cannot depend on + // because that will add static initializers to all files that + // include this header. See crbug.com/94794. + std::ostream& stream(); +}; + // This class serves two purposes: // (1) It adds common headers to the log message, e.g. timestamp, process ID. // (2) It adds a line break at the end of the log message. @@ -52,13 +63,18 @@ class CdmLogMessage { #define CDM_LAZY_STREAM(stream, condition) \ !(condition) ? (void) 0 : LogMessageVoidify() & (stream) -#define CDM_DLOG() CDM_LAZY_STREAM(std::cout, CDM_DLOG_IS_ON()) \ - << CdmLogMessage(__FILE__, __LINE__).message() - #if defined(NDEBUG) +// Logging is disabled for the release builds, theoretically the compiler should +// take care of removing the references to CdmLogMessage but it's not always the +// case when some specific optimizations are turned on (like PGO). Update the +// macro to make sure that we don't try to do any logging or to refer to +// CdmLogMessage in release. #define CDM_DLOG_IS_ON() false +#define CDM_DLOG() CDM_LAZY_STREAM(CdmLogStream().stream(), CDM_DLOG_IS_ON()) #else #define CDM_DLOG_IS_ON() true +#define CDM_DLOG() CDM_LAZY_STREAM(CdmLogStream().stream(), CDM_DLOG_IS_ON()) \ + << CdmLogMessage(__FILE__, __LINE__).message() #endif } // namespace media -- 2.11.4.GIT