| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include "content/browser/tracing/tracing_controller_impl.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/browser/tracing/trace_message_filter.h" | 12 #include "content/browser/tracing/trace_message_filter.h" |
| 13 #include "content/browser/tracing/tracing_ui.h" | 13 #include "content/browser/tracing/tracing_ui.h" |
| 14 #include "content/common/child_process_messages.h" | 14 #include "content/common/child_process_messages.h" |
| 15 #include "content/public/browser/browser_message_filter.h" | 15 #include "content/public/browser/browser_message_filter.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 | 17 |
| 18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chromeos/dbus/debug_daemon_client.h" | 20 #include "chromeos/dbus/debug_daemon_client.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "content/browser/tracing/etw_system_event_consumer_win.h" | 24 #include "content/browser/tracing/etw_system_event_consumer_win.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 using base::debug::TraceLog; | 27 using base::trace_event::TraceLog; |
| 28 using base::debug::TraceOptions; | 28 using base::trace_event::TraceOptions; |
| 29 using base::debug::CategoryFilter; | 29 using base::trace_event::CategoryFilter; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = | 35 base::LazyInstance<TracingControllerImpl>::Leaky g_controller = |
| 36 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
| 37 | 37 |
| 38 class FileTraceDataSink : public TracingController::TraceDataSink { | 38 class FileTraceDataSink : public TracingController::TraceDataSink { |
| 39 public: | 39 public: |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 | 258 |
| 259 base::Closure on_enable_recording_done_callback = | 259 base::Closure on_enable_recording_done_callback = |
| 260 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, | 260 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, |
| 261 base::Unretained(this), | 261 base::Unretained(this), |
| 262 category_filter, trace_options, callback); | 262 category_filter, trace_options, callback); |
| 263 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 263 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 264 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | 264 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
| 265 base::Unretained(this), | 265 base::Unretained(this), |
| 266 category_filter, | 266 category_filter, |
| 267 base::debug::TraceLog::RECORDING_MODE, | 267 base::trace_event::TraceLog::RECORDING_MODE, |
| 268 trace_options, | 268 trace_options, |
| 269 on_enable_recording_done_callback)); | 269 on_enable_recording_done_callback)); |
| 270 return true; | 270 return true; |
| 271 } | 271 } |
| 272 | 272 |
| 273 void TracingControllerImpl::OnEnableRecordingDone( | 273 void TracingControllerImpl::OnEnableRecordingDone( |
| 274 const CategoryFilter& category_filter, | 274 const CategoryFilter& category_filter, |
| 275 const TraceOptions& trace_options, | 275 const TraceOptions& trace_options, |
| 276 const EnableRecordingDoneCallback& callback) { | 276 const EnableRecordingDoneCallback& callback) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 trace_options_ = trace_options; | 376 trace_options_ = trace_options; |
| 377 | 377 |
| 378 base::Closure on_enable_monitoring_done_callback = | 378 base::Closure on_enable_monitoring_done_callback = |
| 379 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, | 379 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, |
| 380 base::Unretained(this), | 380 base::Unretained(this), |
| 381 category_filter, trace_options, callback); | 381 category_filter, trace_options, callback); |
| 382 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 382 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 383 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | 383 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
| 384 base::Unretained(this), | 384 base::Unretained(this), |
| 385 category_filter, | 385 category_filter, |
| 386 base::debug::TraceLog::MONITORING_MODE, | 386 base::trace_event::TraceLog::MONITORING_MODE, |
| 387 trace_options, | 387 trace_options, |
| 388 on_enable_monitoring_done_callback)); | 388 on_enable_monitoring_done_callback)); |
| 389 return true; | 389 return true; |
| 390 } | 390 } |
| 391 | 391 |
| 392 void TracingControllerImpl::OnEnableMonitoringDone( | 392 void TracingControllerImpl::OnEnableMonitoringDone( |
| 393 const CategoryFilter& category_filter, | 393 const CategoryFilter& category_filter, |
| 394 const TraceOptions& trace_options, | 394 const TraceOptions& trace_options, |
| 395 const EnableMonitoringDoneCallback& callback) { | 395 const EnableMonitoringDoneCallback& callback) { |
| 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 return false; | 508 return false; |
| 509 | 509 |
| 510 pending_trace_buffer_usage_callback_ = callback; | 510 pending_trace_buffer_usage_callback_ = callback; |
| 511 | 511 |
| 512 // Count myself in pending_trace_log_status_ack_count_, acked below. | 512 // Count myself in pending_trace_log_status_ack_count_, acked below. |
| 513 pending_trace_log_status_ack_count_ = trace_message_filters_.size() + 1; | 513 pending_trace_log_status_ack_count_ = trace_message_filters_.size() + 1; |
| 514 pending_trace_log_status_filters_ = trace_message_filters_; | 514 pending_trace_log_status_filters_ = trace_message_filters_; |
| 515 maximum_trace_buffer_usage_ = 0; | 515 maximum_trace_buffer_usage_ = 0; |
| 516 approximate_event_count_ = 0; | 516 approximate_event_count_ = 0; |
| 517 | 517 |
| 518 base::debug::TraceLogStatus status = TraceLog::GetInstance()->GetStatus(); | 518 base::trace_event::TraceLogStatus status = |
| 519 TraceLog::GetInstance()->GetStatus(); |
| 519 // Call OnTraceLogStatusReply unconditionally for the browser process. | 520 // Call OnTraceLogStatusReply unconditionally for the browser process. |
| 520 // This will result in immediate execution of the callback if there are no | 521 // This will result in immediate execution of the callback if there are no |
| 521 // child processes. | 522 // child processes. |
| 522 BrowserThread::PostTask( | 523 BrowserThread::PostTask( |
| 523 BrowserThread::UI, FROM_HERE, | 524 BrowserThread::UI, FROM_HERE, |
| 524 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 525 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 525 base::Unretained(this), scoped_refptr<TraceMessageFilter>(), | 526 base::Unretained(this), scoped_refptr<TraceMessageFilter>(), |
| 526 status)); | 527 status)); |
| 527 | 528 |
| 528 // Notify all child processes. | 529 // Notify all child processes. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 637 } |
| 637 if (pending_trace_log_status_ack_count_ > 0) { | 638 if (pending_trace_log_status_ack_count_ > 0) { |
| 638 TraceMessageFilterSet::const_iterator it = | 639 TraceMessageFilterSet::const_iterator it = |
| 639 pending_trace_log_status_filters_.find(trace_message_filter); | 640 pending_trace_log_status_filters_.find(trace_message_filter); |
| 640 if (it != pending_trace_log_status_filters_.end()) { | 641 if (it != pending_trace_log_status_filters_.end()) { |
| 641 BrowserThread::PostTask( | 642 BrowserThread::PostTask( |
| 642 BrowserThread::UI, FROM_HERE, | 643 BrowserThread::UI, FROM_HERE, |
| 643 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 644 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 644 base::Unretained(this), | 645 base::Unretained(this), |
| 645 make_scoped_refptr(trace_message_filter), | 646 make_scoped_refptr(trace_message_filter), |
| 646 base::debug::TraceLogStatus())); | 647 base::trace_event::TraceLogStatus())); |
| 647 } | 648 } |
| 648 } | 649 } |
| 649 | 650 |
| 650 trace_message_filters_.erase(trace_message_filter); | 651 trace_message_filters_.erase(trace_message_filter); |
| 651 } | 652 } |
| 652 | 653 |
| 653 void TracingControllerImpl::OnDisableRecordingAcked( | 654 void TracingControllerImpl::OnDisableRecordingAcked( |
| 654 TraceMessageFilter* trace_message_filter, | 655 TraceMessageFilter* trace_message_filter, |
| 655 const std::vector<std::string>& known_category_groups) { | 656 const std::vector<std::string>& known_category_groups) { |
| 656 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 657 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 814 |
| 814 if (has_more_events) | 815 if (has_more_events) |
| 815 return; | 816 return; |
| 816 | 817 |
| 817 // Simulate an CaptureMonitoringSnapshotAcked for the local trace. | 818 // Simulate an CaptureMonitoringSnapshotAcked for the local trace. |
| 818 OnCaptureMonitoringSnapshotAcked(NULL); | 819 OnCaptureMonitoringSnapshotAcked(NULL); |
| 819 } | 820 } |
| 820 | 821 |
| 821 void TracingControllerImpl::OnTraceLogStatusReply( | 822 void TracingControllerImpl::OnTraceLogStatusReply( |
| 822 TraceMessageFilter* trace_message_filter, | 823 TraceMessageFilter* trace_message_filter, |
| 823 const base::debug::TraceLogStatus& status) { | 824 const base::trace_event::TraceLogStatus& status) { |
| 824 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 825 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 825 BrowserThread::PostTask( | 826 BrowserThread::PostTask( |
| 826 BrowserThread::UI, FROM_HERE, | 827 BrowserThread::UI, FROM_HERE, |
| 827 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 828 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 828 base::Unretained(this), | 829 base::Unretained(this), |
| 829 make_scoped_refptr(trace_message_filter), status)); | 830 make_scoped_refptr(trace_message_filter), status)); |
| 830 return; | 831 return; |
| 831 } | 832 } |
| 832 | 833 |
| 833 if (pending_trace_log_status_ack_count_ == 0) | 834 if (pending_trace_log_status_ack_count_ == 0) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 is_monitoring_ = is_monitoring; | 884 is_monitoring_ = is_monitoring; |
| 884 #if !defined(OS_ANDROID) | 885 #if !defined(OS_ANDROID) |
| 885 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 886 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
| 886 it != tracing_uis_.end(); it++) { | 887 it != tracing_uis_.end(); it++) { |
| 887 (*it)->OnMonitoringStateChanged(is_monitoring); | 888 (*it)->OnMonitoringStateChanged(is_monitoring); |
| 888 } | 889 } |
| 889 #endif | 890 #endif |
| 890 } | 891 } |
| 891 | 892 |
| 892 } // namespace content | 893 } // namespace content |
| OLD | NEW |