Have ChildProcessInfo contain a list of all running child processes (i.e. instead of Service and other child process service maintain it).  In a future change I'll start moving some of the code from PluginProcessHost to ChildProcessInfo.
Review URL: http://codereview.chromium.org/24017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9804 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc
index d36cc69..87d2aeb2 100644
--- a/chrome/browser/plugin_service.cc
+++ b/chrome/browser/plugin_service.cc
@@ -5,7 +5,6 @@
 #include "chrome/browser/plugin_service.h"
 
 #include "base/command_line.h"
-#include "base/singleton.h"
 #include "base/thread.h"
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/chrome_plugin_host.h"
@@ -30,7 +29,6 @@
       plugin_shutdown_handler_(new ShutdownHandler) {
   // Have the NPAPI plugin list search for Chrome plugins as well.
   ChromePluginLib::RegisterPluginsWithNPAPI();
-
   // Load the one specified on the command line as well.
   const CommandLine* command_line = CommandLine::ForCurrentProcess();
   std::wstring path = command_line->GetSwitchValue(switches::kLoadPlugin);
@@ -77,9 +75,13 @@
     return NULL;
   }
 
-  PluginMap::iterator found = plugin_hosts_.find(plugin_path);
-  if (found != plugin_hosts_.end())
-    return found->second;
+  for (ChildProcessInfo::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
+       !iter.Done(); ++iter) {
+    PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
+    if (plugin->info().path == plugin_path)
+      return plugin;
+  }
+
   return NULL;
 }
 
@@ -100,13 +102,13 @@
   }
 
   // This plugin isn't loaded by any plugin process, so create a new process.
-  plugin_host = new PluginProcessHost(this);
+  plugin_host = new PluginProcessHost();
   if (!plugin_host->Init(info, clsid, ui_locale_)) {
     DCHECK(false);  // Init is not expected to fail
     delete plugin_host;
     return NULL;
   }
-  plugin_hosts_[plugin_path] = plugin_host;
+
   return plugin_host;
 
   // TODO(jabdelmalek): adding a new channel means we can have one less
@@ -133,31 +135,6 @@
   }
 }
 
-void PluginService::OnPluginProcessIsShuttingDown(PluginProcessHost* host) {
-  RemoveHost(host);
-}
-
-void PluginService::OnPluginProcessExited(PluginProcessHost* host) {
-  RemoveHost(host);  // in case shutdown was not graceful
-  delete host;
-}
-
-void PluginService::RemoveHost(PluginProcessHost* host) {
-  DCHECK(MessageLoop::current() ==
-         ChromeThread::GetMessageLoop(ChromeThread::IO));
-  // Search for the instance rather than lookup by plugin path,
-  // there is a small window where two instances for the same
-  // plugin path can co-exists.
-  PluginMap::iterator i = plugin_hosts_.begin();
-  while (i != plugin_hosts_.end()) {
-    if (i->second == host) {
-      plugin_hosts_.erase(i);
-      return;
-    }
-    i++;
-  }
-}
-
 FilePath PluginService::GetPluginPath(const GURL& url,
                                       const std::string& mime_type,
                                       const std::string& clsid,
@@ -193,29 +170,12 @@
 }
 
 void PluginService::OnShutdown() {
-  PluginMap::iterator host_index;
-  for (host_index = plugin_hosts_.begin(); host_index != plugin_hosts_.end();
-          ++host_index) {
-    host_index->second->Shutdown();
+  for (ChildProcessInfo::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
+       !iter.Done(); ++iter) {
+    static_cast<PluginProcessHost*>(*iter)->Shutdown();
   }
 }
 
-PluginProcessHostIterator::PluginProcessHostIterator()
-    : iterator_(PluginService::GetInstance()->plugin_hosts_.begin()),
-      end_(PluginService::GetInstance()->plugin_hosts_.end()) {
-  DCHECK(MessageLoop::current() ==
-         ChromeThread::GetMessageLoop(ChromeThread::IO)) <<
-             "PluginProcessHostIterator must be used on the IO thread.";
-}
-
-PluginProcessHostIterator::PluginProcessHostIterator(
-      const PluginProcessHostIterator& instance)
-    : iterator_(instance.iterator_) {
-  DCHECK(MessageLoop::current() ==
-         ChromeThread::GetMessageLoop(ChromeThread::IO)) <<
-             "PluginProcessHostIterator must be used on the IO thread.";
-}
-
 void PluginService::ShutdownHandler::InitiateShutdown() {
   g_browser_process->io_thread()->message_loop()->PostTask(
       FROM_HERE,