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

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

Issue 7980011: Convert the PluginService interface to be an async wrapper around PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 3 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 a64e993ec28ddedd60efd5d550a3f14feae8d114..4efdc8c3175bcdd69090e336b9b29f50da8ac8d1 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"
@@ -321,44 +322,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());
@@ -796,12 +759,38 @@ void MetricsService::InitializeMetricsState() {
ScheduleNextStateSave();
}
-void MetricsService::OnInitTaskComplete(
- const std::string& hardware_class,
- const std::vector<webkit::WebPluginInfo>& plugins) {
+void MetricsService::InitTaskGetHardwareClass(
+ base::MessageLoopProxy* target_loop) {
+ DCHECK(state_ == INIT_TASK_SCHEDULED);
+ 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) {
DCHECK(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,
+ base::Unretained(this)));
+}
+
+void MetricsService::OnInitTaskGotPluginInfo(
+ const std::vector<webkit::WebPluginInfo>& plugins) {
+ DCHECK(state_ == INIT_TASK_SCHEDULED);
plugins_ = plugins;
+
io_thread_ = g_browser_process->io_thread();
if (state_ == INIT_TASK_SCHEDULED)
state_ = INIT_TASK_DONE;
@@ -853,8 +842,10 @@ void MetricsService::StartRecording() {
// 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()),
+ BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&MetricsService::InitTaskGetHardwareClass,
+ base::Unretained(this),
+ MessageLoop::current()->message_loop_proxy()),
kInitializationDelaySeconds * 1000);
}
}

Powered by Google App Engine
This is Rietveld 408576698