Commit afc941e8 authored by yurys@chromium.org's avatar yurys@chromium.org

DevTools: introduce DevToolsAgentHost

We need an abstract interface that would encapsulate communication
with inspected instance's DevTools agent. It is going to have different
implementations at least for render views and shared workers. This
patch leaves all methods on the DevToolsManager that accept inspected
RenderViewHost just for convenience. Eventually DevToolsManager should
operate in terms of DevToolsAgentHost and DevToolsClientHost only.

BUG=None
TEST=DevTools tests
TBR=pfeldman

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98598 0039d316-1c4b-4281-b951-d872f2087c98
parent 6ca1d669
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/debugger/devtools_agent_host.h"
#include "base/basictypes.h"
DevToolsAgentHost::DevToolsAgentHost() : close_listener_(NULL) {
}
void DevToolsAgentHost::NotifyCloseListener() {
if (close_listener_) {
close_listener_->AgentHostClosing(this);
close_listener_ = NULL;
}
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEBUGGER_DEVTOOLS_AGENT_HOST_H_
#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_AGENT_HOST_H_
#pragma once
namespace IPC {
class Message;
}
// Describes interface for managing devtools agents from the browser process.
class DevToolsAgentHost {
public:
class CloseListener {
public:
virtual void AgentHostClosing(DevToolsAgentHost*) = 0;
protected:
virtual ~CloseListener() {}
};
// Sends the message to the devtools agent hosted by this object.
virtual void SendMessageToAgent(IPC::Message* msg) = 0;
// TODO(yurys): get rid of this method
virtual void NotifyClientClosing() = 0;
virtual int GetRenderProcessId() = 0;
void set_close_listener(CloseListener* listener) {
close_listener_ = listener;
}
protected:
DevToolsAgentHost();
virtual ~DevToolsAgentHost() {}
void NotifyCloseListener();
CloseListener* close_listener_;
};
#endif // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_AGENT_HOST_H_
......@@ -9,14 +9,14 @@
#include <map>
#include <string>
#include "content/browser/debugger/devtools_agent_host.h"
#include "content/browser/debugger/devtools_client_host.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
namespace IPC {
class Message;
}
class DevToolsAgentHost;
class DevToolsNetLogObserver;
class GURL;
class IOThread;
......@@ -28,8 +28,12 @@ typedef std::map<std::string, std::string> DevToolsRuntimeProperties;
// This class is a singleton that manages DevToolsClientHost instances and
// routes messages between developer tools clients and agents.
//
// Methods below that accept inspected RenderViewHost as a parameter are
// just convenience methods that call corresponding methods accepting
// DevToolAgentHost.
class DevToolsManager : public DevToolsClientHost::CloseListener,
public NotificationObserver {
public DevToolsAgentHost::CloseListener {
public:
static DevToolsManager* GetInstance();
......@@ -79,6 +83,9 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
// Closes all open developer tools windows.
void CloseAllClientHosts();
DevToolsClientHost* GetDevToolsClientHostFor(DevToolsAgentHost* agent_host);
void UnregisterDevToolsClientHostFor(DevToolsAgentHost* agent_host);
private:
// DevToolsClientHost::CloseListener override.
// This method will remove all references from the manager to the
......@@ -86,23 +93,19 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
// DevToolsClientHost.
virtual void ClientHostClosing(DevToolsClientHost* host);
// Overridden from NotificationObserver:
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details);
// DevToolsAgentHost::CloseListener implementation.
virtual void AgentHostClosing(DevToolsAgentHost* host);
// Returns RenderViewHost for the tab that is inspected by devtools
// client hosted by DevToolsClientHost.
RenderViewHost* GetInspectedRenderViewHost(DevToolsClientHost* client_host);
// Returns DevToolsAgentHost inspected by the DevToolsClientHost.
DevToolsAgentHost* GetAgentHost(DevToolsClientHost* client_host);
void SendAttachToAgent(RenderViewHost* inspected_rvh);
void SendDetachToAgent(RenderViewHost* inspected_rvh);
void SendAttachToAgent(DevToolsAgentHost*);
void SendDetachToAgent(DevToolsAgentHost*);
void BindClientHost(RenderViewHost* inspected_rvh,
void BindClientHost(DevToolsAgentHost* agent_host,
DevToolsClientHost* client_host,
const DevToolsRuntimeProperties& runtime_properties);
void UnbindClientHost(RenderViewHost* inspected_rvh,
void UnbindClientHost(DevToolsAgentHost* agent_host,
DevToolsClientHost* client_host);
// These two maps are for tracking dependencies between inspected tabs and
......@@ -111,15 +114,15 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
//
// DevToolsManager start listening to DevToolsClientHosts when they are put
// into these maps and removes them when they are closing.
typedef std::map<RenderViewHost*, DevToolsClientHost*>
InspectedRvhToClientHostMap;
InspectedRvhToClientHostMap inspected_rvh_to_client_host_;
typedef std::map<DevToolsAgentHost*, DevToolsClientHost*>
AgentToClientHostMap;
AgentToClientHostMap agent_to_client_host_;
typedef std::map<DevToolsClientHost*, RenderViewHost*>
typedef std::map<DevToolsClientHost*, DevToolsAgentHost*>
ClientHostToInspectedRvhMap;
ClientHostToInspectedRvhMap client_host_to_inspected_rvh_;
ClientHostToInspectedRvhMap client_to_agent_host_;
typedef std::map<RenderViewHost*, DevToolsRuntimeProperties>
typedef std::map<DevToolsAgentHost*, DevToolsRuntimeProperties>
RuntimePropertiesMap;
RuntimePropertiesMap runtime_properties_map_;
......@@ -129,8 +132,6 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
OrphanClientHosts orphan_client_hosts_;
int last_orphan_cookie_;
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(DevToolsManager);
};
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/debugger/render_view_devtools_agent_host.h"
#include "base/basictypes.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/site_instance.h"
#include "content/common/notification_service.h"
RenderViewDevToolsAgentHost::Instances RenderViewDevToolsAgentHost::instances_;
DevToolsAgentHost* RenderViewDevToolsAgentHost::FindFor(
RenderViewHost* rvh) {
Instances::iterator it = instances_.find(rvh);
if (it != instances_.end())
return it->second;
return new RenderViewDevToolsAgentHost(rvh);
}
RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh)
: render_view_host_(rvh) {
registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
Source<RenderViewHost>(rvh));
instances_[rvh] = this;
}
void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) {
msg->set_routing_id(render_view_host_->routing_id());
render_view_host_->Send(msg);
}
void RenderViewDevToolsAgentHost::NotifyClientClosing() {
NotificationService::current()->Notify(
content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
Source<content::BrowserContext>(
render_view_host_->site_instance()->GetProcess()->browser_context()),
Details<RenderViewHost>(render_view_host_));
}
int RenderViewDevToolsAgentHost::GetRenderProcessId() {
return render_view_host_->process()->id();
}
void RenderViewDevToolsAgentHost::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
DCHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_DELETED);
NotifyCloseListener();
delete this;
}
RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() {
instances_.erase(render_view_host_);
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEBUGGER_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_
#define CONTENT_BROWSER_DEBUGGER_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_
#pragma once
#include <map>
#include "base/basictypes.h"
#include "content/browser/debugger/devtools_agent_host.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
class RenderViewHost;
class RenderViewDevToolsAgentHost : public DevToolsAgentHost,
public NotificationObserver {
public:
static DevToolsAgentHost* FindFor(RenderViewHost*);
private:
RenderViewDevToolsAgentHost(RenderViewHost*);
virtual ~RenderViewDevToolsAgentHost();
// DevToolsAgentHost implementation.
virtual void SendMessageToAgent(IPC::Message* msg);
virtual void NotifyClientClosing();
virtual int GetRenderProcessId();
// Overridden from NotificationObserver:
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details);
RenderViewHost* render_view_host_;
NotificationRegistrar registrar_;
typedef std::map<RenderViewHost*, RenderViewDevToolsAgentHost*> Instances;
static Instances instances_;
DISALLOW_COPY_AND_ASSIGN(RenderViewDevToolsAgentHost);
};
#endif // CONTENT_BROWSER_DEBUGGER_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_
......@@ -79,6 +79,8 @@
'browser/content_browser_client.h',
'browser/cross_site_request_manager.cc',
'browser/cross_site_request_manager.h',
'browser/debugger/devtools_agent_host.cc',
'browser/debugger/devtools_agent_host.h',
'browser/debugger/devtools_client_host.cc',
'browser/debugger/devtools_client_host.h',
'browser/debugger/devtools_handler.cc',
......@@ -89,6 +91,8 @@
'browser/debugger/devtools_manager.h',
'browser/debugger/devtools_netlog_observer.cc',
'browser/debugger/devtools_netlog_observer.h',
'browser/debugger/render_view_devtools_agent_host.cc',
'browser/debugger/render_view_devtools_agent_host.h',
'browser/debugger/worker_devtools_manager_io.cc',
'browser/debugger/worker_devtools_manager_io.h',
'browser/debugger/worker_devtools_message_filter.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment