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/public/browser/browser_thread.h"
18 typedef std::map
<std::string
, DevToolsAgentHostImpl
*> Instances
;
19 base::LazyInstance
<Instances
>::Leaky g_instances
= LAZY_INSTANCE_INITIALIZER
;
22 DevToolsAgentHostImpl::DevToolsAgentHostImpl()
23 : close_listener_(NULL
),
24 id_(base::GenerateGUID()) {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
26 g_instances
.Get()[id_
] = this;
29 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
31 g_instances
.Get().erase(g_instances
.Get().find(id_
));
34 scoped_refptr
<DevToolsAgentHost
> DevToolsAgentHost::GetForId(
35 const std::string
& id
) {
36 if (g_instances
== NULL
)
38 Instances::iterator it
= g_instances
.Get().find(id
);
39 if (it
== g_instances
.Get().end())
44 bool DevToolsAgentHostImpl::IsAttached() {
45 return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this);
48 void DevToolsAgentHostImpl::InspectElement(int x
, int y
) {
51 std::string
DevToolsAgentHostImpl::GetId() {
55 RenderViewHost
* DevToolsAgentHostImpl::GetRenderViewHost() {
59 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {}
61 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost
* rvh
) {}
63 void DevToolsAgentHostImpl::NotifyCloseListener() {
64 if (close_listener_
) {
65 scoped_refptr
<DevToolsAgentHostImpl
> protect(this);
66 close_listener_
->AgentHostClosing(this);
67 close_listener_
= NULL
;
71 } // namespace content