Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / media / base / media_log.h
blobabeb42057fffbdf678bfba5236a9623b5f3e6a80
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 {
21 // Indicates a string should be added to the log.
22 // First parameter - The string to add to the log.
23 typedef base::Callback<void(const std::string&)> LogCB;
25 // Helper class to make it easier to use log_cb like DVLOG().
26 class LogHelper {
27 public:
28 LogHelper(const LogCB& Log_cb);
29 ~LogHelper();
31 std::ostream& stream() { return stream_; }
33 private:
34 LogCB log_cb_;
35 std::stringstream stream_;
38 #define MEDIA_LOG(log_cb) LogHelper(log_cb).stream()
40 // Logs only while count < max. Increments count for each log. Use LAZY_STREAM
41 // to avoid wasteful evaluation of subsequent stream arguments.
42 #define LIMITED_MEDIA_LOG(log_cb, count, max) \
43 LAZY_STREAM(MEDIA_LOG(log_cb), (count) < (max) && ((count)++ || true))
45 class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> {
46 public:
47 // Convert various enums to strings.
48 static std::string EventTypeToString(MediaLogEvent::Type type);
49 static std::string PipelineStatusToString(PipelineStatus status);
51 MediaLog();
53 // Add an event to this log. Overriden by inheritors to actually do something
54 // with it.
55 virtual void AddEvent(scoped_ptr<MediaLogEvent> event);
57 // Helper methods to create events and their parameters.
58 scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type);
59 scoped_ptr<MediaLogEvent> CreateBooleanEvent(
60 MediaLogEvent::Type type, const std::string& property, bool value);
61 scoped_ptr<MediaLogEvent> CreateStringEvent(MediaLogEvent::Type type,
62 const std::string& property,
63 const std::string& value);
64 scoped_ptr<MediaLogEvent> CreateTimeEvent(MediaLogEvent::Type type,
65 const std::string& property,
66 base::TimeDelta value);
67 scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url);
68 scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds);
69 scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent(
70 Pipeline::State state);
71 scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error);
72 scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent(
73 size_t width, size_t height);
74 scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent(
75 int64 start, int64 current, int64 end);
76 scoped_ptr<MediaLogEvent> CreateMediaSourceErrorEvent(
77 const std::string& error);
79 // Report a property change without an accompanying event.
80 void SetStringProperty(const std::string& key, const std::string& value);
81 void SetIntegerProperty(const std::string& key, int value);
82 void SetDoubleProperty(const std::string& key, double value);
83 void SetBooleanProperty(const std::string& key, bool value);
84 void SetTimeProperty(const std::string& key, base::TimeDelta value);
86 protected:
87 friend class base::RefCountedThreadSafe<MediaLog>;
88 virtual ~MediaLog();
90 private:
91 // A unique (to this process) id for this MediaLog.
92 int32 id_;
94 DISALLOW_COPY_AND_ASSIGN(MediaLog);
97 } // namespace media
99 #endif // MEDIA_BASE_MEDIA_LOG_H_