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. 4 5 #include "content/browser/devtools/devtools_agent_host_impl.h" 6 7 #include <map> 8 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 14 namespace content { 15 16 namespace { 17 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; 18 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; 19 } // namespace 20 21 DevToolsAgentHostImpl::DevToolsAgentHostImpl() 22 : close_listener_(NULL), 23 id_(base::GenerateGUID()) { 24 g_instances.Get()[id_] = this; 25 } 26 27 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 28 g_instances.Get().erase(g_instances.Get().find(id_)); 29 } 30 31 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( 32 const std::string& id) { 33 if (g_instances == NULL) 34 return NULL; 35 Instances::iterator it = g_instances.Get().find(id); 36 if (it == g_instances.Get().end()) 37 return NULL; 38 return it->second; 39 } 40 41 bool DevToolsAgentHostImpl::IsAttached() { 42 return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this); 43 } 44 45 void DevToolsAgentHostImpl::InspectElement(int x, int y) { 46 } 47 48 std::string DevToolsAgentHostImpl::GetId() { 49 return id_; 50 } 51 52 RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() { 53 return NULL; 54 } 55 56 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {} 57 58 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost* rvh) {} 59 60 void DevToolsAgentHostImpl::NotifyCloseListener() { 61 if (close_listener_) { 62 scoped_refptr<DevToolsAgentHostImpl> protect(this); 63 close_listener_->AgentHostClosing(this); 64 close_listener_ = NULL; 65 } 66 } 67 68 } // namespace content 69