summaryrefslogtreecommitdiffstats
path: root/chrome/browser/metrics/metrics_service.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:52:32 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:52:32 +0000
commit90d4137638f7f8e0abd591d796ff0bd396ae6826 (patch)
treec26377fb9157fa2cd08e61fcd0cdbe2bc46986e3 /chrome/browser/metrics/metrics_service.cc
parentac52245b577be6105226d4a4befb9b55fe45ef19 (diff)
downloadchromium_src-90d4137638f7f8e0abd591d796ff0bd396ae6826.zip
chromium_src-90d4137638f7f8e0abd591d796ff0bd396ae6826.tar.gz
chromium_src-90d4137638f7f8e0abd591d796ff0bd396ae6826.tar.bz2
Relocate plugin list fetching to PluginService
We fetch the plugin list from three places. Previously, each location had custom code to proxy the query to the file thread. This change moves the query to the PluginService, which then internally manages posting to the file thread and calling back. I experimented with some different approaches to handling the lifetimes of the requests and responses. The approach now is simple: - The PluginService plugin methods are called and respond on the IO thread. Two of the three consumers of the plugin lists are already on the IO thread, so they don't need any complicated thread handling. - None of the callers ever need to cancel their requests: one is a singleton, and the other two always wait (in terms of holding a ref on the object) for the requests to complete. This makes lifetime management a lot simpler than it would otherwise be. With this change in place, I can then look at refactoring the PluginService implementation on Linux to do more complicated plugin loading as needed in bug 17863. BUG=17863 Review URL: http://codereview.chromium.org/437069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/metrics/metrics_service.cc')
-rw-r--r--chrome/browser/metrics/metrics_service.cc57
1 files changed, 32 insertions, 25 deletions
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 5839171..82cdeac 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -174,6 +174,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/load_notification_details.h"
#include "chrome/browser/memory_details.h"
+#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -284,35 +285,39 @@ class MetricsMemoryDetails : public MemoryDetails {
DISALLOW_EVIL_CONSTRUCTORS(MetricsMemoryDetails);
};
-class MetricsService::GetPluginListTaskComplete : public Task {
+// This object and its static functions manage the calls to and from
+// the plugin service. It lives on the IO thread. It only lives long
+// enough to handle the callback, then it deletes itself.
+class GetPluginListClient : public PluginService::GetPluginListClient {
public:
- explicit GetPluginListTaskComplete(
- const std::vector<WebPluginInfo>& plugins) : plugins_(plugins) { }
- virtual void Run() {
- g_browser_process->metrics_service()->OnGetPluginListTaskComplete(plugins_);
+ // Call GetPluginList on a GetPluginListClient. Used to proxy this call
+ // from the UI thread to the IO thread.
+ static void CallGetPluginList(GetPluginListClient* client) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ PluginService::GetInstance()->GetPluginList(false, client);
}
- private:
- std::vector<WebPluginInfo> plugins_;
-};
-
-class MetricsService::GetPluginListTask : public Task {
- public:
- explicit GetPluginListTask(MessageLoop* callback_loop)
- : callback_loop_(callback_loop) {}
-
- virtual void Run() {
- std::vector<WebPluginInfo> plugins;
- NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
-
- callback_loop_->PostTask(
- FROM_HERE, new GetPluginListTaskComplete(plugins));
+ // Callback from the PluginService when the plugin list has been retrieved.
+ virtual void OnGetPluginList(const std::vector<WebPluginInfo>& plugins) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ // Forward back to the UI thread.
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableFunction(&GetPluginListClient::GetPluginListComplete,
+ plugins));
+ delete this;
}
- private:
- MessageLoop* callback_loop_;
+ // A function to proxy the plugin list back from the IO thread to the UI
+ // thread to call the metrics service.
+ // |plugins| is intentionally pass by value.
+ static void GetPluginListComplete(const std::vector<WebPluginInfo> plugins) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ g_browser_process->metrics_service()->OnGetPluginListComplete(plugins);
+ }
};
+
// static
void MetricsService::RegisterPrefs(PrefService* local_state) {
DCHECK(IsSingleThreaded());
@@ -745,7 +750,7 @@ void MetricsService::InitializeMetricsState() {
ScheduleNextStateSave();
}
-void MetricsService::OnGetPluginListTaskComplete(
+void MetricsService::OnGetPluginListComplete(
const std::vector<WebPluginInfo>& plugins) {
DCHECK(state_ == PLUGIN_LIST_REQUESTED);
plugins_ = plugins;
@@ -826,8 +831,10 @@ void MetricsService::StartRecording() {
// Make sure the plugin list is loaded before the inital log is sent, so
// that the main thread isn't blocked generating the list.
- g_browser_process->file_thread()->message_loop()->PostDelayedTask(FROM_HERE,
- new GetPluginListTask(MessageLoop::current()),
+ ChromeThread::PostDelayedTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(&GetPluginListClient::CallGetPluginList,
+ new GetPluginListClient),
kInitialInterlogDuration * 1000 / 2);
}
}