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 "content/browser/tracing/tracing_controller_impl.h" | 5 #include "content/browser/tracing/tracing_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 return false; | 417 return false; |
418 | 418 |
419 pending_trace_buffer_percent_full_callback_ = callback; | 419 pending_trace_buffer_percent_full_callback_ = callback; |
420 | 420 |
421 // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below. | 421 // Count myself in pending_trace_buffer_percent_full_ack_count_, acked below. |
422 pending_trace_buffer_percent_full_ack_count_ = | 422 pending_trace_buffer_percent_full_ack_count_ = |
423 trace_message_filters_.size() + 1; | 423 trace_message_filters_.size() + 1; |
424 pending_trace_buffer_percent_full_filters_ = trace_message_filters_; | 424 pending_trace_buffer_percent_full_filters_ = trace_message_filters_; |
425 maximum_trace_buffer_percent_full_ = 0; | 425 maximum_trace_buffer_percent_full_ = 0; |
426 | 426 |
427 // Handle special case of zero child processes. | 427 // Call OnTraceBufferPercentFullReply unconditionally for the browser process. |
428 if (pending_trace_buffer_percent_full_ack_count_ == 1) { | 428 // This will result in immediate execution of the callback if there are no |
429 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 429 // child processes. |
430 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | 430 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
431 base::Unretained(this), | 431 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, |
432 scoped_refptr<TraceMessageFilter>(), | 432 base::Unretained(this), |
433 TraceLog::GetInstance()->GetBufferPercentFull())); | 433 scoped_refptr<TraceMessageFilter>(), |
434 } | 434 TraceLog::GetInstance()->GetBufferPercentFull())); |
435 | 435 |
436 // Notify all child processes. | 436 // Notify all child processes. |
437 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 437 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
438 it != trace_message_filters_.end(); ++it) { | 438 it != trace_message_filters_.end(); ++it) { |
439 it->get()->SendGetTraceBufferPercentFull(); | 439 it->get()->SendGetTraceBufferPercentFull(); |
440 } | 440 } |
441 return true; | 441 return true; |
442 } | 442 } |
443 | 443 |
444 bool TracingControllerImpl::SetWatchEvent( | 444 bool TracingControllerImpl::SetWatchEvent( |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 750 |
751 maximum_trace_buffer_percent_full_ = | 751 maximum_trace_buffer_percent_full_ = |
752 std::max(maximum_trace_buffer_percent_full_, percent_full); | 752 std::max(maximum_trace_buffer_percent_full_, percent_full); |
753 | 753 |
754 if (--pending_trace_buffer_percent_full_ack_count_ == 0) { | 754 if (--pending_trace_buffer_percent_full_ack_count_ == 0) { |
755 // Trigger callback if one is set. | 755 // Trigger callback if one is set. |
756 pending_trace_buffer_percent_full_callback_.Run( | 756 pending_trace_buffer_percent_full_callback_.Run( |
757 maximum_trace_buffer_percent_full_); | 757 maximum_trace_buffer_percent_full_); |
758 pending_trace_buffer_percent_full_callback_.Reset(); | 758 pending_trace_buffer_percent_full_callback_.Reset(); |
759 } | 759 } |
760 | |
761 if (pending_trace_buffer_percent_full_ack_count_ == 1) { | |
762 // The last ack represents local trace, so we need to ack it now. Note that | |
763 // this code only executes if there were child processes. | |
764 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
765 base::Bind(&TracingControllerImpl::OnTraceBufferPercentFullReply, | |
766 base::Unretained(this), | |
767 make_scoped_refptr(trace_message_filter), | |
768 TraceLog::GetInstance()->GetBufferPercentFull())); | |
769 } | |
770 } | 760 } |
771 | 761 |
772 void TracingControllerImpl::OnWatchEventMatched() { | 762 void TracingControllerImpl::OnWatchEventMatched() { |
773 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 763 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
774 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 764 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
775 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 765 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
776 base::Unretained(this))); | 766 base::Unretained(this))); |
777 return; | 767 return; |
778 } | 768 } |
779 | 769 |
780 if (!watch_event_callback_.is_null()) | 770 if (!watch_event_callback_.is_null()) |
781 watch_event_callback_.Run(); | 771 watch_event_callback_.Run(); |
782 } | 772 } |
783 | 773 |
784 } // namespace content | 774 } // namespace content |
OLD | NEW |