DevTools: introduce public content::DevToolsAgentHost.

BUG=166824
TBR=jam

Review URL: https://chromiumcodereview.appspot.com/11665025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174606 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/devtools/devtools_agent_host.cc b/content/browser/devtools/devtools_agent_host_impl.cc
similarity index 65%
rename from content/browser/devtools/devtools_agent_host.cc
rename to content/browser/devtools/devtools_agent_host_impl.cc
index 75907f0..166158c 100644
--- a/content/browser/devtools/devtools_agent_host.cc
+++ b/content/browser/devtools/devtools_agent_host_impl.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "content/browser/devtools/devtools_agent_host.h"
+#include "content/browser/devtools/devtools_agent_host_impl.h"
 
 #include "base/basictypes.h"
 #include "content/common/devtools_messages.h"
@@ -13,47 +13,52 @@
 static int g_next_agent_host_id = 0;
 }  // namespace
 
-DevToolsAgentHost::DevToolsAgentHost()
+DevToolsAgentHostImpl::DevToolsAgentHostImpl()
     : close_listener_(NULL),
       id_(++g_next_agent_host_id) {
 }
 
-void DevToolsAgentHost::Attach() {
+void DevToolsAgentHostImpl::Attach() {
   SendMessageToAgent(new DevToolsAgentMsg_Attach(MSG_ROUTING_NONE));
   NotifyClientAttaching();
 }
 
-void DevToolsAgentHost::Reattach(const std::string& saved_agent_state) {
+void DevToolsAgentHostImpl::Reattach(const std::string& saved_agent_state) {
   SendMessageToAgent(new DevToolsAgentMsg_Reattach(
       MSG_ROUTING_NONE,
       saved_agent_state));
   NotifyClientAttaching();
 }
 
-void DevToolsAgentHost::Detach() {
+void DevToolsAgentHostImpl::Detach() {
   SendMessageToAgent(new DevToolsAgentMsg_Detach(MSG_ROUTING_NONE));
   NotifyClientDetaching();
 }
 
-void DevToolsAgentHost::DipatchOnInspectorBackend(const std::string& message) {
+void DevToolsAgentHostImpl::DipatchOnInspectorBackend(
+    const std::string& message) {
   SendMessageToAgent(new DevToolsAgentMsg_DispatchOnInspectorBackend(
       MSG_ROUTING_NONE, message));
 }
 
-void DevToolsAgentHost::InspectElement(int x, int y) {
+void DevToolsAgentHostImpl::InspectElement(int x, int y) {
   SendMessageToAgent(new DevToolsAgentMsg_InspectElement(MSG_ROUTING_NONE,
                                                          x, y));
 }
 
-void DevToolsAgentHost::AddMessageToConsole(ConsoleMessageLevel level,
-                                            const std::string& message) {
+void DevToolsAgentHostImpl::AddMessageToConsole(ConsoleMessageLevel level,
+                                                const std::string& message) {
   SendMessageToAgent(new DevToolsAgentMsg_AddMessageToConsole(
       MSG_ROUTING_NONE,
       level,
       message));
 }
 
-bool DevToolsAgentHost::NotifyCloseListener() {
+RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() {
+  return NULL;
+}
+
+bool DevToolsAgentHostImpl::NotifyCloseListener() {
   if (close_listener_) {
     CloseListener* close_listener = close_listener_;
     close_listener_ = NULL;
diff --git a/content/browser/devtools/devtools_agent_host.h b/content/browser/devtools/devtools_agent_host_impl.h
similarity index 69%
rename from content/browser/devtools/devtools_agent_host.h
rename to content/browser/devtools/devtools_agent_host_impl.h
index 2fb9856..df55c7e 100644
--- a/content/browser/devtools/devtools_agent_host.h
+++ b/content/browser/devtools/devtools_agent_host_impl.h
@@ -2,12 +2,14 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_H_
-#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_H_
+#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
+#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
 
 #include <string>
 
+#include "base/compiler_specific.h"
 #include "content/common/content_export.h"
+#include "content/public/browser/devtools_agent_host.h"
 #include "content/public/common/console_message_level.h"
 
 namespace IPC {
@@ -17,11 +19,11 @@
 namespace content {
 
 // Describes interface for managing devtools agents from the browser process.
-class CONTENT_EXPORT DevToolsAgentHost {
+class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
  public:
   class CONTENT_EXPORT CloseListener {
    public:
-    virtual void AgentHostClosing(DevToolsAgentHost*) = 0;
+    virtual void AgentHostClosing(DevToolsAgentHostImpl*) = 0;
    protected:
     virtual ~CloseListener() {}
   };
@@ -35,17 +37,18 @@
   void AddMessageToConsole(ConsoleMessageLevel level,
                            const std::string& message);
 
-  virtual int GetRenderProcessId() = 0;
-
   void set_close_listener(CloseListener* listener) {
     close_listener_ = listener;
   }
 
   int id() { return id_; }
 
+  // DevToolsAgentHost implementation.
+  virtual RenderViewHost* GetRenderViewHost() OVERRIDE;
+
  protected:
-  DevToolsAgentHost();
-  virtual ~DevToolsAgentHost() {}
+  DevToolsAgentHostImpl();
+  virtual ~DevToolsAgentHostImpl() {}
 
   virtual void SendMessageToAgent(IPC::Message* msg) = 0;
   virtual void NotifyClientAttaching() = 0;
@@ -61,4 +64,4 @@
 
 }  // namespace content
 
-#endif  // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_H_
+#endif  // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc
index 486113c..2e78bbfe 100644
--- a/content/browser/devtools/devtools_http_handler_impl.cc
+++ b/content/browser/devtools/devtools_http_handler_impl.cc
@@ -19,12 +19,13 @@
 #include "base/threading/thread.h"
 #include "base/utf_string_conversions.h"
 #include "base/values.h"
+#include "content/browser/devtools/devtools_agent_host_impl.h"
 #include "content/browser/devtools/devtools_browser_target.h"
 #include "content/browser/devtools/devtools_tracing_handler.h"
 #include "content/browser/web_contents/web_contents_impl.h"
 #include "content/common/devtools_messages.h"
 #include "content/public/browser/browser_thread.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
+#include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/devtools_client_host.h"
 #include "content/public/browser/devtools_http_handler_delegate.h"
 #include "content/public/browser/devtools_manager.h"
@@ -274,7 +275,7 @@
     DevToolsAgentHost* agent = manager->GetDevToolsAgentHostFor(it->second);
     if (!agent)
       continue;
-    RenderViewHost* rvh = DevToolsAgentHostRegistry::GetRenderViewHost(agent);
+    RenderViewHost* rvh = agent->GetRenderViewHost();
     if (rvh && rvh->GetProcess() == process)
       it->second->InspectedContentsClosing();
   }
@@ -623,8 +624,7 @@
   }
 
   DevToolsManager* manager = DevToolsManager::GetInstance();
-  DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
-      rvh);
+  DevToolsAgentHost* agent = DevToolsAgentHost::GetFor(rvh);
   if (manager->GetDevToolsClientHostFor(agent)) {
     Send500(connection_id,
             "Target with given id is being inspected: " + page_id);
@@ -820,8 +820,7 @@
 DevToolsHttpHandlerImpl::CreatePageInfo(RenderViewHost* rvh)
 {
   RenderViewHostDelegate* host_delegate = rvh->GetDelegate();
-  DevToolsAgentHost* agent =
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
+  DevToolsAgentHost* agent = DevToolsAgentHost::GetFor(rvh);
   DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
       GetDevToolsClientHostFor(agent);
   PageInfo page_info;
diff --git a/content/browser/devtools/devtools_manager_impl.cc b/content/browser/devtools/devtools_manager_impl.cc
index a17a629..579329b8 100644
--- a/content/browser/devtools/devtools_manager_impl.cc
+++ b/content/browser/devtools/devtools_manager_impl.cc
@@ -14,7 +14,6 @@
 #include "content/browser/renderer_host/render_view_host_impl.h"
 #include "content/browser/web_contents/web_contents_impl.h"
 #include "content/public/browser/browser_thread.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
 #include "content/public/browser/devtools_client_host.h"
 #include "googleurl/src/gurl.h"
 
@@ -40,7 +39,10 @@
 
 DevToolsClientHost* DevToolsManagerImpl::GetDevToolsClientHostFor(
     DevToolsAgentHost* agent_host) {
-  AgentToClientHostMap::iterator it = agent_to_client_host_.find(agent_host);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  AgentToClientHostMap::iterator it =
+      agent_to_client_host_.find(agent_host_impl);
   if (it != agent_to_client_host_.end())
     return it->second;
   return NULL;
@@ -57,8 +59,10 @@
 void DevToolsManagerImpl::RegisterDevToolsClientHostFor(
     DevToolsAgentHost* agent_host,
     DevToolsClientHost* client_host) {
-  BindClientHost(agent_host, client_host);
-  agent_host->Attach();
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  BindClientHost(agent_host_impl, client_host);
+  agent_host_impl->Attach();
 }
 
 bool DevToolsManagerImpl::DispatchOnInspectorBackend(
@@ -67,8 +71,9 @@
   DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(from);
   if (!agent_host)
     return false;
-
-  agent_host->DipatchOnInspectorBackend(message);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  agent_host_impl->DipatchOnInspectorBackend(message);
   return true;
 }
 
@@ -86,24 +91,29 @@
 
 void DevToolsManagerImpl::InspectElement(DevToolsAgentHost* agent_host,
                                          int x, int y) {
-  agent_host->InspectElement(x, y);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  agent_host_impl->InspectElement(x, y);
 }
 
 void DevToolsManagerImpl::AddMessageToConsole(DevToolsAgentHost* agent_host,
                                               ConsoleMessageLevel level,
                                               const std::string& message) {
-  agent_host->AddMessageToConsole(level, message);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  agent_host_impl->AddMessageToConsole(level, message);
 }
 
 void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) {
   DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host);
   if (!agent_host)
     return;
-
-  UnbindClientHost(agent_host, client_host);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  UnbindClientHost(agent_host_impl, client_host);
 }
 
-void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHost* agent_host) {
+void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHostImpl* agent_host) {
   UnregisterDevToolsClientHostFor(agent_host);
 }
 
@@ -112,12 +122,14 @@
   DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host);
   if (!client_host)
     return;
-  UnbindClientHost(agent_host, client_host);
+  DevToolsAgentHostImpl* agent_host_impl =
+      static_cast<DevToolsAgentHostImpl*>(agent_host);
+  UnbindClientHost(agent_host_impl, client_host);
   client_host->InspectedContentsClosing();
 }
 
 void DevToolsManagerImpl::BindClientHost(
-    DevToolsAgentHost* agent_host,
+    DevToolsAgentHostImpl* agent_host,
     DevToolsClientHost* client_host) {
   DCHECK(agent_to_client_host_.find(agent_host) ==
       agent_to_client_host_.end());
@@ -134,13 +146,16 @@
   client_to_agent_host_[client_host] = agent_host;
   agent_host->set_close_listener(this);
 
-  int process_id = agent_host->GetRenderProcessId();
-  if (process_id != -1)
+  // TODO(pfeldman): move this into the RenderViewDevToolsAgentHost attach /
+  // detach sniffers.
+  RenderViewHost* rvh = agent_host->GetRenderViewHost();
+  if (rvh) {
     ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies(
-        process_id);
+        rvh->GetProcess()->GetID());
+  }
 }
 
-void DevToolsManagerImpl::UnbindClientHost(DevToolsAgentHost* agent_host,
+void DevToolsManagerImpl::UnbindClientHost(DevToolsAgentHostImpl* agent_host,
                                            DevToolsClientHost* client_host) {
   DCHECK(agent_host);
   DCHECK(agent_to_client_host_.find(agent_host)->second ==
@@ -158,12 +173,14 @@
         FROM_HERE,
         base::Bind(&DevToolsNetLogObserver::Detach));
   }
-  int process_id = agent_host->GetRenderProcessId();
-  bool process_has_agents = false;
+  RenderViewHost* rvh = agent_host->GetRenderViewHost();
+  int process_id = rvh ? rvh->GetProcess()->GetID() : -1;
+  bool process_has_agents = !rvh;
   for (AgentToClientHostMap::iterator it = agent_to_client_host_.begin();
        !process_has_agents && it != agent_to_client_host_.end();
        ++it) {
-    if (it->first->GetRenderProcessId() == process_id)
+    RenderViewHost* cur_rvh = it->first->GetRenderViewHost();
+    if (cur_rvh && cur_rvh->GetProcess()->GetID() == process_id)
       process_has_agents = true;
   }
 
diff --git a/content/browser/devtools/devtools_manager_impl.h b/content/browser/devtools/devtools_manager_impl.h
index 95028353..655561c 100644
--- a/content/browser/devtools/devtools_manager_impl.h
+++ b/content/browser/devtools/devtools_manager_impl.h
@@ -10,7 +10,7 @@
 
 #include "base/compiler_specific.h"
 #include "base/memory/singleton.h"
-#include "content/browser/devtools/devtools_agent_host.h"
+#include "content/browser/devtools/devtools_agent_host_impl.h"
 #include "content/common/content_export.h"
 #include "content/public/browser/devtools_client_host.h"
 #include "content/public/browser/devtools_manager.h"
@@ -23,7 +23,6 @@
 
 namespace content {
 
-class DevToolsAgentHost;
 class RenderViewHost;
 
 // This class is a singleton that manages DevToolsClientHost instances and
@@ -33,7 +32,7 @@
 // just convenience methods that call corresponding methods accepting
 // DevToolAgentHost.
 class CONTENT_EXPORT DevToolsManagerImpl
-    : public DevToolsAgentHost::CloseListener,
+    : public DevToolsAgentHostImpl::CloseListener,
       public DevToolsManager {
  public:
   // Returns single instance of this class. The instance is destroyed on the
@@ -70,11 +69,11 @@
   friend struct DefaultSingletonTraits<DevToolsManagerImpl>;
 
   // DevToolsAgentHost::CloseListener implementation.
-  virtual void AgentHostClosing(DevToolsAgentHost* host) OVERRIDE;
+  virtual void AgentHostClosing(DevToolsAgentHostImpl* host) OVERRIDE;
 
-  void BindClientHost(DevToolsAgentHost* agent_host,
+  void BindClientHost(DevToolsAgentHostImpl* agent_host,
                       DevToolsClientHost* client_host);
-  void UnbindClientHost(DevToolsAgentHost* agent_host,
+  void UnbindClientHost(DevToolsAgentHostImpl* agent_host,
                         DevToolsClientHost* client_host);
 
   // These two maps are for tracking dependencies between inspected contents and
@@ -83,11 +82,11 @@
   //
   // DevToolsManagerImpl starts listening to DevToolsClientHosts when they are
   // put into these maps and removes them when they are closing.
-  typedef std::map<DevToolsAgentHost*, DevToolsClientHost*>
+  typedef std::map<DevToolsAgentHostImpl*, DevToolsClientHost*>
       AgentToClientHostMap;
   AgentToClientHostMap agent_to_client_host_;
 
-  typedef std::map<DevToolsClientHost*, DevToolsAgentHost*>
+  typedef std::map<DevToolsClientHost*, DevToolsAgentHostImpl*>
       ClientToAgentHostMap;
   ClientToAgentHostMap client_to_agent_host_;
 
diff --git a/content/browser/devtools/devtools_manager_unittest.cc b/content/browser/devtools/devtools_manager_unittest.cc
index 48fb62f8..21f637be 100644
--- a/content/browser/devtools/devtools_manager_unittest.cc
+++ b/content/browser/devtools/devtools_manager_unittest.cc
@@ -10,7 +10,7 @@
 #include "content/browser/web_contents/test_web_contents.h"
 #include "content/common/view_messages.h"
 #include "content/public/browser/content_browser_client.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
+#include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/devtools_client_host.h"
 #include "content/public/browser/web_contents_delegate.h"
 #include "content/test/test_content_browser_client.h"
@@ -127,8 +127,7 @@
 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) {
   DevToolsManagerImpl manager;
 
-  DevToolsAgentHost* agent =
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh());
+  DevToolsAgentHost* agent = DevToolsAgentHost::GetFor(rvh());
   DevToolsClientHost* host = manager.GetDevToolsClientHostFor(agent);
   EXPECT_TRUE(NULL == host);
 
@@ -154,13 +153,12 @@
   DevToolsManagerImpl manager;
 
   TestDevToolsClientHost client_host;
-  DevToolsAgentHost* agent_host =
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh());
+  DevToolsAgentHost* agent_host = DevToolsAgentHost::GetFor(rvh());
   manager.RegisterDevToolsClientHostFor(agent_host, &client_host);
   EXPECT_EQ(0, TestDevToolsClientHost::close_counter);
 
   std::string m = "test message";
-  agent_host = DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh());
+  agent_host = DevToolsAgentHost::GetFor(rvh());
   manager.DispatchOnInspectorFrontend(agent_host, m);
   EXPECT_TRUE(&m == client_host.last_sent_message);
 
@@ -176,8 +174,7 @@
   contents()->SetDelegate(&delegate);
 
   TestDevToolsClientHost client_host;
-  DevToolsAgentHost* agent_host =
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(inspected_rvh);
+  DevToolsAgentHost* agent_host = DevToolsAgentHost::GetFor(inspected_rvh);
   DevToolsManager::GetInstance()->
       RegisterDevToolsClientHostFor(agent_host, &client_host);
 
@@ -214,7 +211,7 @@
   TestDevToolsClientHost client_host;
   DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
   devtools_manager->RegisterDevToolsClientHostFor(
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh()),
+      DevToolsAgentHost::GetFor(rvh()),
       &client_host);
 
   // Navigate to new site which should get a new RenderViewHost.
@@ -223,7 +220,7 @@
       url2, Referrer(), PAGE_TRANSITION_TYPED, std::string());
   EXPECT_TRUE(contents()->cross_navigation_pending());
   EXPECT_EQ(&client_host, devtools_manager->GetDevToolsClientHostFor(
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(pending_rvh())));
+      DevToolsAgentHost::GetFor(pending_rvh())));
 
   // Interrupt pending navigation and navigate back to the original site.
   controller().LoadURL(
@@ -231,7 +228,7 @@
   contents()->TestDidNavigate(rvh(), 1, url, PAGE_TRANSITION_TYPED);
   EXPECT_FALSE(contents()->cross_navigation_pending());
   EXPECT_EQ(&client_host, devtools_manager->GetDevToolsClientHostFor(
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh())));
+      DevToolsAgentHost::GetFor(rvh())));
   client_host.Close(DevToolsManager::GetInstance());
 }
 
diff --git a/content/browser/devtools/render_view_devtools_agent_host.cc b/content/browser/devtools/render_view_devtools_agent_host.cc
index 2f056d08..37448bf4 100644
--- a/content/browser/devtools/render_view_devtools_agent_host.cc
+++ b/content/browser/devtools/render_view_devtools_agent_host.cc
@@ -15,7 +15,6 @@
 #include "content/browser/web_contents/web_contents_impl.h"
 #include "content/common/devtools_messages.h"
 #include "content/public/browser/content_browser_client.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_types.h"
 #include "content/public/browser/render_widget_host_view.h"
@@ -69,8 +68,7 @@
 };
 
 // static
-DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHost(
-    RenderViewHost* rvh) {
+DevToolsAgentHost* DevToolsAgentHost::GetFor(RenderViewHost* rvh) {
   RenderViewDevToolsAgentHost* result = FindAgentHost(rvh);
   if (!result)
     result = new RenderViewDevToolsAgentHost(rvh);
@@ -78,22 +76,11 @@
 }
 
 // static
-RenderViewHost* DevToolsAgentHostRegistry::GetRenderViewHost(
-     DevToolsAgentHost* agent_host) {
-  Instances::iterator it = std::find(g_instances.Get().begin(),
-                                     g_instances.Get().end(),
-                                     agent_host);
-  if (it != g_instances.Get().end())
-    return (*it)->render_view_host_;
-  return NULL;
-}
-
-// static
-bool DevToolsAgentHostRegistry::HasDevToolsAgentHost(RenderViewHost* rvh) {
+bool DevToolsAgentHost::HasFor(RenderViewHost* rvh) {
   return FindAgentHost(rvh) != NULL;
 }
 
-bool DevToolsAgentHostRegistry::IsDebuggerAttached(WebContents* web_contents) {
+bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) {
   if (g_instances == NULL)
     return false;
   DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
@@ -113,7 +100,7 @@
 }
 
 // static
-int DevToolsAgentHostRegistry::DisconnectRenderViewHost(RenderViewHost* rvh) {
+int DevToolsAgentHost::DisconnectRenderViewHost(RenderViewHost* rvh) {
   RenderViewDevToolsAgentHost* agent_host = FindAgentHost(rvh);
   if (!agent_host)
     return -1;
@@ -122,8 +109,8 @@
 }
 
 // static
-void DevToolsAgentHostRegistry::ConnectRenderViewHost(int cookie,
-                                                      RenderViewHost* rvh) {
+void DevToolsAgentHost::ConnectRenderViewHost(int cookie,
+                                              RenderViewHost* rvh) {
   for (Instances::iterator it = g_instances.Get().begin();
        it != g_instances.Get().end(); ++it) {
     if (cookie == (*it)->id()) {
@@ -137,9 +124,9 @@
 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation(
     RenderViewHost* pending,
     RenderViewHost* current) {
-  int cookie = DevToolsAgentHostRegistry::DisconnectRenderViewHost(pending);
+  int cookie = DevToolsAgentHost::DisconnectRenderViewHost(pending);
   if (cookie != -1)
-    DevToolsAgentHostRegistry::ConnectRenderViewHost(cookie, current);
+    DevToolsAgentHost::ConnectRenderViewHost(cookie, current);
 }
 
 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(
@@ -151,12 +138,14 @@
     Observe(delegate->GetAsWebContents());
 }
 
-
-void RenderViewDevToolsAgentHost::Detach() {
-  DevToolsAgentHost::Detach();
-  Destroy();
+RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() {
+  return render_view_host_;
 }
 
+void RenderViewDevToolsAgentHost::Detach() {
+  DevToolsAgentHostImpl::Detach();
+  Destroy();
+}
 
 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) {
   msg->set_routing_id(render_view_host_->GetRoutingID());
@@ -181,10 +170,6 @@
       Details<RenderViewHost>(render_view_host_));
 }
 
-int RenderViewDevToolsAgentHost::GetRenderProcessId() {
-  return render_view_host_->GetProcess()->GetID();
-}
-
 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() {
   Instances::iterator it = std::find(g_instances.Get().begin(),
                                      g_instances.Get().end(),
diff --git a/content/browser/devtools/render_view_devtools_agent_host.h b/content/browser/devtools/render_view_devtools_agent_host.h
index f9f4f20..580ebe6 100644
--- a/content/browser/devtools/render_view_devtools_agent_host.h
+++ b/content/browser/devtools/render_view_devtools_agent_host.h
@@ -10,7 +10,7 @@
 #include "base/basictypes.h"
 #include "base/compiler_specific.h"
 #include "base/memory/scoped_ptr.h"
-#include "content/browser/devtools/devtools_agent_host.h"
+#include "content/browser/devtools/devtools_agent_host_impl.h"
 #include "content/common/content_export.h"
 #include "content/public/browser/render_view_host_observer.h"
 #include "content/public/browser/web_contents_observer.h"
@@ -22,7 +22,7 @@
 class DevToolsAgentHostRvhObserver;
 
 class CONTENT_EXPORT RenderViewDevToolsAgentHost
-    : public DevToolsAgentHost,
+    : public DevToolsAgentHostImpl,
       private WebContentsObserver {
  public:
   static void OnCancelPendingNavigation(RenderViewHost* pending,
@@ -33,17 +33,19 @@
   RenderViewHost* render_view_host() { return render_view_host_; }
 
  private:
-  friend class DevToolsAgentHostRegistry;
+  friend class DevToolsAgentHost;
   friend class DevToolsAgentHostRvhObserver;
 
   virtual ~RenderViewDevToolsAgentHost();
 
-  // DevToolsAgentHost implementation.
+  // DevTooolsAgentHost overrides.
+  virtual RenderViewHost* GetRenderViewHost() OVERRIDE;
+
+  // DevToolsAgentHostImpl implementation.
   virtual void Detach() OVERRIDE;
   virtual void SendMessageToAgent(IPC::Message* msg) OVERRIDE;
   virtual void NotifyClientAttaching() OVERRIDE;
   virtual void NotifyClientDetaching() OVERRIDE;
-  virtual int GetRenderProcessId() OVERRIDE;
 
   // WebContentsObserver overrides.
   virtual void AboutToNavigateRenderView(RenderViewHost* dest_rvh) OVERRIDE;
diff --git a/content/browser/devtools/worker_devtools_manager.cc b/content/browser/devtools/worker_devtools_manager.cc
index 62079fb..a6c9a79 100644
--- a/content/browser/devtools/worker_devtools_manager.cc
+++ b/content/browser/devtools/worker_devtools_manager.cc
@@ -9,14 +9,13 @@
 
 #include "base/bind.h"
 #include "base/lazy_instance.h"
-#include "content/browser/devtools/devtools_agent_host.h"
+#include "content/browser/devtools/devtools_agent_host_impl.h"
 #include "content/browser/devtools/devtools_manager_impl.h"
 #include "content/browser/devtools/worker_devtools_message_filter.h"
 #include "content/browser/worker_host/worker_service_impl.h"
 #include "content/common/devtools_messages.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/child_process_data.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
 #include "content/public/common/process_type.h"
 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
@@ -28,7 +27,7 @@
 
 // Called on the UI thread.
 // static
-DevToolsAgentHost* DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker(
+DevToolsAgentHost* DevToolsAgentHost::GetForWorker(
     int worker_process_id,
     int worker_route_id) {
   return WorkerDevToolsManager::GetDevToolsAgentHostForWorker(
@@ -57,7 +56,7 @@
 
 
 class WorkerDevToolsManager::WorkerDevToolsAgentHost
-    : public DevToolsAgentHost {
+    : public DevToolsAgentHostImpl {
  public:
   explicit WorkerDevToolsAgentHost(WorkerId worker_id)
       : has_worker_id_(false) {
@@ -87,7 +86,7 @@
   }
 
   virtual void Detach() {
-    DevToolsAgentHost::Detach();
+    DevToolsAgentHostImpl::Detach();
     Destroy();
   }
 
@@ -127,7 +126,7 @@
         worker_process_id, worker_route_id, *message);
   }
 
-  // DevToolsAgentHost implementation.
+  // DevToolsAgentHostImpl implementation.
   virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
     if (!has_worker_id_) {
       delete message;
@@ -144,7 +143,6 @@
 
   virtual void NotifyClientAttaching() OVERRIDE {}
   virtual void NotifyClientDetaching() OVERRIDE {}
-  virtual int GetRenderProcessId() OVERRIDE { return -1; }
 
   bool has_worker_id_;
   WorkerId worker_id_;
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 96e5886..8fcb09c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -48,7 +48,7 @@
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/color_chooser.h"
 #include "content/public/browser/content_browser_client.h"
-#include "content/public/browser/devtools_agent_host_registry.h"
+#include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/download_manager.h"
 #include "content/public/browser/download_url_parameters.h"
 #include "content/public/browser/invalidate_type.h"
@@ -3161,10 +3161,7 @@
   // Ignore renderer unresponsive event if debugger is attached to the tab
   // since the event may be a result of the renderer sitting on a breakpoint.
   // See http://crbug.com/65458
-  DevToolsAgentHost* agent =
-      DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
-  if (agent &&
-      DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
+  if (DevToolsAgentHost::IsDebuggerAttached(this))
     return;
 
   if (is_during_unload) {
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 4542fc1..3359c1f 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -54,7 +54,7 @@
     'public/browser/compositor_util.h',
     'public/browser/content_browser_client.cc',
     'public/browser/content_browser_client.h',
-    'public/browser/devtools_agent_host_registry.h',
+    'public/browser/devtools_agent_host.h',
     'public/browser/devtools_client_host.h',
     'public/browser/download_danger_type.h',
     'public/browser/download_id.h',
@@ -271,8 +271,8 @@
     'browser/child_process_security_policy_impl.h',
     'browser/cross_site_request_manager.cc',
     'browser/cross_site_request_manager.h',
-    'browser/devtools/devtools_agent_host.cc',
-    'browser/devtools/devtools_agent_host.h',
+    'browser/devtools/devtools_agent_host_impl.cc',
+    'browser/devtools/devtools_agent_host_impl.h',
     'browser/devtools/devtools_browser_target.cc',
     'browser/devtools/devtools_browser_target.h',
     'browser/devtools/devtools_frontend_host.cc',
diff --git a/content/public/browser/devtools_agent_host_registry.h b/content/public/browser/devtools_agent_host.h
similarity index 66%
rename from content/public/browser/devtools_agent_host_registry.h
rename to content/public/browser/devtools_agent_host.h
index caefaba..8dfd4cc 100644
--- a/content/public/browser/devtools_agent_host_registry.h
+++ b/content/public/browser/devtools_agent_host.h
@@ -2,34 +2,33 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_REGISTRY_H_
-#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_REGISTRY_H_
+#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
+#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
 
+#include <string>
+
+#include "base/basictypes.h"
 #include "content/common/content_export.h"
 
 namespace content {
 
-class DevToolsAgentHost;
 class RenderViewHost;
 class WebContents;
 
-class CONTENT_EXPORT DevToolsAgentHostRegistry {
+// Describes interface for managing devtools agents from browser process.
+class CONTENT_EXPORT DevToolsAgentHost {
  public:
   // Returns DevToolsAgentHost that can be used for inspecting |rvh|.
   // New DevToolsAgentHost will be created if it does not exist.
-  static DevToolsAgentHost* GetDevToolsAgentHost(RenderViewHost* rvh);
-
-  // Returns render view host instance for given |agent_host|.
-  static RenderViewHost* GetRenderViewHost(
-      DevToolsAgentHost* agent_host);
+  static DevToolsAgentHost* GetFor(RenderViewHost* rvh);
 
   // Returns true iff an instance of DevToolsAgentHost for the |rvh|
   // does exist.
-  static bool HasDevToolsAgentHost(RenderViewHost* rvh);
+  static bool HasFor(RenderViewHost* rvh);
 
   // Returns DevToolsAgentHost that can be used for inspecting shared worker
   // with given worker process host id and routing id.
-  static DevToolsAgentHost* GetDevToolsAgentHostForWorker(
+  static DevToolsAgentHost* GetForWorker(
       int worker_process_id,
       int worker_route_id);
 
@@ -44,8 +43,14 @@
   // to |rvh|.
   static void ConnectRenderViewHost(int agent_host_cookie,
                                     RenderViewHost* rvh);
+
+  // Returns render view host instance for this host if any.
+  virtual RenderViewHost* GetRenderViewHost() = 0;
+
+ protected:
+  virtual ~DevToolsAgentHost() {}
 };
 
 }  // namespace content
 
-#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_REGISTRY_H_
+#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_