| OLD | NEW |
| 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" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 log_buffer_.reset(); | 212 log_buffer_.reset(); |
| 213 logging_state_ = CLOSED; | 213 logging_state_ = CLOSED; |
| 214 FireGenericDoneCallback(&discard_callback, true, ""); | 214 FireGenericDoneCallback(&discard_callback, true, ""); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { | 217 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { |
| 218 BrowserThread::PostTask( | 218 BrowserThread::PostTask( |
| 219 BrowserThread::IO, | 219 BrowserThread::IO, |
| 220 FROM_HERE, | 220 FROM_HERE, |
| 221 base::Bind( | 221 base::Bind( |
| 222 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, this, message)); | 222 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, |
| 223 this, |
| 224 WebRtcLoggingMessageData(base::Time::Now(), 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 WebRtcLoggingMessageData& message) { |
| 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(message.Format(logging_started_time_)); |
| 266 } | 269 } |
| 267 | 270 |
| 268 void WebRtcLoggingHandlerHost::OnAddLogMessage(const std::string& message) { | 271 void WebRtcLoggingHandlerHost::OnAddLogMessages( |
| 272 const std::vector<WebRtcLoggingMessageData>& 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(messages[i].Format(logging_started_time_)); |
| 277 } |
| 278 } |
| 272 } | 279 } |
| 273 | 280 |
| 274 void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() { | 281 void WebRtcLoggingHandlerHost::OnLoggingStoppedInRenderer() { |
| 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 276 if (logging_state_ != STOPPING) { | 283 if (logging_state_ != STOPPING) { |
| 277 // If an out-of-order response is received, stop_callback_ may be invalid, | 284 // If an out-of-order response is received, stop_callback_ may be invalid, |
| 278 // and must not be invoked. | 285 // and must not be invoked. |
| 279 DLOG(ERROR) << "OnLoggingStoppedInRenderer invoked in state " | 286 DLOG(ERROR) << "OnLoggingStoppedInRenderer invoked in state " |
| 280 << logging_state_; | 287 << logging_state_; |
| 281 BadMessageReceived(); | 288 BadMessageReceived(); |
| 282 return; | 289 return; |
| 283 } | 290 } |
| 291 logging_started_time_ = base::Time(); |
| 284 logging_state_ = STOPPED; | 292 logging_state_ = STOPPED; |
| 285 FireGenericDoneCallback(&stop_callback_, true, ""); | 293 FireGenericDoneCallback(&stop_callback_, true, ""); |
| 286 } | 294 } |
| 287 | 295 |
| 288 void WebRtcLoggingHandlerHost::StartLoggingIfAllowed() { | 296 void WebRtcLoggingHandlerHost::StartLoggingIfAllowed() { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 if (!g_browser_process->webrtc_log_uploader()->ApplyForStartLogging()) { | 298 if (!g_browser_process->webrtc_log_uploader()->ApplyForStartLogging()) { |
| 291 logging_state_ = CLOSED; | 299 logging_state_ = CLOSED; |
| 292 FireGenericDoneCallback( | 300 FireGenericDoneCallback( |
| 293 &start_callback_, false, "Cannot start, maybe the maximum number of " | 301 &start_callback_, false, "Cannot start, maybe the maximum number of " |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 LogToCircularBuffer("Name: " + it->friendly_name + ", Address: " + | 399 LogToCircularBuffer("Name: " + it->friendly_name + ", Address: " + |
| 392 IPAddressToSensitiveString(it->address)); | 400 IPAddressToSensitiveString(it->address)); |
| 393 } | 401 } |
| 394 | 402 |
| 395 NotifyLoggingStarted(); | 403 NotifyLoggingStarted(); |
| 396 } | 404 } |
| 397 | 405 |
| 398 void WebRtcLoggingHandlerHost::NotifyLoggingStarted() { | 406 void WebRtcLoggingHandlerHost::NotifyLoggingStarted() { |
| 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 400 Send(new WebRtcLoggingMsg_StartLogging()); | 408 Send(new WebRtcLoggingMsg_StartLogging()); |
| 409 logging_started_time_ = base::Time::Now(); |
| 401 logging_state_ = STARTED; | 410 logging_state_ = STARTED; |
| 402 FireGenericDoneCallback(&start_callback_, true, ""); | 411 FireGenericDoneCallback(&start_callback_, true, ""); |
| 403 } | 412 } |
| 404 | 413 |
| 405 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { | 414 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { |
| 406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 407 DCHECK(circular_buffer_.get()); | 416 DCHECK(circular_buffer_.get()); |
| 408 circular_buffer_->Write(message.c_str(), message.length()); | 417 circular_buffer_->Write(message.c_str(), message.length()); |
| 409 const char eol = '\n'; | 418 const char eol = '\n'; |
| 410 circular_buffer_->Write(&eol, 1); | 419 circular_buffer_->Write(&eol, 1); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( | 459 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( |
| 451 GenericDoneCallback* callback, bool success, | 460 GenericDoneCallback* callback, bool success, |
| 452 const std::string& error_message) { | 461 const std::string& error_message) { |
| 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 454 DCHECK(!(*callback).is_null()); | 463 DCHECK(!(*callback).is_null()); |
| 455 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 464 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 456 base::Bind(*callback, success, | 465 base::Bind(*callback, success, |
| 457 error_message)); | 466 error_message)); |
| 458 (*callback).Reset(); | 467 (*callback).Reset(); |
| 459 } | 468 } |
| OLD | NEW |