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" |
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/media/webrtc_rtp_dump_handler.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/media/webrtc_logging_messages.h" | 25 #include "chrome/common/media/webrtc_logging_messages.h" |
25 #include "chrome/common/partial_circular_buffer.h" | 26 #include "chrome/common/partial_circular_buffer.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chromeos/settings/cros_settings_names.h" | 28 #include "chromeos/settings/cros_settings_names.h" |
28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
30 #include "content/public/browser/gpu_data_manager.h" | 31 #include "content/public/browser/gpu_data_manager.h" |
31 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
32 #include "gpu/config/gpu_info.h" | 33 #include "gpu/config/gpu_info.h" |
33 #include "net/base/address_family.h" | 34 #include "net/base/address_family.h" |
34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
35 | 36 |
36 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
37 #include "base/linux_util.h" | 38 #include "base/linux_util.h" |
38 #endif | 39 #endif |
39 | 40 |
40 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
41 #include "base/mac/mac_util.h" | 42 #include "base/mac/mac_util.h" |
42 #endif | 43 #endif |
43 | 44 |
44 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
45 #include "chromeos/system/statistics_provider.h" | 46 #include "chromeos/system/statistics_provider.h" |
46 #endif | 47 #endif |
47 | 48 |
48 using base::IntToString; | 49 using base::IntToString; |
49 using content::BrowserThread; | 50 using content::BrowserThread; |
| 51 using content::RtpDumpType; |
50 | 52 |
| 53 namespace { |
51 | 54 |
52 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
53 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB | 56 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
54 #else | 57 #else |
55 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB | 58 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
56 #endif | 59 #endif |
57 | 60 |
58 namespace { | |
59 | |
60 const char kLogNotStoppedOrNoLogOpen[] = | 61 const char kLogNotStoppedOrNoLogOpen[] = |
61 "Logging not stopped or no log open."; | 62 "Logging not stopped or no log open."; |
62 | 63 |
63 // For privacy reasons when logging IP addresses. The returned "sensitive | 64 // For privacy reasons when logging IP addresses. The returned "sensitive |
64 // string" is for release builds a string with the end stripped away. Last | 65 // string" is for release builds a string with the end stripped away. Last |
65 // octet for IPv4 and last 80 bits (5 groups) for IPv6. String will be | 66 // octet for IPv4 and last 80 bits (5 groups) for IPv6. String will be |
66 // "1.2.3.x" and "1.2.3::" respectively. For debug builds, the string is | 67 // "1.2.3.x" and "1.2.3::" respectively. For debug builds, the string is |
67 // not stripped. | 68 // not stripped. |
68 std::string IPAddressToSensitiveString(const net::IPAddressNumber& address) { | 69 std::string IPAddressToSensitiveString(const net::IPAddressNumber& address) { |
69 #if defined(NDEBUG) | 70 #if defined(NDEBUG) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 184 } |
184 return; | 185 return; |
185 } | 186 } |
186 upload_callback_ = callback; | 187 upload_callback_ = callback; |
187 logging_state_ = UPLOADING; | 188 logging_state_ = UPLOADING; |
188 content::BrowserThread::PostTaskAndReplyWithResult( | 189 content::BrowserThread::PostTaskAndReplyWithResult( |
189 content::BrowserThread::FILE, | 190 content::BrowserThread::FILE, |
190 FROM_HERE, | 191 FROM_HERE, |
191 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 192 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
192 this), | 193 this), |
193 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); | 194 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
194 } | 195 } |
195 | 196 |
196 void WebRtcLoggingHandlerHost::UploadLogDone() { | 197 void WebRtcLoggingHandlerHost::UploadLogDone() { |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
198 logging_state_ = CLOSED; | 199 logging_state_ = CLOSED; |
199 } | 200 } |
200 | 201 |
201 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { | 202 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
203 DCHECK(!callback.is_null()); | 204 DCHECK(!callback.is_null()); |
204 | 205 |
205 GenericDoneCallback discard_callback = callback; | 206 GenericDoneCallback discard_callback = callback; |
206 if (logging_state_ != STOPPED) { | 207 if (logging_state_ != STOPPED) { |
207 FireGenericDoneCallback(&discard_callback, false, | 208 FireGenericDoneCallback(&discard_callback, false, |
208 kLogNotStoppedOrNoLogOpen); | 209 kLogNotStoppedOrNoLogOpen); |
209 return; | 210 return; |
210 } | 211 } |
211 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); | 212 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
212 circular_buffer_.reset(); | 213 circular_buffer_.reset(); |
213 log_buffer_.reset(); | 214 log_buffer_.reset(); |
214 logging_state_ = CLOSED; | 215 logging_state_ = CLOSED; |
| 216 rtp_dump_handler_.reset(); |
215 FireGenericDoneCallback(&discard_callback, true, ""); | 217 FireGenericDoneCallback(&discard_callback, true, ""); |
216 } | 218 } |
217 | 219 |
218 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { | 220 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { |
219 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
220 BrowserThread::IO, | 222 BrowserThread::IO, |
221 FROM_HERE, | 223 FROM_HERE, |
222 base::Bind( | 224 base::Bind( |
223 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, | 225 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, |
224 this, | 226 this, |
225 WebRtcLoggingMessageData(base::Time::Now(), message))); | 227 WebRtcLoggingMessageData(base::Time::Now(), message))); |
226 } | 228 } |
227 | 229 |
228 void WebRtcLoggingHandlerHost::StartRtpDump( | 230 void WebRtcLoggingHandlerHost::StartRtpDump( |
229 bool incoming, | 231 RtpDumpType type, |
230 bool outgoing, | 232 const GenericDoneCallback& callback, |
231 const GenericDoneCallback& callback) { | 233 const content::RenderProcessHost::WebRtcStopRtpDumpCallback& |
232 NOTIMPLEMENTED(); | 234 stop_callback) { |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 236 DCHECK(!callback.is_null()); |
| 237 |
| 238 stop_rtp_dump_callback_ = stop_callback; |
| 239 |
| 240 if (!rtp_dump_handler_) { |
| 241 content::BrowserThread::PostTaskAndReplyWithResult( |
| 242 content::BrowserThread::FILE, |
| 243 FROM_HERE, |
| 244 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 245 this), |
| 246 base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart, |
| 247 this, |
| 248 type, |
| 249 callback)); |
| 250 return; |
| 251 } |
| 252 |
| 253 GenericDoneCallback start_callback = callback; |
| 254 DoStartRtpDump(type, &start_callback); |
233 } | 255 } |
234 | 256 |
235 void WebRtcLoggingHandlerHost::StopRtpDump( | 257 void WebRtcLoggingHandlerHost::StopRtpDump( |
236 bool incoming, | 258 RtpDumpType type, |
237 bool outgoing, | |
238 const GenericDoneCallback& callback) { | 259 const GenericDoneCallback& callback) { |
239 NOTIMPLEMENTED(); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 261 DCHECK(!callback.is_null()); |
| 262 |
| 263 if (!rtp_dump_handler_) { |
| 264 GenericDoneCallback stop_callback = callback; |
| 265 FireGenericDoneCallback( |
| 266 &stop_callback, false, "RTP dump has not been started."); |
| 267 return; |
| 268 } |
| 269 |
| 270 DCHECK(!stop_rtp_dump_callback_.is_null()); |
| 271 stop_rtp_dump_callback_.Run(type); |
| 272 |
| 273 rtp_dump_handler_->StopDump(type, callback); |
| 274 } |
| 275 |
| 276 void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header, |
| 277 size_t header_length, |
| 278 size_t packet_length, |
| 279 bool incoming) { |
| 280 scoped_ptr<uint8[]> header_data(new uint8[header_length]); |
| 281 memcpy(header_data.get(), packet_header, header_length); |
| 282 |
| 283 BrowserThread::PostTask( |
| 284 BrowserThread::IO, |
| 285 FROM_HERE, |
| 286 base::Bind(&WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread, |
| 287 this, |
| 288 base::Passed(&header_data), |
| 289 header_length, |
| 290 packet_length, |
| 291 incoming)); |
| 292 } |
| 293 |
| 294 void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread( |
| 295 scoped_ptr<uint8[]> packet_header, |
| 296 size_t header_length, |
| 297 size_t packet_length, |
| 298 bool incoming) { |
| 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 300 |
| 301 if (rtp_dump_handler_) { |
| 302 rtp_dump_handler_->OnRtpPacket( |
| 303 packet_header.get(), header_length, packet_length, incoming); |
| 304 } |
240 } | 305 } |
241 | 306 |
242 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 307 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
244 if (logging_state_ == STARTED || logging_state_ == STOPPED) { | 309 if (logging_state_ == STARTED || logging_state_ == STOPPED) { |
245 if (upload_log_on_render_close_) { | 310 if (upload_log_on_render_close_) { |
246 logging_state_ = UPLOADING; | 311 logging_state_ = UPLOADING; |
247 logging_started_time_ = base::Time(); | 312 logging_started_time_ = base::Time(); |
248 content::BrowserThread::PostTaskAndReplyWithResult( | 313 content::BrowserThread::PostTaskAndReplyWithResult( |
249 content::BrowserThread::FILE, | 314 content::BrowserThread::FILE, |
250 FROM_HERE, | 315 FROM_HERE, |
251 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 316 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
252 this), | 317 this), |
253 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); | 318 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
254 } else { | 319 } else { |
255 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); | 320 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
256 } | 321 } |
257 } | 322 } |
258 content::BrowserMessageFilter::OnChannelClosing(); | 323 content::BrowserMessageFilter::OnChannelClosing(); |
259 } | 324 } |
260 | 325 |
261 void WebRtcLoggingHandlerHost::OnDestruct() const { | 326 void WebRtcLoggingHandlerHost::OnDestruct() const { |
262 BrowserThread::DeleteOnIOThread::Destruct(this); | 327 BrowserThread::DeleteOnIOThread::Destruct(this); |
263 } | 328 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 base::FilePath log_dir_path = | 510 base::FilePath log_dir_path = |
446 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); | 511 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); |
447 base::File::Error error; | 512 base::File::Error error; |
448 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) { | 513 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) { |
449 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error; | 514 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error; |
450 return base::FilePath(); | 515 return base::FilePath(); |
451 } | 516 } |
452 return log_dir_path; | 517 return log_dir_path; |
453 } | 518 } |
454 | 519 |
455 void WebRtcLoggingHandlerHost::TriggerUploadLog( | 520 void WebRtcLoggingHandlerHost::TriggerUpload( |
456 const base::FilePath& log_directory) { | 521 const base::FilePath& log_directory) { |
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
458 DCHECK_EQ(logging_state_, UPLOADING); | 523 DCHECK_EQ(logging_state_, UPLOADING); |
459 | 524 |
| 525 WebRtcRtpDumpHandler::ReleasedDumps dumps; |
| 526 if (rtp_dump_handler_) |
| 527 dumps = rtp_dump_handler_->ReleaseDumps(); |
| 528 |
| 529 DoUploadLogAndDumps(log_directory, dumps); |
| 530 } |
| 531 |
| 532 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( |
| 533 GenericDoneCallback* callback, |
| 534 bool success, |
| 535 const std::string& error_message) { |
| 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 537 DCHECK(!(*callback).is_null()); |
| 538 content::BrowserThread::PostTask( |
| 539 content::BrowserThread::UI, |
| 540 FROM_HERE, |
| 541 base::Bind(*callback, success, error_message)); |
| 542 (*callback).Reset(); |
| 543 } |
| 544 |
| 545 void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart( |
| 546 RtpDumpType type, |
| 547 GenericDoneCallback callback, |
| 548 const base::FilePath& dump_dir) { |
| 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 550 |
| 551 if (!rtp_dump_handler_) |
| 552 rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir)); |
| 553 |
| 554 DoStartRtpDump(type, &callback); |
| 555 } |
| 556 |
| 557 void WebRtcLoggingHandlerHost::DoStartRtpDump(RtpDumpType type, |
| 558 GenericDoneCallback* callback) { |
| 559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 560 DCHECK(rtp_dump_handler_); |
| 561 |
| 562 std::string error; |
| 563 |
| 564 bool result = rtp_dump_handler_->StartDump(type, &error); |
| 565 FireGenericDoneCallback(callback, result, error); |
| 566 } |
| 567 |
| 568 void WebRtcLoggingHandlerHost::DoUploadLogAndDumps( |
| 569 const base::FilePath& log_directory, |
| 570 const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps) { |
460 WebRtcLogUploadDoneData upload_done_data; | 571 WebRtcLogUploadDoneData upload_done_data; |
461 upload_done_data.log_path = log_directory; | 572 upload_done_data.log_path = log_directory; |
| 573 |
| 574 if (!rtp_dumps.incoming_dump_path.empty()) { |
| 575 upload_done_data.rtp_dumps.push_back( |
| 576 WebRtcRtpDumpDescription("rtpdump_recv", rtp_dumps.incoming_dump_path)); |
| 577 } |
| 578 |
| 579 if (!rtp_dumps.outgoing_dump_path.empty()) { |
| 580 upload_done_data.rtp_dumps.push_back( |
| 581 WebRtcRtpDumpDescription("rtpdump_send", rtp_dumps.outgoing_dump_path)); |
| 582 } |
| 583 |
462 upload_done_data.callback = upload_callback_; | 584 upload_done_data.callback = upload_callback_; |
463 upload_done_data.host = this; | 585 upload_done_data.host = this; |
464 upload_callback_.Reset(); | 586 upload_callback_.Reset(); |
465 | 587 |
466 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | 588 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
467 &WebRtcLogUploader::LoggingStoppedDoUpload, | 589 &WebRtcLogUploader::LoggingStoppedDoUpload, |
468 base::Unretained(g_browser_process->webrtc_log_uploader()), | 590 base::Unretained(g_browser_process->webrtc_log_uploader()), |
469 Passed(&log_buffer_), | 591 Passed(&log_buffer_), |
470 kWebRtcLogSize, | 592 kWebRtcLogSize, |
471 meta_data_, | 593 meta_data_, |
472 upload_done_data)); | 594 upload_done_data)); |
473 | 595 |
474 meta_data_.clear(); | 596 meta_data_.clear(); |
475 circular_buffer_.reset(); | 597 circular_buffer_.reset(); |
476 } | 598 } |
477 | |
478 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( | |
479 GenericDoneCallback* callback, bool success, | |
480 const std::string& error_message) { | |
481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
482 DCHECK(!(*callback).is_null()); | |
483 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
484 base::Bind(*callback, success, | |
485 error_message)); | |
486 (*callback).Reset(); | |
487 } | |
OLD | NEW |