1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/devtools/devtools_agent_host_impl.h"
9 #include "base/basictypes.h"
10 #include "base/guid.h"
11 #include "base/lazy_instance.h"
12 #include "content/browser/devtools/devtools_manager_impl.h"
13 #include "content/browser/devtools/forwarding_agent_host.h"
14 #include "content/public/browser/browser_thread.h"
19 typedef std::map
<std::string
, DevToolsAgentHostImpl
*> Instances
;
20 base::LazyInstance
<Instances
>::Leaky g_instances
= LAZY_INSTANCE_INITIALIZER
;
23 DevToolsAgentHostImpl::DevToolsAgentHostImpl()
24 : close_listener_(NULL
),
25 id_(base::GenerateGUID()) {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
27 g_instances
.Get()[id_
] = this;
30 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
32 g_instances
.Get().erase(g_instances
.Get().find(id_
));
36 scoped_refptr
<DevToolsAgentHost
> DevToolsAgentHost::GetForId(
37 const std::string
& id
) {
38 if (g_instances
== NULL
)
40 Instances::iterator it
= g_instances
.Get().find(id
);
41 if (it
== g_instances
.Get().end())
47 scoped_refptr
<DevToolsAgentHost
> DevToolsAgentHost::Create(
48 DevToolsExternalAgentProxyDelegate
* delegate
) {
49 return new ForwardingAgentHost(delegate
);
52 bool DevToolsAgentHostImpl::IsAttached() {
53 return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this);
56 void DevToolsAgentHostImpl::InspectElement(int x
, int y
) {
59 std::string
DevToolsAgentHostImpl::GetId() {
63 RenderViewHost
* DevToolsAgentHostImpl::GetRenderViewHost() {
67 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {}
69 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost
* rvh
) {}
71 bool DevToolsAgentHostImpl::IsWorker() const {
75 void DevToolsAgentHostImpl::NotifyCloseListener() {
76 if (close_listener_
) {
77 scoped_refptr
<DevToolsAgentHostImpl
> protect(this);
78 close_listener_
->AgentHostClosing(this);
79 close_listener_
= NULL
;
83 } // namespace content