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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 2957383002: [Cleanup] Use a sequence checker rather than a thread checker for the metrics service. (Closed)
Patch Set: Created 3 years, 5 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 | « chrome/browser/metrics/chrome_metrics_service_client.h ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 #endif 309 #endif
310 #if defined(OS_WIN) 310 #if defined(OS_WIN)
311 google_update_metrics_provider_(nullptr), 311 google_update_metrics_provider_(nullptr),
312 watcher_metrics_provider_(nullptr), 312 watcher_metrics_provider_(nullptr),
313 antivirus_metrics_provider_(nullptr), 313 antivirus_metrics_provider_(nullptr),
314 #endif 314 #endif
315 drive_metrics_provider_(nullptr), 315 drive_metrics_provider_(nullptr),
316 start_time_(base::TimeTicks::Now()), 316 start_time_(base::TimeTicks::Now()),
317 has_uploaded_profiler_data_(false), 317 has_uploaded_profiler_data_(false),
318 weak_ptr_factory_(this) { 318 weak_ptr_factory_(this) {
319 DCHECK(thread_checker_.CalledOnValidThread()); 319 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
320 RecordCommandLineMetrics(); 320 RecordCommandLineMetrics();
321 RegisterForNotifications(); 321 RegisterForNotifications();
322 } 322 }
323 323
324 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { 324 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
325 DCHECK(thread_checker_.CalledOnValidThread()); 325 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
326 base::GlobalHistogramAllocator* allocator = 326 base::GlobalHistogramAllocator* allocator =
327 base::GlobalHistogramAllocator::Get(); 327 base::GlobalHistogramAllocator::Get();
328 if (allocator) { 328 if (allocator) {
329 // A normal shutdown is almost complete so there is no benefit in keeping a 329 // A normal shutdown is almost complete so there is no benefit in keeping a
330 // file with no new data to be processed during the next startup sequence. 330 // file with no new data to be processed during the next startup sequence.
331 // Deleting the file during shutdown adds an extra disk-access or two to 331 // Deleting the file during shutdown adds an extra disk-access or two to
332 // shutdown but eliminates the unnecessary processing of the contents during 332 // shutdown but eliminates the unnecessary processing of the contents during
333 // startup only to find nothing. 333 // startup only to find nothing.
334 allocator->DeletePersistentLocation(); 334 allocator->DeletePersistentLocation();
335 } 335 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // |task.Run()| can be asynchronous or synchronous. For the latter case, we 510 // |task.Run()| can be asynchronous or synchronous. For the latter case, we
511 // may recurse back to this function. Therefore we must pop_front() first. 511 // may recurse back to this function. Therefore we must pop_front() first.
512 initialize_task_queue_.pop_front(); 512 initialize_task_queue_.pop_front();
513 // Assumes this causes |OnInitNextTask()| to be called again for all but the 513 // Assumes this causes |OnInitNextTask()| to be called again for all but the
514 // last task in |initialize_task_queue_|. 514 // last task in |initialize_task_queue_|.
515 task.Run(); 515 task.Run();
516 } 516 }
517 517
518 void ChromeMetricsServiceClient::CollectFinalMetricsForLog( 518 void ChromeMetricsServiceClient::CollectFinalMetricsForLog(
519 const base::Closure& done_callback) { 519 const base::Closure& done_callback) {
520 DCHECK(thread_checker_.CalledOnValidThread()); 520 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
521 521
522 collect_final_metrics_done_callback_ = done_callback; 522 collect_final_metrics_done_callback_ = done_callback;
523 523
524 if (ShouldIncludeProfilerDataInLog()) { 524 if (ShouldIncludeProfilerDataInLog()) {
525 // Fetch profiler data. This will call into 525 // Fetch profiler data. This will call into
526 // |FinishedReceivingProfilerData()| when the task completes. 526 // |FinishedReceivingProfilerData()| when the task completes.
527 metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( 527 metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously(
528 weak_ptr_factory_.GetWeakPtr()); 528 weak_ptr_factory_.GetWeakPtr());
529 } else { 529 } else {
530 CollectFinalHistograms(); 530 CollectFinalHistograms();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 process_data_phase, attributes.process_id, attributes.process_type, 783 process_data_phase, attributes.process_id, attributes.process_type,
784 attributes.profiling_phase, attributes.phase_start - start_time_, 784 attributes.profiling_phase, attributes.phase_start - start_time_,
785 attributes.phase_finish - start_time_, past_events); 785 attributes.phase_finish - start_time_, past_events);
786 } 786 }
787 787
788 void ChromeMetricsServiceClient::FinishedReceivingProfilerData() { 788 void ChromeMetricsServiceClient::FinishedReceivingProfilerData() {
789 CollectFinalHistograms(); 789 CollectFinalHistograms();
790 } 790 }
791 791
792 void ChromeMetricsServiceClient::CollectFinalHistograms() { 792 void ChromeMetricsServiceClient::CollectFinalHistograms() {
793 DCHECK(thread_checker_.CalledOnValidThread()); 793 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
794 794
795 // Begin the multi-step process of collecting memory usage histograms: 795 // Begin the multi-step process of collecting memory usage histograms:
796 // First spawn a task to collect the memory details; when that task is 796 // First spawn a task to collect the memory details; when that task is
797 // finished, it will call OnMemoryDetailCollectionDone. That will in turn 797 // finished, it will call OnMemoryDetailCollectionDone. That will in turn
798 // call HistogramSynchronization to collect histograms from all renderers and 798 // call HistogramSynchronization to collect histograms from all renderers and
799 // then call OnHistogramSynchronizationDone to continue processing. 799 // then call OnHistogramSynchronizationDone to continue processing.
800 DCHECK(!waiting_for_collect_final_metrics_step_); 800 DCHECK(!waiting_for_collect_final_metrics_step_);
801 waiting_for_collect_final_metrics_step_ = true; 801 waiting_for_collect_final_metrics_step_ = true;
802 802
803 base::Closure callback = 803 base::Closure callback =
804 base::Bind(&ChromeMetricsServiceClient::OnMemoryDetailCollectionDone, 804 base::Bind(&ChromeMetricsServiceClient::OnMemoryDetailCollectionDone,
805 weak_ptr_factory_.GetWeakPtr()); 805 weak_ptr_factory_.GetWeakPtr());
806 806
807 scoped_refptr<MetricsMemoryDetails> details( 807 scoped_refptr<MetricsMemoryDetails> details(
808 new MetricsMemoryDetails(callback, &memory_growth_tracker_)); 808 new MetricsMemoryDetails(callback, &memory_growth_tracker_));
809 details->StartFetch(); 809 details->StartFetch();
810 810
811 scoped_refptr<ProcessMemoryMetricsEmitter> emitter( 811 scoped_refptr<ProcessMemoryMetricsEmitter> emitter(
812 new ProcessMemoryMetricsEmitter); 812 new ProcessMemoryMetricsEmitter);
813 emitter->FetchAndEmitProcessMemoryMetrics(); 813 emitter->FetchAndEmitProcessMemoryMetrics();
814 } 814 }
815 815
816 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() { 816 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() {
817 DCHECK(thread_checker_.CalledOnValidThread()); 817 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
818 818
819 // This function should only be called as the callback from an ansynchronous 819 // This function should only be called as the callback from an ansynchronous
820 // step. 820 // step.
821 DCHECK(waiting_for_collect_final_metrics_step_); 821 DCHECK(waiting_for_collect_final_metrics_step_);
822 822
823 // Create a callback_task for OnHistogramSynchronizationDone. 823 // Create a callback_task for OnHistogramSynchronizationDone.
824 base::Closure callback = base::Bind( 824 base::Closure callback = base::Bind(
825 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone, 825 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone,
826 weak_ptr_factory_.GetWeakPtr()); 826 weak_ptr_factory_.GetWeakPtr());
827 827
(...skipping 24 matching lines...) Expand all
852 callback); 852 callback);
853 853
854 // Set up the callback task to call after we receive histograms from all 854 // Set up the callback task to call after we receive histograms from all
855 // child processes. |timeout| specifies how long to wait before absolutely 855 // child processes. |timeout| specifies how long to wait before absolutely
856 // calling us back on the task. 856 // calling us back on the task.
857 content::FetchHistogramsAsynchronously(base::ThreadTaskRunnerHandle::Get(), 857 content::FetchHistogramsAsynchronously(base::ThreadTaskRunnerHandle::Get(),
858 callback, timeout); 858 callback, timeout);
859 } 859 }
860 860
861 void ChromeMetricsServiceClient::OnHistogramSynchronizationDone() { 861 void ChromeMetricsServiceClient::OnHistogramSynchronizationDone() {
862 DCHECK(thread_checker_.CalledOnValidThread()); 862 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
863 863
864 // This function should only be called as the callback from an ansynchronous 864 // This function should only be called as the callback from an ansynchronous
865 // step. 865 // step.
866 DCHECK(waiting_for_collect_final_metrics_step_); 866 DCHECK(waiting_for_collect_final_metrics_step_);
867 DCHECK_GT(num_async_histogram_fetches_in_progress_, 0); 867 DCHECK_GT(num_async_histogram_fetches_in_progress_, 0);
868 868
869 // Check if all expected requests finished. 869 // Check if all expected requests finished.
870 if (--num_async_histogram_fetches_in_progress_ > 0) 870 if (--num_async_histogram_fetches_in_progress_ > 0)
871 return; 871 return;
872 872
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 browser_sync::ProfileSyncService* sync = 950 browser_sync::ProfileSyncService* sync =
951 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 951 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
952 if (sync) 952 if (sync)
953 ObserveServiceForSyncDisables(static_cast<syncer::SyncService*>(sync)); 953 ObserveServiceForSyncDisables(static_cast<syncer::SyncService*>(sync));
954 } 954 }
955 955
956 void ChromeMetricsServiceClient::Observe( 956 void ChromeMetricsServiceClient::Observe(
957 int type, 957 int type,
958 const content::NotificationSource& source, 958 const content::NotificationSource& source,
959 const content::NotificationDetails& details) { 959 const content::NotificationDetails& details) {
960 DCHECK(thread_checker_.CalledOnValidThread()); 960 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
961 961
962 switch (type) { 962 switch (type) {
963 case chrome::NOTIFICATION_BROWSER_OPENED: 963 case chrome::NOTIFICATION_BROWSER_OPENED:
964 // May have opened an incognito window. 964 // May have opened an incognito window.
965 UpdateRunningServices(); 965 UpdateRunningServices();
966 metrics_service_->OnApplicationNotIdle(); 966 metrics_service_->OnApplicationNotIdle();
967 break; 967 break;
968 case chrome::NOTIFICATION_BROWSER_CLOSED: 968 case chrome::NOTIFICATION_BROWSER_CLOSED:
969 case chrome::NOTIFICATION_TAB_PARENTED: 969 case chrome::NOTIFICATION_TAB_PARENTED:
970 case chrome::NOTIFICATION_TAB_CLOSING: 970 case chrome::NOTIFICATION_TAB_CLOSING:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 ukm_service_->Purge(); 1008 ukm_service_->Purge();
1009 ukm_service_->ResetClientId(); 1009 ukm_service_->ResetClientId();
1010 } 1010 }
1011 // Signal service manager to enable/disable UKM based on new state. 1011 // Signal service manager to enable/disable UKM based on new state.
1012 UpdateRunningServices(); 1012 UpdateRunningServices();
1013 } 1013 }
1014 1014
1015 bool ChromeMetricsServiceClient::IsHistorySyncEnabledOnAllProfiles() { 1015 bool ChromeMetricsServiceClient::IsHistorySyncEnabledOnAllProfiles() {
1016 return SyncDisableObserver::IsHistorySyncEnabledOnAllProfiles(); 1016 return SyncDisableObserver::IsHistorySyncEnabledOnAllProfiles();
1017 } 1017 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698