Create an API around PluginService and use it from Chrome.

BUG=98716
Review URL: http://codereview.chromium.org/9006036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115259 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/plugin_service.cc b/content/browser/plugin_service.cc
index 7e875138..c3ad8ce 100644
--- a/content/browser/plugin_service.cc
+++ b/content/browser/plugin_service.cc
@@ -97,7 +97,7 @@
     webkit::npapi::PluginList::Singleton()->RefreshPlugins();
     BrowserThread::PostTask(
         BrowserThread::UI, FROM_HERE,
-        base::Bind(&PluginService::PurgePluginListCache,
+        base::Bind(&content::PluginService::PurgePluginListCache,
                    static_cast<content::BrowserContext*>(NULL), false));
   }
 
@@ -109,6 +109,24 @@
 };
 #endif
 
+namespace content {
+// static
+PluginService* PluginService::GetInstance() {
+  return ::PluginService::GetInstance();
+}
+
+void PluginService::PurgePluginListCache(BrowserContext* browser_context,
+                                         bool reload_pages) {
+  for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
+       !it.IsAtEnd(); it.Advance()) {
+    RenderProcessHost* host = it.GetCurrentValue();
+    if (!browser_context || host->GetBrowserContext() == browser_context)
+      host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
+  }
+}
+
+}  // namespace content
+
 // static
 PluginService* PluginService::GetInstance() {
   return Singleton<PluginService>::get();
@@ -139,12 +157,12 @@
   if (!plugin_list_)
     plugin_list_ = webkit::npapi::PluginList::Singleton();
 
-  plugin_list()->set_will_load_plugins_callback(
+  plugin_list_->set_will_load_plugins_callback(
       base::Bind(&WillLoadPluginsCallback));
 
   RegisterPepperPlugins();
 
-  content::GetContentClient()->AddNPAPIPlugins(plugin_list());
+  content::GetContentClient()->AddNPAPIPlugins(plugin_list_);
 
   // Load any specified on the command line as well.
   const CommandLine* command_line = CommandLine::ForCurrentProcess();
@@ -153,7 +171,7 @@
     AddExtraPluginPath(path);
   path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
   if (!path.empty())
-    plugin_list()->AddExtraPluginDir(path);
+    plugin_list_->AddExtraPluginDir(path);
 
 #if defined(OS_MACOSX)
   // We need to know when the browser comes forward so we can bring modal plugin
@@ -193,7 +211,7 @@
   // Get the list of all paths for registering the FilePathWatchers
   // that will track and if needed reload the list of plugins on runtime.
   std::vector<FilePath> plugin_dirs;
-  plugin_list()->GetPluginDirectories(&plugin_dirs);
+  plugin_list_->GetPluginDirectories(&plugin_dirs);
 
   for (size_t i = 0; i < plugin_dirs.size(); ++i) {
     // FilePathWatcher can not handle non-absolute paths under windows.
@@ -438,8 +456,8 @@
     std::vector<webkit::WebPluginInfo>* plugins,
     std::vector<std::string>* actual_mime_types) {
   bool use_stale = false;
-  plugin_list()->GetPluginInfoArray(url, mime_type, allow_wildcard,
-                                    &use_stale, plugins, actual_mime_types);
+  plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard,
+                                   &use_stale, plugins, actual_mime_types);
   return use_stale;
 }
 
@@ -486,7 +504,7 @@
 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path,
                                         webkit::WebPluginInfo* info) {
   std::vector<webkit::WebPluginInfo> plugins;
-  plugin_list()->GetPluginsIfNoRefreshNeeded(&plugins);
+  plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins);
 
   for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin();
        it != plugins.end();
@@ -510,7 +528,7 @@
           target_loop, callback));
 #else
   std::vector<webkit::WebPluginInfo> cached_plugins;
-  if (plugin_list()->GetPluginsIfNoRefreshNeeded(&cached_plugins)) {
+  if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) {
     // Can't assume the caller is reentrant.
     target_loop->PostTask(FROM_HERE,
         base::Bind(&RunGetPluginsCallback, callback, cached_plugins));
@@ -536,7 +554,7 @@
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
 
   std::vector<webkit::WebPluginInfo> plugins;
-  plugin_list()->GetPlugins(&plugins);
+  plugin_list_->GetPlugins(&plugins);
 
   target_loop->PostTask(FROM_HERE,
       base::Bind(&RunGetPluginsCallback, callback, plugins));
@@ -551,7 +569,7 @@
     hklm_key_.StartWatching();
   }
 
-  plugin_list()->RefreshPlugins();
+  plugin_list_->RefreshPlugins();
   PurgePluginListCache(NULL, false);
 #else
   // This event should only get signaled on a Windows machine.
@@ -572,18 +590,6 @@
   NOTREACHED();
 }
 
-void PluginService::PurgePluginListCache(
-    content::BrowserContext* browser_context,
-    bool reload_pages) {
-  for (content::RenderProcessHost::iterator it =
-          content::RenderProcessHost::AllHostsIterator();
-       !it.IsAtEnd(); it.Advance()) {
-    content::RenderProcessHost* host = it.GetCurrentValue();
-    if (!browser_context || host->GetBrowserContext() == browser_context)
-      host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
-  }
-}
-
 void PluginService::RegisterPepperPlugins() {
   // TODO(abarth): It seems like the PepperPluginRegistry should do this work.
   PepperPluginRegistry::ComputeList(&ppapi_plugins_);
@@ -630,20 +636,28 @@
 }
 #endif
 
+void PluginService::SetFilter(content::PluginServiceFilter* filter) {
+  filter_ = filter;
+}
+
+content::PluginServiceFilter* PluginService::GetFilter() {
+  return filter_;
+}
+
 void PluginService::RefreshPlugins() {
-  plugin_list()->RefreshPlugins();
+  plugin_list_->RefreshPlugins();
 }
 
 void PluginService::AddExtraPluginPath(const FilePath& path) {
-  plugin_list()->AddExtraPluginPath(path);
+  plugin_list_->AddExtraPluginPath(path);
 }
 
 void PluginService::RemoveExtraPluginPath(const FilePath& path) {
-  plugin_list()->RemoveExtraPluginPath(path);
+  plugin_list_->RemoveExtraPluginPath(path);
 }
 
 void PluginService::UnregisterInternalPlugin(const FilePath& path) {
-  plugin_list()->UnregisterInternalPlugin(path);
+  plugin_list_->UnregisterInternalPlugin(path);
 }
 
 void PluginService::SetPluginListForTesting(
@@ -652,9 +666,13 @@
 }
 
 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) {
-  plugin_list()->RegisterInternalPlugin(info);
+  plugin_list_->RegisterInternalPlugin(info);
 }
 
 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) {
-  return plugin_list()->GetPluginGroupName(plugin_name);
+  return plugin_list_->GetPluginGroupName(plugin_name);
+}
+
+webkit::npapi::PluginList* PluginService::GetPluginList() {
+  return plugin_list_;
 }