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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 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 | « components/metrics/metrics_service.h ('k') | components/nacl/broker/nacl_broker_listener.cc » ('j') | 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 //------------------------------------------------------------------------------ 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 is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // 121 //
122 // 122 //
123 //------------------------------------------------------------------------------ 123 //------------------------------------------------------------------------------
124 124
125 #include "components/metrics/metrics_service.h" 125 #include "components/metrics/metrics_service.h"
126 126
127 #include <algorithm> 127 #include <algorithm>
128 128
129 #include "base/bind.h" 129 #include "base/bind.h"
130 #include "base/callback.h" 130 #include "base/callback.h"
131 #include "base/location.h"
131 #include "base/metrics/histogram.h" 132 #include "base/metrics/histogram.h"
132 #include "base/metrics/histogram_base.h" 133 #include "base/metrics/histogram_base.h"
133 #include "base/metrics/histogram_samples.h" 134 #include "base/metrics/histogram_samples.h"
134 #include "base/metrics/sparse_histogram.h" 135 #include "base/metrics/sparse_histogram.h"
135 #include "base/metrics/statistics_recorder.h" 136 #include "base/metrics/statistics_recorder.h"
136 #include "base/prefs/pref_registry_simple.h" 137 #include "base/prefs/pref_registry_simple.h"
137 #include "base/prefs/pref_service.h" 138 #include "base/prefs/pref_service.h"
139 #include "base/single_thread_task_runner.h"
138 #include "base/strings/string_number_conversions.h" 140 #include "base/strings/string_number_conversions.h"
139 #include "base/strings/utf_string_conversions.h" 141 #include "base/strings/utf_string_conversions.h"
142 #include "base/thread_task_runner_handle.h"
140 #include "base/threading/platform_thread.h" 143 #include "base/threading/platform_thread.h"
141 #include "base/threading/thread.h" 144 #include "base/threading/thread.h"
142 #include "base/threading/thread_restrictions.h" 145 #include "base/threading/thread_restrictions.h"
143 #include "base/time/time.h" 146 #include "base/time/time.h"
144 #include "base/tracked_objects.h" 147 #include "base/tracked_objects.h"
145 #include "base/values.h" 148 #include "base/values.h"
146 #include "components/metrics/metrics_log.h" 149 #include "components/metrics/metrics_log.h"
147 #include "components/metrics/metrics_log_manager.h" 150 #include "components/metrics/metrics_log_manager.h"
148 #include "components/metrics/metrics_log_uploader.h" 151 #include "components/metrics/metrics_log_uploader.h"
149 #include "components/metrics/metrics_pref_names.h" 152 #include "components/metrics/metrics_pref_names.h"
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 for (size_t i = 0; i < metrics_providers_.size(); ++i) 673 for (size_t i = 0; i < metrics_providers_.size(); ++i)
671 metrics_providers_[i]->OnDidCreateMetricsLog(); 674 metrics_providers_[i]->OnDidCreateMetricsLog();
672 } 675 }
673 676
674 //------------------------------------------------------------------------------ 677 //------------------------------------------------------------------------------
675 // State save methods 678 // State save methods
676 679
677 void MetricsService::ScheduleNextStateSave() { 680 void MetricsService::ScheduleNextStateSave() {
678 state_saver_factory_.InvalidateWeakPtrs(); 681 state_saver_factory_.InvalidateWeakPtrs();
679 682
680 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 683 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
681 base::Bind(&MetricsService::SaveLocalState, 684 FROM_HERE, base::Bind(&MetricsService::SaveLocalState,
682 state_saver_factory_.GetWeakPtr()), 685 state_saver_factory_.GetWeakPtr()),
683 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); 686 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
684 } 687 }
685 688
686 void MetricsService::SaveLocalState() { 689 void MetricsService::SaveLocalState() {
687 RecordCurrentState(local_state_); 690 RecordCurrentState(local_state_);
688 691
689 // TODO(jar):110021 Does this run down the batteries???? 692 // TODO(jar):110021 Does this run down the batteries????
690 ScheduleNextStateSave(); 693 ScheduleNextStateSave();
691 } 694 }
692 695
693 696
694 //------------------------------------------------------------------------------ 697 //------------------------------------------------------------------------------
695 // Recording control methods 698 // Recording control methods
696 699
697 void MetricsService::OpenNewLog() { 700 void MetricsService::OpenNewLog() {
698 DCHECK(!log_manager_.current_log()); 701 DCHECK(!log_manager_.current_log());
699 702
700 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); 703 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG));
701 NotifyOnDidCreateMetricsLog(); 704 NotifyOnDidCreateMetricsLog();
702 if (state_ == INITIALIZED) { 705 if (state_ == INITIALIZED) {
703 // We only need to schedule that run once. 706 // We only need to schedule that run once.
704 state_ = INIT_TASK_SCHEDULED; 707 state_ = INIT_TASK_SCHEDULED;
705 708
706 base::MessageLoop::current()->PostDelayedTask( 709 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
707 FROM_HERE, 710 FROM_HERE, base::Bind(&MetricsService::StartGatheringMetrics,
708 base::Bind(&MetricsService::StartGatheringMetrics, 711 self_ptr_factory_.GetWeakPtr()),
709 self_ptr_factory_.GetWeakPtr()),
710 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 712 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
711 } 713 }
712 } 714 }
713 715
714 void MetricsService::StartGatheringMetrics() { 716 void MetricsService::StartGatheringMetrics() {
715 client_->StartGatheringMetrics( 717 client_->StartGatheringMetrics(
716 base::Bind(&MetricsService::FinishedGatheringInitialMetrics, 718 base::Bind(&MetricsService::FinishedGatheringInitialMetrics,
717 self_ptr_factory_.GetWeakPtr())); 719 self_ptr_factory_.GetWeakPtr()));
718 } 720 }
719 721
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 local_state_->SetBoolean(path, value); 1123 local_state_->SetBoolean(path, value);
1122 RecordCurrentState(local_state_); 1124 RecordCurrentState(local_state_);
1123 } 1125 }
1124 1126
1125 void MetricsService::RecordCurrentState(PrefService* pref) { 1127 void MetricsService::RecordCurrentState(PrefService* pref) {
1126 pref->SetInt64(prefs::kStabilityLastTimestampSec, 1128 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1127 base::Time::Now().ToTimeT()); 1129 base::Time::Now().ToTimeT());
1128 } 1130 }
1129 1131
1130 } // namespace metrics 1132 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/nacl/broker/nacl_broker_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698