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

Side by Side Diff: chrome/browser/media/webrtc_logging_handler_host.cc

Issue 218403004: Fix the timestamp generation for webrtc native log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_logging_handler_host.h" 5 #include "chrome/browser/media/webrtc_logging_handler_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/cpu.h" 11 #include "base/cpu.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/media/webrtc_log_list.h" 20 #include "chrome/browser/media/webrtc_log_list.h"
21 #include "chrome/browser/media/webrtc_log_uploader.h" 21 #include "chrome/browser/media/webrtc_log_uploader.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/media/webrtc_logging_messages.h"
25 #include "chrome/common/partial_circular_buffer.h" 24 #include "chrome/common/partial_circular_buffer.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chromeos/settings/cros_settings_names.h" 26 #include "chromeos/settings/cros_settings_names.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/content_browser_client.h" 28 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/gpu_data_manager.h" 29 #include "content/public/browser/gpu_data_manager.h"
31 #include "content/public/browser/render_process_host.h" 30 #include "content/public/browser/render_process_host.h"
32 #include "gpu/config/gpu_info.h" 31 #include "gpu/config/gpu_info.h"
33 #include "net/base/address_family.h" 32 #include "net/base/address_family.h"
34 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 log_buffer_.reset(); 211 log_buffer_.reset();
213 logging_state_ = CLOSED; 212 logging_state_ = CLOSED;
214 FireGenericDoneCallback(&discard_callback, true, ""); 213 FireGenericDoneCallback(&discard_callback, true, "");
215 } 214 }
216 215
217 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { 216 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) {
218 BrowserThread::PostTask( 217 BrowserThread::PostTask(
219 BrowserThread::IO, 218 BrowserThread::IO,
220 FROM_HERE, 219 FROM_HERE,
221 base::Bind( 220 base::Bind(
222 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, this, message)); 221 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser,
222 this,
223 base::Time::Now(),
224 message));
223 } 225 }
224 226
225 void WebRtcLoggingHandlerHost::OnChannelClosing() { 227 void WebRtcLoggingHandlerHost::OnChannelClosing() {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
227 if (logging_state_ == STARTED || logging_state_ == STOPPED) { 229 if (logging_state_ == STARTED || logging_state_ == STOPPED) {
228 if (upload_log_on_render_close_) { 230 if (upload_log_on_render_close_) {
229 logging_state_ = STOPPED; 231 logging_state_ = STOPPED;
232 logging_started_time_ = base::Time();
230 content::BrowserThread::PostTaskAndReplyWithResult( 233 content::BrowserThread::PostTaskAndReplyWithResult(
231 content::BrowserThread::FILE, 234 content::BrowserThread::FILE,
232 FROM_HERE, 235 FROM_HERE,
233 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, 236 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
234 this), 237 this),
235 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); 238 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this));
236 } else { 239 } else {
237 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); 240 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload();
238 } 241 }
239 } 242 }
240 content::BrowserMessageFilter::OnChannelClosing(); 243 content::BrowserMessageFilter::OnChannelClosing();
241 } 244 }
242 245
243 void WebRtcLoggingHandlerHost::OnDestruct() const { 246 void WebRtcLoggingHandlerHost::OnDestruct() const {
244 BrowserThread::DeleteOnIOThread::Destruct(this); 247 BrowserThread::DeleteOnIOThread::Destruct(this);
245 } 248 }
246 249
247 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, 250 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
248 bool* message_was_ok) { 251 bool* message_was_ok) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
250 bool handled = true; 253 bool handled = true;
251 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) 254 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok)
252 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_AddLogMessage, OnAddLogMessage) 255 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_AddLogMessages, OnAddLogMessages)
253 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_LoggingStopped, 256 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_LoggingStopped,
254 OnLoggingStoppedInRenderer) 257 OnLoggingStoppedInRenderer)
255 IPC_MESSAGE_UNHANDLED(handled = false) 258 IPC_MESSAGE_UNHANDLED(handled = false)
256 IPC_END_MESSAGE_MAP_EX() 259 IPC_END_MESSAGE_MAP_EX()
257 260
258 return handled; 261 return handled;
259 } 262 }
260 263
261 void WebRtcLoggingHandlerHost::AddLogMessageFromBrowser( 264 void WebRtcLoggingHandlerHost::AddLogMessageFromBrowser(
262 const std::string& message) { 265 const base::Time& timestamp, const std::string& message) {
tommi (sloooow) - chröme 2014/04/02 15:17:59 can we use WebRtcLoggingMessage here?
jiayl 2014/04/02 16:23:59 Done.
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
264 if (logging_state_ == STARTED) 267 if (logging_state_ == STARTED)
265 LogToCircularBuffer(message); 268 LogToCircularBuffer(FormatMessageWithTimestamp(timestamp, message));
tommi (sloooow) - chröme 2014/04/02 15:17:59 maybe FormatMessage should just accept WebRtcLoggi
jiayl 2014/04/02 16:23:59 Done.
266 } 269 }
267 270
268 void WebRtcLoggingHandlerHost::OnAddLogMessage(const std::string& message) { 271 void WebRtcLoggingHandlerHost::OnAddLogMessages(
272 const std::vector<WebRtcLoggingMessage>& messages) {
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
270 if (logging_state_ == STARTED || logging_state_ == STOPPING) 274 if (logging_state_ == STARTED || logging_state_ == STOPPING) {
271 LogToCircularBuffer(message); 275 for (size_t i = 0; i < messages.size(); ++i) {
276 LogToCircularBuffer(
277 FormatMessageWithTimestamp(messages[i].timestamp,
278 messages[i].message));
279 }
280 }
272 } 281 }
273 282
274 void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() { 283 void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
276 if (logging_state_ != STOPPING) { 285 if (logging_state_ != STOPPING) {
277 // If an out-of-order response is received, stop_callback_ may be invalid, 286 // If an out-of-order response is received, stop_callback_ may be invalid,
278 // and must not be invoked. 287 // and must not be invoked.
279 DLOG(ERROR) << "OnLoggingStoppedInRenderer invoked in state " 288 DLOG(ERROR) << "OnLoggingStoppedInRenderer invoked in state "
280 << logging_state_; 289 << logging_state_;
281 BadMessageReceived(); 290 BadMessageReceived();
282 return; 291 return;
283 } 292 }
293 logging_started_time_ = base::Time();
284 logging_state_ = STOPPED; 294 logging_state_ = STOPPED;
285 FireGenericDoneCallback(&stop_callback_, true, ""); 295 FireGenericDoneCallback(&stop_callback_, true, "");
286 } 296 }
287 297
288 void WebRtcLoggingHandlerHost::StartLoggingIfAllowed() { 298 void WebRtcLoggingHandlerHost::StartLoggingIfAllowed() {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290 if (!g_browser_process->webrtc_log_uploader()->ApplyForStartLogging()) { 300 if (!g_browser_process->webrtc_log_uploader()->ApplyForStartLogging()) {
291 logging_state_ = CLOSED; 301 logging_state_ = CLOSED;
292 FireGenericDoneCallback( 302 FireGenericDoneCallback(
293 &start_callback_, false, "Cannot start, maybe the maximum number of " 303 &start_callback_, false, "Cannot start, maybe the maximum number of "
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 LogToCircularBuffer("Name: " + it->friendly_name + ", Address: " + 401 LogToCircularBuffer("Name: " + it->friendly_name + ", Address: " +
392 IPAddressToSensitiveString(it->address)); 402 IPAddressToSensitiveString(it->address));
393 } 403 }
394 404
395 NotifyLoggingStarted(); 405 NotifyLoggingStarted();
396 } 406 }
397 407
398 void WebRtcLoggingHandlerHost::NotifyLoggingStarted() { 408 void WebRtcLoggingHandlerHost::NotifyLoggingStarted() {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
400 Send(new WebRtcLoggingMsg_StartLogging()); 410 Send(new WebRtcLoggingMsg_StartLogging());
411 logging_started_time_ = base::Time::Now();
401 logging_state_ = STARTED; 412 logging_state_ = STARTED;
402 FireGenericDoneCallback(&start_callback_, true, ""); 413 FireGenericDoneCallback(&start_callback_, true, "");
403 } 414 }
404 415
405 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { 416 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
407 DCHECK(circular_buffer_.get()); 418 DCHECK(circular_buffer_.get());
408 circular_buffer_->Write(message.c_str(), message.length()); 419 circular_buffer_->Write(message.c_str(), message.length());
409 const char eol = '\n'; 420 const char eol = '\n';
410 circular_buffer_->Write(&eol, 1); 421 circular_buffer_->Write(&eol, 1);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( 461 void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
451 GenericDoneCallback* callback, bool success, 462 GenericDoneCallback* callback, bool success,
452 const std::string& error_message) { 463 const std::string& error_message) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
454 DCHECK(!(*callback).is_null()); 465 DCHECK(!(*callback).is_null());
455 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 466 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
456 base::Bind(*callback, success, 467 base::Bind(*callback, success,
457 error_message)); 468 error_message));
458 (*callback).Reset(); 469 (*callback).Reset();
459 } 470 }
471
472 std::string WebRtcLoggingHandlerHost::FormatMessageWithTimestamp(
473 const base::Time& timestamp, const std::string& message) {
474 uint64 interval_ms = (timestamp - logging_started_time_).InMilliseconds();
475
476 std::string result = base::StringPrintf("[%03ld:%03ld] %s",
477 interval_ms / 1000,
478 interval_ms % 1000,
479 message.c_str());
480 return result;
481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698