Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / media / base / media_log.h
blob1a76cbf5f01ed68e67479f523e4119bd365b3dc8
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/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/media_export.h"
14 #include "media/base/media_log_event.h"
15 #include "media/base/pipeline.h"
16 #include "media/base/pipeline_status.h"
18 namespace media {
20 // Indicates a string should be added to the log.
21 // First parameter - The string to add to the log.
22 typedef base::Callback<void(const std::string&)> LogCB;
24 // Helper class to make it easier to use log_cb like DVLOG().
25 class LogHelper {
26 public:
27 LogHelper(const LogCB& Log_cb);
28 ~LogHelper();
30 std::ostream& stream() { return stream_; }
32 private:
33 LogCB log_cb_;
34 std::stringstream stream_;
37 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream()
39 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> {
40 public:
41 // Convert various enums to strings.
42 static std::string EventTypeToString(MediaLogEvent::Type type);
43 static std::string PipelineStatusToString(PipelineStatus status);
45 MediaLog();
47 // Add an event to this log. Overriden by inheritors to actually do something
48 // with it.
49 virtual void AddEvent(scoped_ptr<MediaLogEvent> event);
51 // Helper methods to create events and their parameters.
52 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type);
53 scoped_ptr<MediaLogEvent> CreateBooleanEvent(
54 MediaLogEvent::Type type, const std::string& property, bool value);
55 scoped_ptr<MediaLogEvent> CreateStringEvent(MediaLogEvent::Type type,
56 const std::string& property,
57 const std::string& value);
58 scoped_ptr<MediaLogEvent> CreateTimeEvent(MediaLogEvent::Type type,
59 const std::string& property,
60 base::TimeDelta value);
61 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url);
62 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds);
63 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent(
64 Pipeline::State state);
65 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error);
66 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent(
67 size_t width, size_t height);
68 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent(
69 int64 start, int64 current, int64 end);
70 scoped_ptr<MediaLogEvent> CreateMediaSourceErrorEvent(
71 const std::string& error);
73 // Report a property change without an accompanying event.
74 void SetStringProperty(const std::string& key, const std::string& value);
75 void SetIntegerProperty(const std::string& key, int value);
76 void SetDoubleProperty(const std::string& key, double value);
77 void SetBooleanProperty(const std::string& key, bool value);
78 void SetTimeProperty(const std::string& key, base::TimeDelta value);
80 protected:
81 friend class base::RefCountedThreadSafe<MediaLog>;
82 virtual ~MediaLog();
84 private:
85 // A unique (to this process) id for this MediaLog.
86 int32 id_;
88 DISALLOW_COPY_AND_ASSIGN(MediaLog);
91 } // namespace media
93 #endif // MEDIA_BASE_MEDIA_LOG_H_