Added logging useful for understanding Pepper broker lifetime.

Also, added support for VLOG to Pepper OOP plugin and Pepper broker processes by forwarding --vmodule to these processes.

BUG=none
TEST=Launch a dbg build of Chrome with --vmodule=ppapi_plugin_process_host=1,broker_process_dispatcher=1,ppapi_broker_main=1,broker_dispatcher=1,proxy_channel=1", visit a page that uses the broker, and navigate away from that page. The new log statements should be displayed.


Review URL: http://codereview.chromium.org/8347009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107451 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc
index d72dd55..eea898d 100644
--- a/content/browser/ppapi_plugin_process_host.cc
+++ b/content/browser/ppapi_plugin_process_host.cc
@@ -4,6 +4,7 @@
 
 #include "content/browser/ppapi_plugin_process_host.h"
 
+#include "base/base_switches.h"
 #include "base/command_line.h"
 #include "base/file_path.h"
 #include "base/process_util.h"
@@ -52,6 +53,8 @@
 };
 
 PpapiPluginProcessHost::~PpapiPluginProcessHost() {
+  DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "")
+           << "~PpapiPluginProcessHost()";
   CancelRequests();
 }
 
@@ -132,16 +135,23 @@
                                          : switches::kPpapiPluginProcess);
   cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id());
 
+  // These switches are forwarded to both plugin and broker pocesses.
+  static const char* kCommonForwardSwitches[] = {
+    switches::kVModule
+  };
+  cmd_line->CopySwitchesFrom(browser_command_line, kCommonForwardSwitches,
+                             arraysize(kCommonForwardSwitches));
+
   if (!is_broker_) {
     // TODO(vtl): Stop passing flash args in the command line, on windows is
     // going to explode.
-    static const char* kForwardSwitches[] = {
+    static const char* kPluginForwardSwitches[] = {
       switches::kNoSandbox,
       switches::kPpapiFlashArgs,
       switches::kPpapiStartupDialog
     };
-    cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
-                               arraysize(kForwardSwitches));
+    cmd_line->CopySwitchesFrom(browser_command_line, kPluginForwardSwitches,
+                               arraysize(kPluginForwardSwitches));
   }
 
   if (!plugin_launcher.empty())
@@ -212,6 +222,8 @@
 // Called when the browser <--> plugin channel has an error. This normally
 // means the plugin has crashed.
 void PpapiPluginProcessHost::OnChannelError() {
+  DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "")
+           << "::OnChannelError()";
   // We don't need to notify the renderers that were communicating with the
   // plugin since they have their own channels which will go into the error
   // state at the same time. Instead, we just need to notify any renderers
@@ -220,6 +232,8 @@
 }
 
 void PpapiPluginProcessHost::CancelRequests() {
+  DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "")
+           << "CancelRequests()";
   for (size_t i = 0; i < pending_requests_.size(); i++) {
     pending_requests_[i]->OnChannelOpened(base::kNullProcessHandle,
                                           IPC::ChannelHandle());
diff --git a/content/ppapi_plugin/broker_process_dispatcher.cc b/content/ppapi_plugin/broker_process_dispatcher.cc
index b8c31d3..26a7100 100644
--- a/content/ppapi_plugin/broker_process_dispatcher.cc
+++ b/content/ppapi_plugin/broker_process_dispatcher.cc
@@ -8,15 +8,16 @@
 
 namespace {
 
-class PluginReleaseTask : public Task {
+class BrokerReleaseTask : public Task {
  public:
   void Run() {
+    DVLOG(1) << "BrokerReleaseTask::Run()";
     ChildProcess::current()->ReleaseProcess();
   }
 };
 
-// How long we wait before releasing the plugin process.
-const int kPluginReleaseTimeMs = 30 * 1000;  // 30 seconds.
+// How long we wait before releasing the broker process.
+const int kBrokerReleaseTimeMs = 30 * 1000;  // 30 seconds.
 
 }  // namespace
 
@@ -29,11 +30,12 @@
 }
 
 BrokerProcessDispatcher::~BrokerProcessDispatcher() {
+  DVLOG(1) << "BrokerProcessDispatcher::~BrokerProcessDispatcher()";
   // Don't free the process right away. This timer allows the child process
   // to be re-used if the user rapidly goes to a new page that requires this
   // plugin. This is the case for common plugins where they may be used on a
   // source and destination page of a navigation. We don't want to tear down
   // and re-start processes each time in these cases.
-  MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(),
-                                          kPluginReleaseTimeMs);
+  MessageLoop::current()->PostDelayedTask(FROM_HERE, new BrokerReleaseTask(),
+                                          kBrokerReleaseTimeMs);
 }
diff --git a/content/ppapi_plugin/ppapi_broker_main.cc b/content/ppapi_plugin/ppapi_broker_main.cc
index 17cd7b7..8789a612 100644
--- a/content/ppapi_plugin/ppapi_broker_main.cc
+++ b/content/ppapi_plugin/ppapi_broker_main.cc
@@ -24,5 +24,6 @@
   ppapi_broker_process.set_main_thread(new PpapiThread(true));  // Broker.
 
   main_message_loop.Run();
+  DVLOG(1) << "PpapiBrokerMain exiting";
   return 0;
 }
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index 9c798a1..56aa7b9 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -478,11 +478,11 @@
 }
 
 bool BrokerDispatcherWrapper::Init(
-    base::ProcessHandle plugin_process_handle,
+    base::ProcessHandle broker_process_handle,
     const IPC::ChannelHandle& channel_handle) {
   dispatcher_delegate_.reset(new DispatcherDelegate);
   dispatcher_.reset(
-      new ppapi::proxy::BrokerHostDispatcher(plugin_process_handle));
+      new ppapi::proxy::BrokerHostDispatcher(broker_process_handle));
 
   if (!dispatcher_->InitBrokerWithChannel(dispatcher_delegate_.get(),
                                           channel_handle,
diff --git a/ppapi/proxy/broker_dispatcher.cc b/ppapi/proxy/broker_dispatcher.cc
index 23c13240..30cee185 100644
--- a/ppapi/proxy/broker_dispatcher.cc
+++ b/ppapi/proxy/broker_dispatcher.cc
@@ -83,6 +83,7 @@
 }
 
 void BrokerHostDispatcher::OnChannelError() {
+  DVLOG(1) << "BrokerHostDispatcher::OnChannelError()";
   BrokerDispatcher::OnChannelError();  // Stop using the channel.
 
   // Tell the host about the crash so it can clean up and display notification.
@@ -97,6 +98,7 @@
 }
 
 void BrokerSideDispatcher::OnChannelError() {
+  DVLOG(1) << "BrokerSideDispatcher::OnChannelError()";
   BrokerDispatcher::OnChannelError();
 
   // The renderer has crashed or exited. This channel and all instances
diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc
index 18e8651a..3bf6c206 100644
--- a/ppapi/proxy/proxy_channel.cc
+++ b/ppapi/proxy/proxy_channel.cc
@@ -17,6 +17,7 @@
 }
 
 ProxyChannel::~ProxyChannel() {
+  DVLOG(1) << "ProxyChannel::~ProxyChannel()";
 }
 
 bool ProxyChannel::InitWithChannel(Delegate* delegate,