Remove obsolete for_web_contents parameter in FontRenderParamsQuery.
[chromium-blink-merge.git] / media / base / media_log.h
blob8b40b5d4e61ff9ccff2e78b4a041f7d8f5ca3f2c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_MEDIA_LOG_H_
6 #define MEDIA_BASE_MEDIA_LOG_H_
8 #include <sstream>
9 #include <string>
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/media_export.h"
15 #include "media/base/media_log_event.h"
16 #include "media/base/pipeline.h"
17 #include "media/base/pipeline_status.h"
19 namespace media {
22 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> {
23 public:
24 enum MediaLogLevel {
25 MEDIALOG_ERROR,
26 MEDIALOG_INFO,
27 MEDIALOG_DEBUG,
30 // Convert various enums to strings.
31 static std::string MediaLogLevelToString(MediaLogLevel level);
32 static MediaLogEvent::Type MediaLogLevelToEventType(MediaLogLevel level);
33 static std::string EventTypeToString(MediaLogEvent::Type type);
34 static std::string PipelineStatusToString(PipelineStatus status);
36 static std::string MediaEventToLogString(const MediaLogEvent& event);
38 MediaLog();
40 // Add an event to this log. Overriden by inheritors to actually do something
41 // with it.
42 virtual void AddEvent(scoped_ptr<MediaLogEvent> event);
44 // Helper methods to create events and their parameters.
45 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type);
46 scoped_ptr<MediaLogEvent> CreateBooleanEvent(
47 MediaLogEvent::Type type, const std::string& property, bool value);
48 scoped_ptr<MediaLogEvent> CreateStringEvent(MediaLogEvent::Type type,
49 const std::string& property,
50 const std::string& value);
51 scoped_ptr<MediaLogEvent> CreateTimeEvent(MediaLogEvent::Type type,
52 const std::string& property,
53 base::TimeDelta value);
54 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url);
55 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds);
56 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent(
57 Pipeline::State state);
58 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error);
59 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent(
60 size_t width, size_t height);
61 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent(
62 int64 start, int64 current, int64 end);
64 // Report a log message at the specified log level.
65 void AddLogEvent(MediaLogLevel level, const std::string& message);
67 // Report a property change without an accompanying event.
68 void SetStringProperty(const std::string& key, const std::string& value);
69 void SetIntegerProperty(const std::string& key, int value);
70 void SetDoubleProperty(const std::string& key, double value);
71 void SetBooleanProperty(const std::string& key, bool value);
72 void SetTimeProperty(const std::string& key, base::TimeDelta value);
74 protected:
75 friend class base::RefCountedThreadSafe<MediaLog>;
76 virtual ~MediaLog();
78 private:
79 // A unique (to this process) id for this MediaLog.
80 int32 id_;
82 DISALLOW_COPY_AND_ASSIGN(MediaLog);
85 // Indicates a string should be added to the log.
86 // First parameter - The log level for the string.
87 // Second parameter - The string to add to the log.
88 typedef base::Callback<void(MediaLog::MediaLogLevel, const std::string&)> LogCB;
90 // Helper class to make it easier to use log_cb like DVLOG().
91 class LogHelper {
92 public:
93 LogHelper(MediaLog::MediaLogLevel level, const LogCB& log_cb);
94 ~LogHelper();
96 std::ostream& stream() { return stream_; }
98 private:
99 MediaLog::MediaLogLevel level_;
100 LogCB log_cb_;
101 std::stringstream stream_;
104 // Provides a stringstream to collect a log entry to pass to the provided
105 // LogCB at the requested level.
106 #define MEDIA_LOG(level, log_cb) \
107 LogHelper((MediaLog::MEDIALOG_##level), (log_cb)).stream()
109 // Logs only while count < max. Increments count for each log. Use LAZY_STREAM
110 // to avoid wasteful evaluation of subsequent stream arguments.
111 #define LIMITED_MEDIA_LOG(level, log_cb, count, max) \
112 LAZY_STREAM(MEDIA_LOG(level, log_cb), (count) < (max) && ((count)++ || true))
114 } // namespace media
116 #endif // MEDIA_BASE_MEDIA_LOG_H_