Index: chrome/browser/metrics/metrics_service.cc |
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc |
index 60944871c2ddc1a79116ccd3782cdf9134a23f4c..9102c783bb67a2db65321c064e7d559f49a07681 100644 |
--- a/chrome/browser/metrics/metrics_service.cc |
+++ b/chrome/browser/metrics/metrics_service.cc |
@@ -187,6 +187,7 @@ |
#include "chrome/common/pref_names.h" |
#include "chrome/common/render_messages.h" |
#include "content/browser/load_notification_details.h" |
+#include "content/browser/plugin_service.h" |
#include "content/browser/renderer_host/render_process_host.h" |
#include "content/common/child_process_info.h" |
#include "content/common/notification_service.h" |
@@ -323,44 +324,6 @@ class MetricsMemoryDetails : public MemoryDetails { |
DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
}; |
-class MetricsService::InitTaskComplete : public Task { |
- public: |
- explicit InitTaskComplete( |
- const std::string& hardware_class, |
- const std::vector<webkit::WebPluginInfo>& plugins) |
- : hardware_class_(hardware_class), plugins_(plugins) {} |
- |
- virtual void Run() { |
- g_browser_process->metrics_service()->OnInitTaskComplete( |
- hardware_class_, plugins_); |
- } |
- |
- private: |
- std::string hardware_class_; |
- std::vector<webkit::WebPluginInfo> plugins_; |
-}; |
- |
-class MetricsService::InitTask : public Task { |
- public: |
- explicit InitTask(MessageLoop* callback_loop) |
- : callback_loop_(callback_loop) {} |
- |
- virtual void Run() { |
- std::vector<webkit::WebPluginInfo> plugins; |
- webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
- std::string hardware_class; // Empty string by default. |
-#if defined(OS_CHROMEOS) |
- chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
- "hardware_class", &hardware_class); |
-#endif // OS_CHROMEOS |
- callback_loop_->PostTask(FROM_HERE, new InitTaskComplete( |
- hardware_class, plugins)); |
- } |
- |
- private: |
- MessageLoop* callback_loop_; |
-}; |
- |
// static |
void MetricsService::RegisterPrefs(PrefService* local_state) { |
DCHECK(IsSingleThreaded()); |
@@ -445,6 +408,7 @@ MetricsService::MetricsService() |
: recording_active_(false), |
reporting_active_(false), |
state_(INITIALIZED), |
+ init_state_(INIT_SUBTASK_UNSTARTED), |
current_fetch_(NULL), |
io_thread_(NULL), |
idle_since_last_transmission_(false), |
@@ -798,15 +762,59 @@ void MetricsService::InitializeMetricsState() { |
ScheduleNextStateSave(); |
} |
-void MetricsService::OnInitTaskComplete( |
- const std::string& hardware_class, |
- const std::vector<webkit::WebPluginInfo>& plugins) { |
- DCHECK(state_ == INIT_TASK_SCHEDULED); |
+void MetricsService::RunInitTasks() { |
+ // 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::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&MetricsService::InitTaskGetHardwareClass, |
+ base::Unretained(this), |
+ MessageLoop::current()->message_loop_proxy())); |
+ |
+ PluginService::GetInstance()->GetPlugins( |
+ base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
+ base::Unretained(this))); |
+} |
+ |
+void MetricsService::InitTaskGetHardwareClass( |
+ base::MessageLoopProxy* target_loop) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ |
+ std::string hardware_class; |
+#if defined(OS_CHROMEOS) |
+ chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( |
+ "hardware_class", &hardware_class); |
+#endif // OS_CHROMEOS |
+ |
+ target_loop->PostTask(FROM_HERE, |
+ base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
+ base::Unretained(this), hardware_class)); |
+} |
+ |
+void MetricsService::OnInitTaskGotHardwareClass( |
+ const std::string& hardware_class) { |
hardware_class_ = hardware_class; |
+ init_state_ |= INIT_SUBTASK_HWCLASS; |
+ OnInitTaskMaybeDone(); |
+} |
+ |
+void MetricsService::OnInitTaskGotPluginInfo( |
+ std::vector<webkit::WebPluginInfo> plugins) { |
plugins_ = plugins; |
+ init_state_ |= INIT_SUBTASK_PLUGINS; |
+ OnInitTaskMaybeDone(); |
+} |
+ |
+void MetricsService::OnInitTaskMaybeDone() { |
+ DCHECK(state_ == INIT_TASK_SCHEDULED); |
+ if (state_ != INIT_TASK_SCHEDULED || |
+ (init_state_ & INIT_SUBTASK_ALL) != INIT_SUBTASK_ALL) { |
+ return; |
+ } |
+ |
io_thread_ = g_browser_process->io_thread(); |
- if (state_ == INIT_TASK_SCHEDULED) |
- state_ = INIT_TASK_DONE; |
+ state_ = INIT_TASK_DONE; |
} |
std::string MetricsService::GenerateClientID() { |
@@ -851,12 +859,8 @@ 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. |
- g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE, |
- new InitTask(MessageLoop::current()), |
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, |
+ base::Bind(&MetricsService::RunInitTasks, base::Unretained(this)), |
kInitializationDelaySeconds * 1000); |
} |
} |