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

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: rebase again Created 7 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 | 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 }; 373 };
374 374
375 // Handles asynchronous fetching of memory details. 375 // Handles asynchronous fetching of memory details.
376 // Will run the provided task after finished. 376 // Will run the provided task after finished.
377 class MetricsMemoryDetails : public MemoryDetails { 377 class MetricsMemoryDetails : public MemoryDetails {
378 public: 378 public:
379 explicit MetricsMemoryDetails(const base::Closure& callback) 379 explicit MetricsMemoryDetails(const base::Closure& callback)
380 : callback_(callback) {} 380 : callback_(callback) {}
381 381
382 virtual void OnDetailsAvailable() OVERRIDE { 382 virtual void OnDetailsAvailable() OVERRIDE {
383 MessageLoop::current()->PostTask(FROM_HERE, callback_); 383 base::MessageLoop::current()->PostTask(FROM_HERE, callback_);
384 } 384 }
385 385
386 private: 386 private:
387 virtual ~MetricsMemoryDetails() {} 387 virtual ~MetricsMemoryDetails() {}
388 388
389 base::Closure callback_; 389 base::Closure callback_;
390 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); 390 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
391 }; 391 };
392 392
393 // static 393 // static
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 const std::vector<webkit::WebPluginInfo>& plugins) { 953 const std::vector<webkit::WebPluginInfo>& plugins) {
954 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); 954 DCHECK_EQ(INIT_TASK_SCHEDULED, state_);
955 plugins_ = plugins; 955 plugins_ = plugins;
956 956
957 // Schedules a task on a blocking pool thread to gather Google Update 957 // Schedules a task on a blocking pool thread to gather Google Update
958 // statistics (requires Registry reads). 958 // statistics (requires Registry reads).
959 BrowserThread::PostBlockingPoolTask( 959 BrowserThread::PostBlockingPoolTask(
960 FROM_HERE, 960 FROM_HERE,
961 base::Bind(&MetricsService::InitTaskGetGoogleUpdateData, 961 base::Bind(&MetricsService::InitTaskGetGoogleUpdateData,
962 self_ptr_factory_.GetWeakPtr(), 962 self_ptr_factory_.GetWeakPtr(),
963 MessageLoop::current()->message_loop_proxy())); 963 base::MessageLoop::current()->message_loop_proxy()));
964 } 964 }
965 965
966 // static 966 // static
967 void MetricsService::InitTaskGetGoogleUpdateData( 967 void MetricsService::InitTaskGetGoogleUpdateData(
968 base::WeakPtr<MetricsService> self, 968 base::WeakPtr<MetricsService> self,
969 base::MessageLoopProxy* target_loop) { 969 base::MessageLoopProxy* target_loop) {
970 GoogleUpdateMetrics google_update_metrics; 970 GoogleUpdateMetrics google_update_metrics;
971 971
972 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) 972 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
973 const bool system_install = GoogleUpdateSettings::IsSystemInstall(); 973 const bool system_install = GoogleUpdateSettings::IsSystemInstall();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 std::string MetricsService::GenerateClientID() { 1064 std::string MetricsService::GenerateClientID() {
1065 return base::GenerateGUID(); 1065 return base::GenerateGUID();
1066 } 1066 }
1067 1067
1068 //------------------------------------------------------------------------------ 1068 //------------------------------------------------------------------------------
1069 // State save methods 1069 // State save methods
1070 1070
1071 void MetricsService::ScheduleNextStateSave() { 1071 void MetricsService::ScheduleNextStateSave() {
1072 state_saver_factory_.InvalidateWeakPtrs(); 1072 state_saver_factory_.InvalidateWeakPtrs();
1073 1073
1074 MessageLoop::current()->PostDelayedTask(FROM_HERE, 1074 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1075 base::Bind(&MetricsService::SaveLocalState, 1075 base::Bind(&MetricsService::SaveLocalState,
1076 state_saver_factory_.GetWeakPtr()), 1076 state_saver_factory_.GetWeakPtr()),
1077 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); 1077 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes));
1078 } 1078 }
1079 1079
1080 void MetricsService::SaveLocalState() { 1080 void MetricsService::SaveLocalState() {
1081 PrefService* pref = g_browser_process->local_state(); 1081 PrefService* pref = g_browser_process->local_state();
1082 if (!pref) { 1082 if (!pref) {
1083 NOTREACHED(); 1083 NOTREACHED();
1084 return; 1084 return;
(...skipping 20 matching lines...) Expand all
1105 1105
1106 // Schedules a task on the file thread for execution of slower 1106 // Schedules a task on the file thread for execution of slower
1107 // initialization steps (such as plugin list generation) necessary 1107 // initialization steps (such as plugin list generation) necessary
1108 // for sending the initial log. This avoids blocking the main UI 1108 // for sending the initial log. This avoids blocking the main UI
1109 // thread. 1109 // thread.
1110 BrowserThread::PostDelayedTask( 1110 BrowserThread::PostDelayedTask(
1111 BrowserThread::FILE, 1111 BrowserThread::FILE,
1112 FROM_HERE, 1112 FROM_HERE,
1113 base::Bind(&MetricsService::InitTaskGetHardwareClass, 1113 base::Bind(&MetricsService::InitTaskGetHardwareClass,
1114 self_ptr_factory_.GetWeakPtr(), 1114 self_ptr_factory_.GetWeakPtr(),
1115 MessageLoop::current()->message_loop_proxy()), 1115 base::MessageLoop::current()->message_loop_proxy()),
1116 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); 1116 base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
1117 } 1117 }
1118 } 1118 }
1119 1119
1120 void MetricsService::CloseCurrentLog() { 1120 void MetricsService::CloseCurrentLog() {
1121 if (!log_manager_.current_log()) 1121 if (!log_manager_.current_log())
1122 return; 1122 return;
1123 1123
1124 // TODO(jar): Integrate bounds on log recording more consistently, so that we 1124 // TODO(jar): Integrate bounds on log recording more consistently, so that we
1125 // can stop recording logs that are too big much sooner. 1125 // can stop recording logs that are too big much sooner.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 1256
1257 // Create a callback_task for OnHistogramSynchronizationDone. 1257 // Create a callback_task for OnHistogramSynchronizationDone.
1258 base::Closure callback = base::Bind( 1258 base::Closure callback = base::Bind(
1259 &MetricsService::OnHistogramSynchronizationDone, 1259 &MetricsService::OnHistogramSynchronizationDone,
1260 self_ptr_factory_.GetWeakPtr()); 1260 self_ptr_factory_.GetWeakPtr());
1261 1261
1262 // Set up the callback to task to call after we receive histograms from all 1262 // Set up the callback to task to call after we receive histograms from all
1263 // child processes. Wait time specifies how long to wait before absolutely 1263 // child processes. Wait time specifies how long to wait before absolutely
1264 // calling us back on the task. 1264 // calling us back on the task.
1265 content::FetchHistogramsAsynchronously( 1265 content::FetchHistogramsAsynchronously(
1266 MessageLoop::current(), callback, 1266 base::MessageLoop::current(), callback,
1267 base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration)); 1267 base::TimeDelta::FromMilliseconds(kMaxHistogramGatheringWaitDuration));
1268 } 1268 }
1269 1269
1270 void MetricsService::OnHistogramSynchronizationDone() { 1270 void MetricsService::OnHistogramSynchronizationDone() {
1271 DCHECK(IsSingleThreaded()); 1271 DCHECK(IsSingleThreaded());
1272 // This function should only be called as the callback from an ansynchronous 1272 // This function should only be called as the callback from an ansynchronous
1273 // step. 1273 // step.
1274 DCHECK(waiting_for_asynchronous_reporting_step_); 1274 DCHECK(waiting_for_asynchronous_reporting_step_);
1275 1275
1276 waiting_for_asynchronous_reporting_step_ = false; 1276 waiting_for_asynchronous_reporting_step_ = false;
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 if (local_state) { 1811 if (local_state) {
1812 const PrefService::Preference* uma_pref = 1812 const PrefService::Preference* uma_pref =
1813 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1813 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1814 if (uma_pref) { 1814 if (uma_pref) {
1815 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1815 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1816 DCHECK(success); 1816 DCHECK(success);
1817 } 1817 }
1818 } 1818 }
1819 return result; 1819 return result;
1820 } 1820 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log_unittest.cc ('k') | chrome/browser/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698