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

Side by Side Diff: base/trace_event/trace_log.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/trace_event/trace_log.h" 5 #include "base/trace_event/trace_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 640
641 dispatching_to_observer_list_ = true; 641 dispatching_to_observer_list_ = true;
642 observer_list = enabled_state_observer_list_; 642 observer_list = enabled_state_observer_list_;
643 observer_map = async_observers_; 643 observer_map = async_observers_;
644 } 644 }
645 // Notify observers outside the lock in case they trigger trace events. 645 // Notify observers outside the lock in case they trigger trace events.
646 for (EnabledStateObserver* observer : observer_list) 646 for (EnabledStateObserver* observer : observer_list)
647 observer->OnTraceLogEnabled(); 647 observer->OnTraceLogEnabled();
648 for (const auto& it : observer_map) { 648 for (const auto& it : observer_map) {
649 it.second.task_runner->PostTask( 649 it.second.task_runner->PostTask(
650 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogEnabled, 650 FROM_HERE, BindOnce(&AsyncEnabledStateObserver::OnTraceLogEnabled,
651 it.second.observer)); 651 it.second.observer));
652 } 652 }
653 653
654 { 654 {
655 AutoLock lock(lock_); 655 AutoLock lock(lock_);
656 dispatching_to_observer_list_ = false; 656 dispatching_to_observer_list_ = false;
657 } 657 }
658 } 658 }
659 659
660 void TraceLog::SetArgumentFilterPredicate( 660 void TraceLog::SetArgumentFilterPredicate(
661 const ArgumentFilterPredicate& argument_filter_predicate) { 661 const ArgumentFilterPredicate& argument_filter_predicate) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 async_observers_; 741 async_observers_;
742 742
743 { 743 {
744 // Dispatch to observers outside the lock in case the observer triggers a 744 // Dispatch to observers outside the lock in case the observer triggers a
745 // trace event. 745 // trace event.
746 AutoUnlock unlock(lock_); 746 AutoUnlock unlock(lock_);
747 for (EnabledStateObserver* observer : observer_list) 747 for (EnabledStateObserver* observer : observer_list)
748 observer->OnTraceLogDisabled(); 748 observer->OnTraceLogDisabled();
749 for (const auto& it : observer_map) { 749 for (const auto& it : observer_map) {
750 it.second.task_runner->PostTask( 750 it.second.task_runner->PostTask(
751 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogDisabled, 751 FROM_HERE, BindOnce(&AsyncEnabledStateObserver::OnTraceLogDisabled,
752 it.second.observer)); 752 it.second.observer));
753 } 753 }
754 } 754 }
755 dispatching_to_observer_list_ = false; 755 dispatching_to_observer_list_ = false;
756 } 756 }
757 757
758 int TraceLog::GetNumTracesRecorded() { 758 int TraceLog::GetNumTracesRecorded() {
759 AutoLock lock(lock_); 759 AutoLock lock(lock_);
760 if (!IsEnabled()) 760 if (!IsEnabled())
761 return -1; 761 return -1;
762 return num_traces_recorded_; 762 return num_traces_recorded_;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 std::move(thread_shared_chunk_)); 886 std::move(thread_shared_chunk_));
887 } 887 }
888 888
889 for (MessageLoop* loop : thread_message_loops_) 889 for (MessageLoop* loop : thread_message_loops_)
890 thread_message_loop_task_runners.push_back(loop->task_runner()); 890 thread_message_loop_task_runners.push_back(loop->task_runner());
891 } 891 }
892 892
893 if (!thread_message_loop_task_runners.empty()) { 893 if (!thread_message_loop_task_runners.empty()) {
894 for (auto& task_runner : thread_message_loop_task_runners) { 894 for (auto& task_runner : thread_message_loop_task_runners) {
895 task_runner->PostTask( 895 task_runner->PostTask(
896 FROM_HERE, Bind(&TraceLog::FlushCurrentThread, Unretained(this), 896 FROM_HERE, BindOnce(&TraceLog::FlushCurrentThread, Unretained(this),
897 gen, discard_events)); 897 gen, discard_events));
898 } 898 }
899 flush_task_runner_->PostDelayedTask( 899 flush_task_runner_->PostDelayedTask(
900 FROM_HERE, Bind(&TraceLog::OnFlushTimeout, Unretained(this), gen, 900 FROM_HERE,
901 discard_events), 901 BindOnce(&TraceLog::OnFlushTimeout, Unretained(this), gen,
902 discard_events),
902 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs)); 903 TimeDelta::FromMilliseconds(kThreadFlushTimeoutMs));
903 return; 904 return;
904 } 905 }
905 906
906 FinishFlush(gen, discard_events); 907 FinishFlush(gen, discard_events);
907 } 908 }
908 909
909 // Usually it runs on a different thread. 910 // Usually it runs on a different thread.
910 void TraceLog::ConvertTraceEventsToTraceFormat( 911 void TraceLog::ConvertTraceEventsToTraceFormat(
911 std::unique_ptr<TraceBuffer> logged_events, 912 std::unique_ptr<TraceBuffer> logged_events,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 if (discard_events) { 963 if (discard_events) {
963 if (!flush_output_callback.is_null()) { 964 if (!flush_output_callback.is_null()) {
964 scoped_refptr<RefCountedString> empty_result = new RefCountedString; 965 scoped_refptr<RefCountedString> empty_result = new RefCountedString;
965 flush_output_callback.Run(empty_result, false); 966 flush_output_callback.Run(empty_result, false);
966 } 967 }
967 return; 968 return;
968 } 969 }
969 970
970 if (use_worker_thread_) { 971 if (use_worker_thread_) {
971 base::PostTaskWithTraits( 972 base::PostTaskWithTraits(
972 FROM_HERE, base::TaskTraits() 973 FROM_HERE,
973 .MayBlock() 974 base::TaskTraits()
974 .WithPriority(base::TaskPriority::BACKGROUND) 975 .MayBlock()
975 .WithShutdownBehavior( 976 .WithPriority(base::TaskPriority::BACKGROUND)
976 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), 977 .WithShutdownBehavior(
977 Bind(&TraceLog::ConvertTraceEventsToTraceFormat, 978 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
978 Passed(&previous_logged_events), flush_output_callback, 979 BindOnce(&TraceLog::ConvertTraceEventsToTraceFormat,
979 argument_filter_predicate)); 980 Passed(&previous_logged_events), flush_output_callback,
981 argument_filter_predicate));
980 return; 982 return;
981 } 983 }
982 984
983 ConvertTraceEventsToTraceFormat(std::move(previous_logged_events), 985 ConvertTraceEventsToTraceFormat(std::move(previous_logged_events),
984 flush_output_callback, 986 flush_output_callback,
985 argument_filter_predicate); 987 argument_filter_predicate);
986 } 988 }
987 989
988 // Run in each thread holding a local event buffer. 990 // Run in each thread holding a local event buffer.
989 void TraceLog::FlushCurrentThread(int generation, bool discard_events) { 991 void TraceLog::FlushCurrentThread(int generation, bool discard_events) {
990 { 992 {
991 AutoLock lock(lock_); 993 AutoLock lock(lock_);
992 if (!CheckGeneration(generation) || !flush_task_runner_) { 994 if (!CheckGeneration(generation) || !flush_task_runner_) {
993 // This is late. The corresponding flush has finished. 995 // This is late. The corresponding flush has finished.
994 return; 996 return;
995 } 997 }
996 } 998 }
997 999
998 // This will flush the thread local buffer. 1000 // This will flush the thread local buffer.
999 delete thread_local_event_buffer_.Get(); 1001 delete thread_local_event_buffer_.Get();
1000 1002
1001 AutoLock lock(lock_); 1003 AutoLock lock(lock_);
1002 if (!CheckGeneration(generation) || !flush_task_runner_ || 1004 if (!CheckGeneration(generation) || !flush_task_runner_ ||
1003 !thread_message_loops_.empty()) 1005 !thread_message_loops_.empty())
1004 return; 1006 return;
1005 1007
1006 flush_task_runner_->PostTask( 1008 flush_task_runner_->PostTask(
1007 FROM_HERE, Bind(&TraceLog::FinishFlush, Unretained(this), generation, 1009 FROM_HERE, BindOnce(&TraceLog::FinishFlush, Unretained(this), generation,
1008 discard_events)); 1010 discard_events));
1009 } 1011 }
1010 1012
1011 void TraceLog::OnFlushTimeout(int generation, bool discard_events) { 1013 void TraceLog::OnFlushTimeout(int generation, bool discard_events) {
1012 { 1014 {
1013 AutoLock lock(lock_); 1015 AutoLock lock(lock_);
1014 if (!CheckGeneration(generation) || !flush_task_runner_) { 1016 if (!CheckGeneration(generation) || !flush_task_runner_) {
1015 // Flush has finished before timeout. 1017 // Flush has finished before timeout.
1016 return; 1018 return;
1017 } 1019 }
1018 1020
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1735 }
1734 1736
1735 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1737 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1736 if (*category_group_enabled_) { 1738 if (*category_group_enabled_) {
1737 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1739 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1738 event_handle_); 1740 event_handle_);
1739 } 1741 }
1740 } 1742 }
1741 1743
1742 } // namespace trace_event_internal 1744 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698