Chromium Code Reviews| Index: media/base/media_log.h |
| diff --git a/media/base/media_log.h b/media/base/media_log.h |
| index e388c9b0801869373456b27ae85c481bc6f03a07..0f6836eaf8e8b15596e41d7ecb79e9fce66fa97d 100644 |
| --- a/media/base/media_log.h |
| +++ b/media/base/media_log.h |
| @@ -18,33 +18,17 @@ |
| namespace media { |
| -// Indicates a string should be added to the log. |
| -// First parameter - The string to add to the log. |
| -typedef base::Callback<void(const std::string&)> LogCB; |
| - |
| -// Helper class to make it easier to use log_cb like DVLOG(). |
| -class LogHelper { |
| - public: |
| - LogHelper(const LogCB& Log_cb); |
| - ~LogHelper(); |
| - |
| - std::ostream& stream() { return stream_; } |
| - |
| - private: |
| - LogCB log_cb_; |
| - std::stringstream stream_; |
| -}; |
| - |
| -#define MEDIA_LOG(log_cb) LogHelper(log_cb).stream() |
| - |
| -// Logs only while count < max. Increments count for each log. Use LAZY_STREAM |
| -// to avoid wasteful evaluation of subsequent stream arguments. |
| -#define LIMITED_MEDIA_LOG(log_cb, count, max) \ |
| - LAZY_STREAM(MEDIA_LOG(log_cb), (count) < (max) && ((count)++ || true)) |
| class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| public: |
| + enum MediaLogLevel { |
| + MEDIALOG_ERROR, |
| + MEDIALOG_INFO, |
| + MEDIALOG_DEBUG, |
| + }; |
| + |
| // Convert various enums to strings. |
| + static std::string MediaLogLevelToString(MediaLogLevel level); |
| static std::string EventTypeToString(MediaLogEvent::Type type); |
| static std::string PipelineStatusToString(PipelineStatus status); |
| @@ -75,8 +59,8 @@ class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| size_t width, size_t height); |
| scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( |
| int64 start, int64 current, int64 end); |
| - scoped_ptr<MediaLogEvent> CreateMediaSourceErrorEvent( |
| - const std::string& error); |
| + scoped_ptr<MediaLogEvent> CreateLogEvent(MediaLogLevel level, |
| + const std::string& message); |
| // Report a property change without an accompanying event. |
| void SetStringProperty(const std::string& key, const std::string& value); |
| @@ -96,6 +80,35 @@ class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { |
| DISALLOW_COPY_AND_ASSIGN(MediaLog); |
| }; |
| +// Indicates a string should be added to the log. |
| +// First parameter - The log level for the string. |
| +// Second parameter - The string to add to the log. |
| +typedef base::Callback<void(MediaLog::MediaLogLevel, const std::string&)> LogCB; |
| + |
| +// Helper class to make it easier to use log_cb like DVLOG(). |
| +class LogHelper { |
| + public: |
| + LogHelper(const LogCB& log_cb, MediaLog::MediaLogLevel level); |
| + ~LogHelper(); |
| + |
| + std::ostream& stream() { return stream_; } |
| + |
| + private: |
| + LogCB log_cb_; |
| + MediaLog::MediaLogLevel level_; |
| + std::stringstream stream_; |
| +}; |
| + |
| +// Provides a stringstream to collect a log entry to pass to the provided |
| +// LogCB at the requested level. |
| +#define MEDIA_LOG(log_cb, level) \ |
|
DaleCurtis
2015/03/31 00:12:26
Hmm, we typically have the level before any other
wolenetz
2015/03/31 00:30:11
No specific reason. I can change the sequence here
DaleCurtis
2015/03/31 00:34:25
I think the constructor can stay the same if you d
wolenetz
2015/03/31 19:20:22
Done (level first for both the macros and the .cto
|
| + LogHelper((log_cb), (MediaLog::MEDIALOG_ ## level)).stream() |
| + |
| +// Logs only while count < max. Increments count for each log. Use LAZY_STREAM |
| +// to avoid wasteful evaluation of subsequent stream arguments. |
| +#define LIMITED_MEDIA_LOG(log_cb, level, count, max) \ |
| + LAZY_STREAM(MEDIA_LOG(log_cb, level), (count) < (max) && ((count)++ || true)) |
| + |
| } // namespace media |
| #endif // MEDIA_BASE_MEDIA_LOG_H_ |