Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/media/webrtc_event_log_handler.h" | 5 #include "chrome/browser/media/webrtc_event_log_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 | 22 |
| 23 // Keys used to attach handler to the RenderProcessHost | 23 // Keys used to attach handler to the RenderProcessHost |
| 24 const char WebRtcEventLogHandler::kWebRtcEventLogHandlerKey[] = | 24 const char WebRtcEventLogHandler::kWebRtcEventLogHandlerKey[] = |
| 25 "kWebRtcEventLogHandlerKey"; | 25 "kWebRtcEventLogHandlerKey"; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Returns a path name to be used as prefix for RTC event log files. | 29 // Returns a path name to be used as prefix for RTC event log files. |
| 30 base::FilePath GetWebRtcEventLogPrefixPath(const base::FilePath& directory, | 30 base::FilePath GetWebRtcEventLogPrefixPath(const base::FilePath& directory, |
| 31 uint64_t rtc_event_log_id) { | 31 uint64_t rtc_event_log_id) { |
|
Henrik Grunell
2016/05/24 13:31:59
Isn't an int enough?
Ivo-OOO until feb 6
2016/05/25 14:57:00
It probably is, but since the current code uses a
| |
| 32 static const char kWebRtcEventLogFilePrefix[] = "WebRtcEventLog."; | 32 static const char kWebRtcEventLogFilePrefix[] = "WebRtcEventLog."; |
| 33 return directory.AppendASCII(kWebRtcEventLogFilePrefix + | 33 return directory.AppendASCII(kWebRtcEventLogFilePrefix + |
| 34 base::Int64ToString(rtc_event_log_id)); | 34 base::Uint64ToString(rtc_event_log_id)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 WebRtcEventLogHandler::WebRtcEventLogHandler(Profile* profile) | 39 WebRtcEventLogHandler::WebRtcEventLogHandler(Profile* profile) |
| 40 : profile_(profile), | 40 : profile_(profile), |
| 41 is_rtc_event_logging_in_progress_(false), | |
| 42 current_rtc_event_log_id_(0) { | 41 current_rtc_event_log_id_(0) { |
| 43 DCHECK(profile_); | 42 DCHECK(profile_); |
| 44 thread_checker_.DetachFromThread(); | 43 thread_checker_.DetachFromThread(); |
| 45 } | 44 } |
| 46 | 45 |
| 47 WebRtcEventLogHandler::~WebRtcEventLogHandler() {} | 46 WebRtcEventLogHandler::~WebRtcEventLogHandler() {} |
| 48 | 47 |
| 49 void WebRtcEventLogHandler::StartWebRtcEventLogging( | 48 void WebRtcEventLogHandler::StartWebRtcEventLogging( |
| 50 content::RenderProcessHost* host, | 49 content::RenderProcessHost* host, |
| 51 base::TimeDelta delay, | 50 base::TimeDelta delay, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 } | 86 } |
| 88 | 87 |
| 89 void WebRtcEventLogHandler::DoStartWebRtcEventLogging( | 88 void WebRtcEventLogHandler::DoStartWebRtcEventLogging( |
| 90 content::RenderProcessHost* host, | 89 content::RenderProcessHost* host, |
| 91 base::TimeDelta delay, | 90 base::TimeDelta delay, |
| 92 const RecordingDoneCallback& callback, | 91 const RecordingDoneCallback& callback, |
| 93 const RecordingErrorCallback& error_callback, | 92 const RecordingErrorCallback& error_callback, |
| 94 const base::FilePath& log_directory) { | 93 const base::FilePath& log_directory) { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 | 95 |
| 97 if (is_rtc_event_logging_in_progress_) { | 96 base::FilePath prefix_path = |
| 97 GetWebRtcEventLogPrefixPath(log_directory, current_rtc_event_log_id_); | |
| 98 if (!host->StartWebRTCEventLog(prefix_path)) { | |
| 98 error_callback.Run("RTC event logging already in progress"); | 99 error_callback.Run("RTC event logging already in progress"); |
| 99 return; | 100 return; |
| 100 } | 101 } |
| 101 | 102 |
| 102 is_rtc_event_logging_in_progress_ = true; | |
| 103 base::FilePath prefix_path = | |
| 104 GetWebRtcEventLogPrefixPath(log_directory, ++current_rtc_event_log_id_); | |
| 105 host->EnableEventLogRecordings(prefix_path); | |
| 106 | |
| 107 if (delay.is_zero()) { | 103 if (delay.is_zero()) { |
| 108 const bool is_stopped = false, is_manual_stop = false; | 104 const bool is_stopped = false, is_manual_stop = false; |
| 109 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 105 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 110 return; | 106 return; |
| 111 } | 107 } |
| 112 | 108 |
| 113 const bool is_manual_stop = false; | 109 const bool is_manual_stop = false; |
| 114 BrowserThread::PostDelayedTask( | 110 BrowserThread::PostDelayedTask( |
| 115 BrowserThread::UI, FROM_HERE, | 111 BrowserThread::UI, FROM_HERE, |
| 116 base::Bind(&WebRtcEventLogHandler::DoStopWebRtcEventLogging, this, host, | 112 base::Bind(&WebRtcEventLogHandler::DoStopWebRtcEventLogging, this, host, |
| 117 is_manual_stop, current_rtc_event_log_id_, callback, | 113 is_manual_stop, ++current_rtc_event_log_id_, callback, |
|
ncarter (slow)
2016/05/20 18:27:20
This ++ doesn't make any sense to me. The paramete
Ivo-OOO until feb 6
2016/05/25 14:57:00
Right, good catch. This ++ is indeed in the wrong
| |
| 118 error_callback, log_directory), | 114 error_callback, log_directory), |
| 119 delay); | 115 delay); |
| 120 } | 116 } |
| 121 | 117 |
| 122 void WebRtcEventLogHandler::DoStopWebRtcEventLogging( | 118 void WebRtcEventLogHandler::DoStopWebRtcEventLogging( |
| 123 content::RenderProcessHost* host, | 119 content::RenderProcessHost* host, |
| 124 bool is_manual_stop, | 120 bool is_manual_stop, |
| 125 uint64_t rtc_event_log_id, | 121 uint64_t rtc_event_log_id, |
| 126 const RecordingDoneCallback& callback, | 122 const RecordingDoneCallback& callback, |
| 127 const RecordingErrorCallback& error_callback, | 123 const RecordingErrorCallback& error_callback, |
| 128 const base::FilePath& log_directory) { | 124 const base::FilePath& log_directory) { |
| 129 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 130 DCHECK_LE(rtc_event_log_id, current_rtc_event_log_id_); | 126 DCHECK_LE(rtc_event_log_id, current_rtc_event_log_id_); |
| 131 | 127 |
| 132 base::FilePath prefix_path = | 128 base::FilePath prefix_path = |
| 133 GetWebRtcEventLogPrefixPath(log_directory, rtc_event_log_id); | 129 GetWebRtcEventLogPrefixPath(log_directory, rtc_event_log_id); |
| 134 // Prevent an old posted DoStopWebRtcEventLogging() call to stop a newer dump. | 130 // Prevent an old posted DoStopWebRtcEventLogging() call to stop a newer dump. |
| 135 // This could happen in a sequence like: | 131 // This could happen in a sequence like: |
| 136 // Start(10); // Start dump 1. Post Stop() to run after 10 seconds. | 132 // Start(10); // Start dump 1. Post Stop() to run after 10 seconds. |
| 137 // Stop(); // Manually stop dump 1 before 10 seconds; | 133 // Stop(); // Manually stop dump 1 before 10 seconds; |
| 138 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. | 134 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. |
| 139 if (rtc_event_log_id < current_rtc_event_log_id_) { | 135 if (rtc_event_log_id < current_rtc_event_log_id_) { |
| 140 const bool is_stopped = false; | 136 const bool is_stopped = false; |
| 141 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 137 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 142 return; | 138 return; |
| 143 } | 139 } |
| 144 | 140 |
| 145 if (!is_rtc_event_logging_in_progress_) { | 141 if (!host->StopWebRTCEventLog()) { |
| 146 error_callback.Run("No RTC event logging in progress"); | 142 error_callback.Run("No RTC event logging in progress"); |
| 147 return; | 143 return; |
| 148 } | 144 } |
| 149 | 145 |
| 150 host->DisableEventLogRecordings(); | |
| 151 is_rtc_event_logging_in_progress_ = false; | |
| 152 const bool is_stopped = true; | 146 const bool is_stopped = true; |
| 153 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 147 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 154 } | 148 } |
| OLD | NEW |