| Index: content/browser/devtools/devtools_agent_host_impl.cc
|
| diff --git a/content/browser/devtools/devtools_agent_host_impl.cc b/content/browser/devtools/devtools_agent_host_impl.cc
|
| index 1309eac12e157356ebe73352f9d731bc1c935470..9d4e707165c79fdac8713cf9ad15964809a19573 100644
|
| --- a/content/browser/devtools/devtools_agent_host_impl.cc
|
| +++ b/content/browser/devtools/devtools_agent_host_impl.cc
|
| @@ -5,7 +5,6 @@
|
| #include "content/browser/devtools/devtools_agent_host_impl.h"
|
|
|
| #include <map>
|
| -#include <vector>
|
|
|
| #include "base/basictypes.h"
|
| #include "base/guid.h"
|
| @@ -13,23 +12,17 @@
|
| #include "content/browser/devtools/devtools_manager_impl.h"
|
| #include "content/browser/devtools/forwarding_agent_host.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/devtools_manager_delegate.h"
|
|
|
| namespace content {
|
|
|
| namespace {
|
| typedef std::map<std::string, DevToolsAgentHostImpl*> Instances;
|
| base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| -typedef std::vector<const DevToolsAgentHost::AgentStateCallback*>
|
| - AgentStateCallbacks;
|
| -base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks =
|
| - LAZY_INSTANCE_INITIALIZER;
|
| } // namespace
|
|
|
| DevToolsAgentHostImpl::DevToolsAgentHostImpl()
|
| - : id_(base::GenerateGUID()),
|
| - client_(NULL) {
|
| + : close_listener_(NULL),
|
| + id_(base::GenerateGUID()) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| g_instances.Get()[id_] = this;
|
| }
|
| @@ -56,30 +49,8 @@
|
| return new ForwardingAgentHost(delegate);
|
| }
|
|
|
| -void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) {
|
| - scoped_refptr<DevToolsAgentHostImpl> protect(this);
|
| - if (client_) {
|
| - client_->AgentHostClosed(this, true);
|
| - Detach();
|
| - } else {
|
| - DevToolsManagerImpl::GetInstance()->OnClientAttached();
|
| - }
|
| - client_ = client;
|
| - Attach();
|
| -}
|
| -
|
| -void DevToolsAgentHostImpl::DetachClient() {
|
| - if (!client_)
|
| - return;
|
| -
|
| - scoped_refptr<DevToolsAgentHostImpl> protect(this);
|
| - client_ = NULL;
|
| - Detach();
|
| - DevToolsManagerImpl::GetInstance()->OnClientDetached();
|
| -}
|
| -
|
| bool DevToolsAgentHostImpl::IsAttached() {
|
| - return !!client_;
|
| + return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this);
|
| }
|
|
|
| void DevToolsAgentHostImpl::InspectElement(int x, int y) {
|
| @@ -103,76 +74,12 @@
|
| return false;
|
| }
|
|
|
| -void DevToolsAgentHostImpl::HostClosed() {
|
| - if (!client_)
|
| - return;
|
| -
|
| - scoped_refptr<DevToolsAgentHostImpl> protect(this);
|
| - client_->AgentHostClosed(this, false);
|
| - client_ = NULL;
|
| - DevToolsManagerImpl::GetInstance()->OnClientDetached();
|
| -}
|
| -
|
| -void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) {
|
| - if (!client_)
|
| - return;
|
| - client_->DispatchProtocolMessage(this, message);
|
| -}
|
| -
|
| -// static
|
| -void DevToolsAgentHost::DetachAllClients() {
|
| - if (g_instances == NULL)
|
| - return;
|
| -
|
| - // Make a copy, since detaching may lead to agent destruction, which
|
| - // removes it from the instances.
|
| - Instances copy = g_instances.Get();
|
| - for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) {
|
| - DevToolsAgentHostImpl* agent_host = it->second;
|
| - if (agent_host->client_) {
|
| - scoped_refptr<DevToolsAgentHostImpl> protect(agent_host);
|
| - agent_host->client_->AgentHostClosed(agent_host, true);
|
| - agent_host->client_ = NULL;
|
| - agent_host->Detach();
|
| - DevToolsManagerImpl::GetInstance()->OnClientDetached();
|
| - }
|
| +void DevToolsAgentHostImpl::NotifyCloseListener() {
|
| + if (close_listener_) {
|
| + scoped_refptr<DevToolsAgentHostImpl> protect(this);
|
| + close_listener_->AgentHostClosing(this);
|
| + close_listener_ = NULL;
|
| }
|
| }
|
|
|
| -// static
|
| -void DevToolsAgentHost::AddAgentStateCallback(
|
| - const AgentStateCallback& callback) {
|
| - g_callbacks.Get().push_back(&callback);
|
| -}
|
| -
|
| -// static
|
| -void DevToolsAgentHost::RemoveAgentStateCallback(
|
| - const AgentStateCallback& callback) {
|
| - if (g_callbacks == NULL)
|
| - return;
|
| -
|
| - AgentStateCallbacks* callbacks_ = g_callbacks.Pointer();
|
| - AgentStateCallbacks::iterator it =
|
| - std::find(callbacks_->begin(), callbacks_->end(), &callback);
|
| - DCHECK(it != callbacks_->end());
|
| - callbacks_->erase(it);
|
| -}
|
| -
|
| -// static
|
| -void DevToolsAgentHostImpl::NotifyCallbacks(
|
| - DevToolsAgentHostImpl* agent_host, bool attached) {
|
| - AgentStateCallbacks copy(g_callbacks.Get());
|
| - DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance();
|
| - if (manager->delegate())
|
| - manager->delegate()->DevToolsAgentStateChanged(agent_host, attached);
|
| - for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it)
|
| - (*it)->Run(agent_host, attached);
|
| -}
|
| -
|
| -void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) {
|
| - DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance();
|
| - if (manager->delegate())
|
| - manager->delegate()->Inspect(browser_context, this);
|
| -}
|
| -
|
| } // namespace content
|
|
|