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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 }; 372 };
373 373
374 // Handles asynchronous fetching of memory details. 374 // Handles asynchronous fetching of memory details.
375 // Will run the provided task after finished. 375 // Will run the provided task after finished.
376 class MetricsMemoryDetails : public MemoryDetails { 376 class MetricsMemoryDetails : public MemoryDetails {
377 public: 377 public:
378 explicit MetricsMemoryDetails(const base::Closure& callback) 378 explicit MetricsMemoryDetails(const base::Closure& callback)
379 : callback_(callback) {} 379 : callback_(callback) {}
380 380
381 virtual void OnDetailsAvailable() OVERRIDE { 381 virtual void OnDetailsAvailable() OVERRIDE {
382 MessageLoop::current()->PostTask(FROM_HERE, callback_); 382 base::MessageLoop::current()->PostTask(FROM_HERE, callback_);
383 } 383 }
384 384
385 private: 385 private:
386 virtual ~MetricsMemoryDetails() {} 386 virtual ~MetricsMemoryDetails() {}
387 387
388 base::Closure callback_; 388 base::Closure callback_;
389 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); 389 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
390 }; 390 };
391 391
392 // static 392 // static
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 const std::vector<webkit::WebPluginInfo>& plugins) { 947 const std::vector<webkit::WebPluginInfo>& plugins) {
948 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 948 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
949 plugins_ = plugins; 949 plugins_ = plugins;
950 950
951 // Schedules a task on a blocking pool thread to gather Google Update 951 // Schedules a task on a blocking pool thread to gather Google Update
952 // statistics (requires Registry reads). 952 // statistics (requires Registry reads).
953 BrowserThread::PostBlockingPoolTask( 953 BrowserThread::PostBlockingPoolTask(
954 FROM_HERE, 954 FROM_HERE,
955 base::Bind(&MetricsService::InitTaskGetGoogleUpdateData, 955 base::Bind(&MetricsService::InitTaskGetGoogleUpdateData,
956 self_ptr_factory_.GetWeakPtr(), 956 self_ptr_factory_.GetWeakPtr(),
957 MessageLoop::current()->message_loop_proxy())); 957 base::MessageLoop::current()->message_loop_proxy()));
958 } 958 }
959 959
960 // static 960 // static
961 void MetricsService::InitTaskGetGoogleUpdateData( 961 void MetricsService::InitTaskGetGoogleUpdateData(
962 base::WeakPtr<MetricsService> self, 962 base::WeakPtr<MetricsService> self,
963 base::MessageLoopProxy* target_loop) { 963 base::MessageLoopProxy* target_loop) {
964 GoogleUpdateMetrics google_update_metrics; 964 GoogleUpdateMetrics google_update_metrics;
965 965
966 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) 966 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
967 const bool system_install = GoogleUpdateSettings::IsSystemInstall(); 967 const bool system_install = GoogleUpdateSettings::IsSystemInstall();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 std::string MetricsService::GenerateClientID() { 1057 std::string MetricsService::GenerateClientID() {
1058 return base::GenerateGUID(); 1058 return base::GenerateGUID();
1059 } 1059 }
1060 1060
1061 //------------------------------------------------------------------------------ 1061 //------------------------------------------------------------------------------
1062 // State save methods 1062 // State save methods
1063 1063
1064 void MetricsService::ScheduleNextStateSave() { 1064 void MetricsService::ScheduleNextStateSave() {
1065 state_saver_factory_.InvalidateWeakPtrs(); 1065 state_saver_factory_.InvalidateWeakPtrs();
1066 1066
1067 MessageLoop::current()->PostDelayedTask(FROM_HERE, 1067 base::MessageLoop::current()->PostDelayedTask(
1068 FROM_HERE,
1068 base::Bind(&MetricsService::SaveLocalState, 1069 base::Bind(&MetricsService::SaveLocalState,
1069 state_saver_factory_.GetWeakPtr()), 1070 state_saver_factory_.GetWeakPtr()),
1070 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); 1071 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
1071 } 1072 }
1072 1073
1073 void MetricsService::SaveLocalState() { 1074 void MetricsService::SaveLocalState() {
1074 PrefService* pref = g_browser_process->local_state(); 1075 PrefService* pref = g_browser_process->local_state();
1075 if (!pref) { 1076 if (!pref) {
1076 NOTREACHED(); 1077 NOTREACHED();
1077 return; 1078 return;
(...skipping 19 matching lines...) Expand all
1097 state_ = INIT_TASK_SCHEDULED; 1098 state_ = INIT_TASK_SCHEDULED;
1098 1099
1099 // Schedules a task on the file thread for execution of slower 1100 // Schedules a task on the file thread for execution of slower
1100 // initialization steps (such as plugin list generation) necessary 1101 // initialization steps (such as plugin list generation) necessary
1101 // for sending the initial log. This avoids blocking the main UI 1102 // for sending the initial log. This avoids blocking the main UI
1102 // thread. 1103 // thread.
1103 BrowserThread::PostDelayedTask( 1104 BrowserThread::PostDelayedTask(
1104 BrowserThread::FILE, 1105 BrowserThread::FILE,
1105 FROM_HERE, 1106 FROM_HERE,
1106 base::Bind(&MetricsService::InitTaskGetHardwareClass, 1107 base::Bind(&MetricsService::InitTaskGetHardwareClass,
1107 self_ptr_factory_.GetWeakPtr(), 1108 self_ptr_factory_.GetWeakPtr(),
1108 MessageLoop::current()->message_loop_proxy()), 1109 base::MessageLoop::current()->message_loop_proxy()),
1109 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 1110 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
1110 } 1111 }
1111 } 1112 }
1112 1113
1113 void MetricsService::CloseCurrentLog() { 1114 void MetricsService::CloseCurrentLog() {
1114 if (!log_manager_.current_log()) 1115 if (!log_manager_.current_log())
1115 return; 1116 return;
1116 1117
1117 // TODO(jar): Integrate bounds on log recording more consistently, so that we 1118 // TODO(jar): Integrate bounds on log recording more consistently, so that we
1118 // can stop recording logs that are too big much sooner. 1119 // can stop recording logs that are too big much sooner.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 base::Closure callback = base::Bind( 1252 base::Closure callback = base::Bind(
1252 &MetricsService::OnHistogramSynchronizationDone, 1253 &MetricsService::OnHistogramSynchronizationDone,
1253 self_ptr_factory_.GetWeakPtr()); 1254 self_ptr_factory_.GetWeakPtr());
1254 1255
1255 base::StatisticsRecorder::CollectHistogramStats("Browser"); 1256 base::StatisticsRecorder::CollectHistogramStats("Browser");
1256 1257
1257 // Set up the callback to task to call after we receive histograms from all 1258 // Set up the callback to task to call after we receive histograms from all
1258 // child processes. Wait time specifies how long to wait before absolutely 1259 // child processes. Wait time specifies how long to wait before absolutely
1259 // calling us back on the task. 1260 // calling us back on the task.
1260 content::FetchHistogramsAsynchronously( 1261 content::FetchHistogramsAsynchronously(
1261 MessageLoop::current(), callback, 1262 base::MessageLoop::current(),
1263 callback,
1262 base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration)); 1264 base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration));
1263 } 1265 }
1264 1266
1265 void MetricsService::OnHistogramSynchronizationDone() { 1267 void MetricsService::OnHistogramSynchronizationDone() {
1266 DCHECK(IsSingleThreaded()); 1268 DCHECK(IsSingleThreaded());
1267 // This function should only be called as the callback from an ansynchronous 1269 // This function should only be called as the callback from an ansynchronous
1268 // step. 1270 // step.
1269 DCHECK(waiting_for_asynchronous_reporting_step_); 1271 DCHECK(waiting_for_asynchronous_reporting_step_);
1270 1272
1271 waiting_for_asynchronous_reporting_step_ = false; 1273 waiting_for_asynchronous_reporting_step_ = false;
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 if (local_state) { 1806 if (local_state) {
1805 const PrefService::Preference* uma_pref = 1807 const PrefService::Preference* uma_pref =
1806 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1808 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1807 if (uma_pref) { 1809 if (uma_pref) {
1808 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1810 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1809 DCHECK(success); 1811 DCHECK(success);
1810 } 1812 }
1811 } 1813 }
1812 return result; 1814 return result;
1813 } 1815 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698