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

Side by Side Diff: webrtc/call/rtc_event_log.cc

Issue 2015543002: Take ownership and close the platform file even if we fail to start logging. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // No-op implementation if flag is not set. 43 // No-op implementation if flag is not set.
44 class RtcEventLogNullImpl final : public RtcEventLog { 44 class RtcEventLogNullImpl final : public RtcEventLog {
45 public: 45 public:
46 bool StartLogging(const std::string& file_name, 46 bool StartLogging(const std::string& file_name,
47 int64_t max_size_bytes) override { 47 int64_t max_size_bytes) override {
48 return false; 48 return false;
49 } 49 }
50 bool StartLogging(rtc::PlatformFile platform_file, 50 bool StartLogging(rtc::PlatformFile platform_file,
51 int64_t max_size_bytes) override { 51 int64_t max_size_bytes) override {
52 // The platform_file is open and needs to be closed.
53 if (!rtc::ClosePlatformFile(platform_file)) {
54 LOG(LS_WARNING) << "Can't close file.";
55 }
52 return false; 56 return false;
53 } 57 }
54 void StopLogging() override {} 58 void StopLogging() override {}
55 void LogVideoReceiveStreamConfig( 59 void LogVideoReceiveStreamConfig(
56 const VideoReceiveStream::Config& config) override {} 60 const VideoReceiveStream::Config& config) override {}
57 void LogVideoSendStreamConfig( 61 void LogVideoSendStreamConfig(
58 const VideoSendStream::Config& config) override {} 62 const VideoSendStream::Config& config) override {}
59 void LogRtpHeader(PacketDirection direction, 63 void LogRtpHeader(PacketDirection direction,
60 MediaType media_type, 64 MediaType media_type,
61 const uint8_t* header, 65 const uint8_t* header,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 187 RTC_DCHECK(thread_checker_.CalledOnValidThread());
184 RtcEventLogHelperThread::ControlMessage message; 188 RtcEventLogHelperThread::ControlMessage message;
185 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE; 189 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE;
186 message.max_size_bytes = max_size_bytes <= 0 190 message.max_size_bytes = max_size_bytes <= 0
187 ? std::numeric_limits<int64_t>::max() 191 ? std::numeric_limits<int64_t>::max()
188 : max_size_bytes; 192 : max_size_bytes;
189 message.start_time = clock_->TimeInMicroseconds(); 193 message.start_time = clock_->TimeInMicroseconds();
190 message.stop_time = std::numeric_limits<int64_t>::max(); 194 message.stop_time = std::numeric_limits<int64_t>::max();
191 message.file.reset(FileWrapper::Create()); 195 message.file.reset(FileWrapper::Create());
192 if (message.file->OpenFile(file_name.c_str(), false) != 0) { 196 if (message.file->OpenFile(file_name.c_str(), false) != 0) {
197 LOG(LS_WARNING) << "Can't open file. Logging not started.";
ivoc 2016/05/26 08:56:58 "Logging" sounds a bit vague to me, how about some
pbos-webrtc 2016/05/26 12:05:18 All of these are errors and should log on LS_ERROR
terelius 2016/05/26 14:54:42 Done.
terelius 2016/05/26 14:54:42 Done.
193 return false; 198 return false;
194 } 199 }
195 if (!message_queue_.Insert(&message)) { 200 if (!message_queue_.Insert(&message)) {
196 LOG(LS_WARNING) << "Message queue full. Can't start logging."; 201 LOG(LS_WARNING) << "Message queue full. Can't start logging.";
197 return false; 202 return false;
198 } 203 }
199 return true; 204 return true;
200 } 205 }
201 206
202 bool RtcEventLogImpl::StartLogging(rtc::PlatformFile platform_file, 207 bool RtcEventLogImpl::StartLogging(rtc::PlatformFile platform_file,
203 int64_t max_size_bytes) { 208 int64_t max_size_bytes) {
204 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 209 RTC_DCHECK(thread_checker_.CalledOnValidThread());
205 RtcEventLogHelperThread::ControlMessage message; 210 RtcEventLogHelperThread::ControlMessage message;
206 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE; 211 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE;
207 message.max_size_bytes = max_size_bytes <= 0 212 message.max_size_bytes = max_size_bytes <= 0
208 ? std::numeric_limits<int64_t>::max() 213 ? std::numeric_limits<int64_t>::max()
209 : max_size_bytes; 214 : max_size_bytes;
210 message.start_time = clock_->TimeInMicroseconds(); 215 message.start_time = clock_->TimeInMicroseconds();
211 message.stop_time = std::numeric_limits<int64_t>::max(); 216 message.stop_time = std::numeric_limits<int64_t>::max();
212 message.file.reset(FileWrapper::Create()); 217 message.file.reset(FileWrapper::Create());
213 FILE* file_handle = rtc::FdopenPlatformFileForWriting(platform_file); 218 FILE* file_handle = rtc::FdopenPlatformFileForWriting(platform_file);
214 if (!file_handle) { 219 if (!file_handle) {
220 LOG(LS_WARNING) << "Can't open file. Logging not started.";
ivoc 2016/05/26 08:56:59 Same here.
terelius 2016/05/26 14:54:42 Done.
221 // Even though we failed to open a FILE*, the platform_file is still open
222 // and needs to be closed.
223 if (!rtc::ClosePlatformFile(platform_file)) {
224 LOG(LS_WARNING) << "Can't close file.";
225 }
215 return false; 226 return false;
216 } 227 }
217 if (message.file->OpenFromFileHandle(file_handle, true, false) != 0) { 228 if (message.file->OpenFromFileHandle(file_handle, true, false) != 0) {
229 LOG(LS_WARNING) << "Can't open file. Logging not started.";
ivoc 2016/05/26 08:56:59 Same here.
terelius 2016/05/26 14:54:42 Done.
218 return false; 230 return false;
219 } 231 }
220 if (!message_queue_.Insert(&message)) { 232 if (!message_queue_.Insert(&message)) {
221 LOG(LS_WARNING) << "Message queue full. Can't start logging."; 233 LOG(LS_WARNING) << "Message queue full. Can't start logging.";
222 return false; 234 return false;
223 } 235 }
ivoc 2016/05/26 08:56:58 This is kind of unrelated to this CL, but I think
pbos-webrtc 2016/05/26 12:05:18 Agreed, that'd be useful.
terelius 2016/05/26 14:54:42 Logging the filename would be very useful, but we
224 return true; 236 return true;
225 } 237 }
226 238
227 void RtcEventLogImpl::StopLogging() { 239 void RtcEventLogImpl::StopLogging() {
228 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 240 RTC_DCHECK(thread_checker_.CalledOnValidThread());
229 RtcEventLogHelperThread::ControlMessage message; 241 RtcEventLogHelperThread::ControlMessage message;
230 message.message_type = RtcEventLogHelperThread::ControlMessage::STOP_FILE; 242 message.message_type = RtcEventLogHelperThread::ControlMessage::STOP_FILE;
231 message.stop_time = clock_->TimeInMicroseconds(); 243 message.stop_time = clock_->TimeInMicroseconds();
232 while (!message_queue_.Insert(&message)) { 244 while (!message_queue_.Insert(&message)) {
233 // TODO(terelius): We would like to have a blocking Insert function in the 245 // TODO(terelius): We would like to have a blocking Insert function in the
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // RtcEventLog member functions. 465 // RtcEventLog member functions.
454 std::unique_ptr<RtcEventLog> RtcEventLog::Create(const Clock* clock) { 466 std::unique_ptr<RtcEventLog> RtcEventLog::Create(const Clock* clock) {
455 #ifdef ENABLE_RTC_EVENT_LOG 467 #ifdef ENABLE_RTC_EVENT_LOG
456 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl(clock)); 468 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl(clock));
457 #else 469 #else
458 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); 470 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
459 #endif // ENABLE_RTC_EVENT_LOG 471 #endif // ENABLE_RTC_EVENT_LOG
460 } 472 }
461 473
462 } // namespace webrtc 474 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698