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

Unified Diff: chrome/browser/metrics/metrics_service.cc

Issue 10078017: Added asynchronous notification of readiness to the StatisticsProvider, and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
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..2726d6c620f7a063af3e7f56ecb146e1d539911d 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,30 +757,38 @@ 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));
+#else
+ if (self)
+ 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;
// 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(
@@ -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()),
base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
}
}
« chrome/browser/metrics/metrics_service.h ('K') | « chrome/browser/metrics/metrics_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698