| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
| 6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
| 7 // | 7 // |
| 8 // OVERVIEW | 8 // OVERVIEW |
| 9 // | 9 // |
| 10 // A MetricsService instance is typically created at application startup. It | 10 // A MetricsService instance is typically created at application startup. It |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // load. | 257 // load. |
| 258 int instances; | 258 int instances; |
| 259 | 259 |
| 260 ChildProcessInfo::ProcessType process_type; | 260 ChildProcessInfo::ProcessType process_type; |
| 261 }; | 261 }; |
| 262 | 262 |
| 263 // Handles asynchronous fetching of memory details. | 263 // Handles asynchronous fetching of memory details. |
| 264 // Will run the provided task after finished. | 264 // Will run the provided task after finished. |
| 265 class MetricsMemoryDetails : public MemoryDetails { | 265 class MetricsMemoryDetails : public MemoryDetails { |
| 266 public: | 266 public: |
| 267 explicit MetricsMemoryDetails(Task* completion) : completion_(completion) {} | 267 explicit MetricsMemoryDetails(const base::Closure& callback) |
| 268 : callback_(callback) {} |
| 268 | 269 |
| 269 virtual void OnDetailsAvailable() { | 270 virtual void OnDetailsAvailable() { |
| 270 MessageLoop::current()->PostTask(FROM_HERE, completion_); | 271 MessageLoop::current()->PostTask(FROM_HERE, callback_); |
| 271 } | 272 } |
| 272 | 273 |
| 273 private: | 274 private: |
| 274 ~MetricsMemoryDetails() {} | 275 ~MetricsMemoryDetails() {} |
| 275 | 276 |
| 276 Task* completion_; | 277 base::Closure callback_; |
| 277 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 278 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
| 278 }; | 279 }; |
| 279 | 280 |
| 280 // static | 281 // static |
| 281 void MetricsService::RegisterPrefs(PrefService* local_state) { | 282 void MetricsService::RegisterPrefs(PrefService* local_state) { |
| 282 DCHECK(IsSingleThreaded()); | 283 DCHECK(IsSingleThreaded()); |
| 283 local_state->RegisterStringPref(prefs::kMetricsClientID, ""); | 284 local_state->RegisterStringPref(prefs::kMetricsClientID, ""); |
| 284 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); | 285 local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); |
| 285 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 286 local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
| 286 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 287 local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 // If reporting has been turned off, the scheduler doesn't need to run. | 869 // If reporting has been turned off, the scheduler doesn't need to run. |
| 869 if (!reporting_active() || !recording_active()) { | 870 if (!reporting_active() || !recording_active()) { |
| 870 scheduler_->Stop(); | 871 scheduler_->Stop(); |
| 871 scheduler_->UploadCancelled(); | 872 scheduler_->UploadCancelled(); |
| 872 return; | 873 return; |
| 873 } | 874 } |
| 874 | 875 |
| 875 DCHECK(!waiting_for_asynchronus_reporting_step_); | 876 DCHECK(!waiting_for_asynchronus_reporting_step_); |
| 876 waiting_for_asynchronus_reporting_step_ = true; | 877 waiting_for_asynchronus_reporting_step_ = true; |
| 877 | 878 |
| 878 Task* task = log_sender_factory_. | 879 base::Closure callback = |
| 879 NewRunnableMethod(&MetricsService::OnMemoryDetailCollectionDone); | 880 base::Bind(&MetricsService::OnMemoryDetailCollectionDone, |
| 881 log_sender_factory_.GetWeakPtr()); |
| 880 | 882 |
| 881 scoped_refptr<MetricsMemoryDetails> details(new MetricsMemoryDetails(task)); | 883 scoped_refptr<MetricsMemoryDetails> details( |
| 884 new MetricsMemoryDetails(callback)); |
| 882 details->StartFetch(); | 885 details->StartFetch(); |
| 883 | 886 |
| 884 // Collect WebCore cache information to put into a histogram. | 887 // Collect WebCore cache information to put into a histogram. |
| 885 for (content::RenderProcessHost::iterator i( | 888 for (content::RenderProcessHost::iterator i( |
| 886 content::RenderProcessHost::AllHostsIterator()); | 889 content::RenderProcessHost::AllHostsIterator()); |
| 887 !i.IsAtEnd(); i.Advance()) | 890 !i.IsAtEnd(); i.Advance()) |
| 888 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats()); | 891 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats()); |
| 889 } | 892 } |
| 890 | 893 |
| 891 void MetricsService::OnMemoryDetailCollectionDone() { | 894 void MetricsService::OnMemoryDetailCollectionDone() { |
| 892 DCHECK(IsSingleThreaded()); | 895 DCHECK(IsSingleThreaded()); |
| 893 // This function should only be called as the callback from an ansynchronous | 896 // This function should only be called as the callback from an ansynchronous |
| 894 // step. | 897 // step. |
| 895 DCHECK(waiting_for_asynchronus_reporting_step_); | 898 DCHECK(waiting_for_asynchronus_reporting_step_); |
| 896 | 899 |
| 897 // Right before the UMA transmission gets started, there's one more thing we'd | 900 // Right before the UMA transmission gets started, there's one more thing we'd |
| 898 // like to record: the histogram of memory usage, so we spawn a task to | 901 // like to record: the histogram of memory usage, so we spawn a task to |
| 899 // collect the memory details and when that task is finished, it will call | 902 // collect the memory details and when that task is finished, it will call |
| 900 // OnMemoryDetailCollectionDone, which will call HistogramSynchronization to | 903 // OnMemoryDetailCollectionDone, which will call HistogramSynchronization to |
| 901 // collect histograms from all renderers and then we will call | 904 // collect histograms from all renderers and then we will call |
| 902 // OnHistogramSynchronizationDone to continue processing. | 905 // OnHistogramSynchronizationDone to continue processing. |
| 903 | 906 |
| 904 // Create a callback_task for OnHistogramSynchronizationDone. | 907 // Create a callback_task for OnHistogramSynchronizationDone. |
| 905 Task* callback_task = log_sender_factory_.NewRunnableMethod( | 908 base::Closure callback = base::Bind( |
| 906 &MetricsService::OnHistogramSynchronizationDone); | 909 &MetricsService::OnHistogramSynchronizationDone, |
| 910 log_sender_factory_.GetWeakPtr()); |
| 907 | 911 |
| 908 base::StatisticsRecorder::CollectHistogramStats("Browser"); | 912 base::StatisticsRecorder::CollectHistogramStats("Browser"); |
| 909 | 913 |
| 910 // Set up the callback to task to call after we receive histograms from all | 914 // Set up the callback to task to call after we receive histograms from all |
| 911 // renderer processes. Wait time specifies how long to wait before absolutely | 915 // renderer processes. Wait time specifies how long to wait before absolutely |
| 912 // calling us back on the task. | 916 // calling us back on the task. |
| 913 HistogramSynchronizer::FetchRendererHistogramsAsynchronously( | 917 HistogramSynchronizer::FetchRendererHistogramsAsynchronously( |
| 914 MessageLoop::current(), callback_task, | 918 MessageLoop::current(), callback, |
| 915 kMaxHistogramGatheringWaitDuration); | 919 kMaxHistogramGatheringWaitDuration); |
| 916 } | 920 } |
| 917 | 921 |
| 918 void MetricsService::OnHistogramSynchronizationDone() { | 922 void MetricsService::OnHistogramSynchronizationDone() { |
| 919 DCHECK(IsSingleThreaded()); | 923 DCHECK(IsSingleThreaded()); |
| 920 | 924 |
| 921 // If somehow there is a fetch in progress, we return and hope things work | 925 // If somehow there is a fetch in progress, we return and hope things work |
| 922 // out. The scheduler isn't informed since if this happens, the scheduler | 926 // out. The scheduler isn't informed since if this happens, the scheduler |
| 923 // will get a response from the upload. | 927 // will get a response from the upload. |
| 924 DCHECK(!current_fetch_.get()); | 928 DCHECK(!current_fetch_.get()); |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 if (local_state) { | 1552 if (local_state) { |
| 1549 const PrefService::Preference* uma_pref = | 1553 const PrefService::Preference* uma_pref = |
| 1550 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1554 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1551 if (uma_pref) { | 1555 if (uma_pref) { |
| 1552 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1556 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1553 DCHECK(success); | 1557 DCHECK(success); |
| 1554 } | 1558 } |
| 1555 } | 1559 } |
| 1556 return result; | 1560 return result; |
| 1557 } | 1561 } |
| OLD | NEW |