Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1512)

Side by Side Diff: media/base/media_log.h

Issue 1235793005: Deprecate LogCB in favor of using MediaLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and attempt to fix Android compilation Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/media/android/media_source_delegate.cc ('k') | media/base/media_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_MEDIA_LOG_H_ 5 #ifndef MEDIA_BASE_MEDIA_LOG_H_
6 #define MEDIA_BASE_MEDIA_LOG_H_ 6 #define MEDIA_BASE_MEDIA_LOG_H_
7 7
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 friend class base::RefCountedThreadSafe<MediaLog>; 74 friend class base::RefCountedThreadSafe<MediaLog>;
75 virtual ~MediaLog(); 75 virtual ~MediaLog();
76 76
77 private: 77 private:
78 // A unique (to this process) id for this MediaLog. 78 // A unique (to this process) id for this MediaLog.
79 int32 id_; 79 int32 id_;
80 80
81 DISALLOW_COPY_AND_ASSIGN(MediaLog); 81 DISALLOW_COPY_AND_ASSIGN(MediaLog);
82 }; 82 };
83 83
84 // Indicates a string should be added to the log. 84 // Helper class to make it easier to use MediaLog like DVLOG().
85 // First parameter - The log level for the string.
86 // Second parameter - The string to add to the log.
87 typedef base::Callback<void(MediaLog::MediaLogLevel, const std::string&)> LogCB;
88
89 // Helper class to make it easier to use LogCB or MediaLog like DVLOG().
90 class MEDIA_EXPORT LogHelper { 85 class MEDIA_EXPORT LogHelper {
91 public: 86 public:
92 LogHelper(MediaLog::MediaLogLevel level, const LogCB& log_cb);
93 LogHelper(MediaLog::MediaLogLevel level, 87 LogHelper(MediaLog::MediaLogLevel level,
94 const scoped_refptr<MediaLog>& media_log); 88 const scoped_refptr<MediaLog>& media_log);
95 ~LogHelper(); 89 ~LogHelper();
96 90
97 std::ostream& stream() { return stream_; } 91 std::ostream& stream() { return stream_; }
98 92
99 private: 93 private:
100 MediaLog::MediaLogLevel level_; 94 MediaLog::MediaLogLevel level_;
101 LogCB log_cb_;
102 const scoped_refptr<MediaLog> media_log_; 95 const scoped_refptr<MediaLog> media_log_;
103 std::stringstream stream_; 96 std::stringstream stream_;
104 }; 97 };
105 98
106 // Provides a stringstream to collect a log entry to pass to the provided 99 // Provides a stringstream to collect a log entry to pass to the provided
107 // logger (LogCB or MediaLog) at the requested level. 100 // MediaLog at the requested level.
108 #define MEDIA_LOG(level, logger) \ 101 #define MEDIA_LOG(level, media_log) \
109 LogHelper((MediaLog::MEDIALOG_##level), (logger)).stream() 102 LogHelper((MediaLog::MEDIALOG_##level), (media_log)).stream()
110 103
111 // Logs only while |count| < |max|, increments |count| for each log, and warns 104 // Logs only while |count| < |max|, increments |count| for each log, and warns
112 // in the log if |count| has just reached |max|. 105 // in the log if |count| has just reached |max|.
113 // Multiple short-circuit evaluations are involved in this macro: 106 // Multiple short-circuit evaluations are involved in this macro:
114 // 1) LAZY_STREAM avoids wasteful MEDIA_LOG and evaluation of subsequent stream 107 // 1) LAZY_STREAM avoids wasteful MEDIA_LOG and evaluation of subsequent stream
115 // arguments if |count| is >= |max|, and 108 // arguments if |count| is >= |max|, and
116 // 2) the |condition| given to LAZY_STREAM itself short-circuits to prevent 109 // 2) the |condition| given to LAZY_STREAM itself short-circuits to prevent
117 // incrementing |count| beyond |max|. 110 // incrementing |count| beyond |max|.
118 // Note that LAZY_STREAM guarantees exactly one evaluation of |condition|, so 111 // Note that LAZY_STREAM guarantees exactly one evaluation of |condition|, so
119 // |count| will be incremented at most once each time this macro runs. 112 // |count| will be incremented at most once each time this macro runs.
120 // The "|| true" portion of |condition| lets logging occur correctly when 113 // The "|| true" portion of |condition| lets logging occur correctly when
121 // |count| < |max| and |count|++ is 0. 114 // |count| < |max| and |count|++ is 0.
122 // TODO(wolenetz,chcunningham): Consider using a helper class instead of a macro 115 // TODO(wolenetz,chcunningham): Consider using a helper class instead of a macro
123 // to improve readability. 116 // to improve readability.
124 #define LIMITED_MEDIA_LOG(level, logger, count, max) \ 117 #define LIMITED_MEDIA_LOG(level, media_log, count, max) \
125 LAZY_STREAM(MEDIA_LOG(level, logger), \ 118 LAZY_STREAM(MEDIA_LOG(level, media_log), \
126 (count) < (max) && ((count)++ || true)) \ 119 (count) < (max) && ((count)++ || true)) \
127 << (((count) == (max)) ? "(Log limit reached. Further similar entries " \ 120 << (((count) == (max)) ? "(Log limit reached. Further similar entries " \
128 "may be suppressed): " \ 121 "may be suppressed): " \
129 : "") 122 : "")
130 123
131 } // namespace media 124 } // namespace media
132 125
133 #endif // MEDIA_BASE_MEDIA_LOG_H_ 126 #endif // MEDIA_BASE_MEDIA_LOG_H_
OLDNEW
« no previous file with comments | « content/renderer/media/android/media_source_delegate.cc ('k') | media/base/media_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698