Chromium Code Reviews| 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..c299fa6be785311860163ba5a24f0e19015fca70 100644 |
| --- a/chrome/browser/metrics/metrics_service.cc |
| +++ b/chrome/browser/metrics/metrics_service.cc |
| @@ -89,11 +89,11 @@ |
| // 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 and waiting for hardware statistics on Chrome OS. |
| +// 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 |
| @@ -150,6 +150,7 @@ |
| #include "base/md5.h" |
| #include "base/metrics/histogram.h" |
| #include "base/string_number_conversions.h" |
| +#include "base/string_util.h" |
| #include "base/threading/platform_thread.h" |
| #include "base/threading/thread.h" |
| #include "base/utf_string_conversions.h" |
| @@ -756,23 +757,31 @@ void MetricsService::InitializeMetricsState() { |
| // static |
| void MetricsService::InitTaskGetHardwareClass( |
| - base::WeakPtr<MetricsService> self, |
| - base::MessageLoopProxy* target_loop) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + base::WeakPtr<MetricsService> self) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| +#if defined(OS_CHROMEOS) |
| + chromeos::system::StatisticsProvider::GetInstance()->WhenReady( |
| + base::Bind(&MetricsService::OnStatisticsProviderReady, |
| + self)); |
|
Ilya Sherman
2012/04/19 19:35:32
Does the WhenReady() call have any sort of timeout
Joao da Silva
2012/04/19 19:54:33
StatisticsProvider is a singleton whose ctor immed
Ilya Sherman
2012/04/19 20:16:54
What if the StatisticsProvider's task gets schedul
Joao da Silva
2012/04/20 11:53:35
There's another CL that moves its task to the Bloc
|
| +#else |
| + if (self) |
| + OnInitTaskGotHardwareClass(EmptyString()); |
| +#endif // OS_CHROMEOS |
| +} |
| - std::string hardware_class; |
| #if defined(OS_CHROMEOS) |
| +void MetricsService::OnStatisticsProviderReady() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + std::string hardware_class; |
| chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
| "hardware_class", &hardware_class); |
| -#endif // OS_CHROMEOS |
| - |
| - target_loop->PostTask(FROM_HERE, |
| - base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
| - self, hardware_class)); |
| + OnInitTaskGotHardwareClass(hardware_class); |
| } |
| +#endif |
| void MetricsService::OnInitTaskGotHardwareClass( |
| const std::string& hardware_class) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
| hardware_class_ = hardware_class; |
| @@ -839,11 +848,10 @@ void MetricsService::StartRecording() { |
| // for sending the initial log. This avoids blocking the main UI |
| // thread. |
| BrowserThread::PostDelayedTask( |
| - BrowserThread::FILE, |
| + BrowserThread::UI, |
| FROM_HERE, |
| base::Bind(&MetricsService::InitTaskGetHardwareClass, |
| - self_ptr_factory_.GetWeakPtr(), |
| - MessageLoop::current()->message_loop_proxy()), |
| + self_ptr_factory_.GetWeakPtr()), |
|
Ilya Sherman
2012/04/19 19:35:32
nit: No need to use a weak pointer if this is all
Joao da Silva
2012/04/19 19:54:33
The WeakPtr is bound to the callback task passed t
Ilya Sherman
2012/04/19 20:16:54
Fair enough.
|
| base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
| } |
| } |