Index: chrome/browser/metrics/metrics_service.cc |
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc |
index 92ee6021a7e0fea7efb9b6b165200fb54f814285..fa181c316d630462acb5bf3cadbd1fea3f2b1051 100644 |
--- a/chrome/browser/metrics/metrics_service.cc |
+++ b/chrome/browser/metrics/metrics_service.cc |
@@ -89,11 +89,10 @@ |
// initial log. |
// |
// INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to complete. |
-// Typically about 30 seconds after startup, a task is sent to a second thread |
-// (the file thread) to perform deferred (lower priority and slower) |
-// initialization steps such as getting the list of plugins. That task will |
-// (when complete) make an async callback (via a Task) to indicate the |
-// completion. |
+// Typically about 30 seconds after startup, a task is posted to perform |
+// deferred (lower priority and slower) initialization steps such as getting the |
+// list of plugins. That task will (when complete) make an async callback (via |
+// a Task) to indicate the completion. |
// |
// INIT_TASK_DONE, // Waiting for timer to send initial log. |
// The callback has arrived, and it is now possible for an initial log to be |
@@ -247,6 +246,11 @@ const int kSaveStateIntervalMinutes = 5; |
// e.g., the server is down. |
const int kNoResponseCode = content::URLFetcher::RESPONSE_CODE_INVALID - 1; |
+// Used to indicate that a report was generated before the hardware_class |
+// property was available from the StatisticsProvider. This is used to identify |
+// faulty reports from Chrome OS clients. |
+const char kHardwareClassNotReady[] = "(not ready)"; |
+ |
} |
// static |
@@ -754,32 +758,22 @@ void MetricsService::InitializeMetricsState() { |
ScheduleNextStateSave(); |
} |
-// static |
-void MetricsService::InitTaskGetHardwareClass( |
- base::WeakPtr<MetricsService> self, |
- base::MessageLoopProxy* target_loop) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- |
- std::string hardware_class; |
+void MetricsService::OnStatisticsProviderReady() { |
#if defined(OS_CHROMEOS) |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
- "hardware_class", &hardware_class); |
-#endif // OS_CHROMEOS |
- |
- target_loop->PostTask(FROM_HERE, |
- base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
- self, hardware_class)); |
+ "hardware_class", &hardware_class_); |
+#endif |
} |
-void MetricsService::OnInitTaskGotHardwareClass( |
- const std::string& hardware_class) { |
+void MetricsService::InitTaskGetPluginInfo() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
- hardware_class_ = hardware_class; |
// Start the next part of the init task: loading plugin information. |
PluginService::GetInstance()->GetPlugins( |
base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
- self_ptr_factory_.GetWeakPtr())); |
+ self_ptr_factory_.GetWeakPtr())); |
} |
void MetricsService::OnInitTaskGotPluginInfo( |
@@ -834,16 +828,22 @@ void MetricsService::StartRecording() { |
// We only need to schedule that run once. |
state_ = INIT_TASK_SCHEDULED; |
- // Schedules a task on the file thread for execution of slower |
- // initialization steps (such as plugin list generation) necessary |
- // for sending the initial log. This avoids blocking the main UI |
- // thread. |
- BrowserThread::PostDelayedTask( |
- BrowserThread::FILE, |
+#if defined(OS_CHROMEOS) |
+ // The hardware class can only be retrieved once the StatisticsProvider is |
+ // ready. This usually happens early enough, but can take longer on some |
+ // faulty hardware. Use a temporary special marker to identify those cases. |
+ hardware_class_ = kHardwareClassNotReady; |
Ilya Sherman
2012/04/20 21:18:37
nit: Any reason not to initialize this in the cons
Joao da Silva
2012/04/23 09:36:50
Done.
|
+ chromeos::system::StatisticsProvider::GetInstance()->WhenReady( |
+ base::Bind(&MetricsService::OnStatisticsProviderReady, |
+ self_ptr_factory_.GetWeakPtr())); |
+#endif |
+ |
+ // Schedules a delayed task for execution of slower initialization steps |
+ // (such as plugin list generation) necessary for sending the initial log. |
+ MessageLoop::current()->PostDelayedTask( |
FROM_HERE, |
- base::Bind(&MetricsService::InitTaskGetHardwareClass, |
- self_ptr_factory_.GetWeakPtr(), |
- MessageLoop::current()->message_loop_proxy()), |
+ base::Bind(&MetricsService::InitTaskGetPluginInfo, |
+ self_ptr_factory_.GetWeakPtr()), |
base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
} |
} |