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 #include "content/browser/devtools/forwarding_agent_host.h" 14 #include "content/public/browser/browser_thread.h" 15 16 namespace content { 17 18 namespace { 19 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; 20 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; 21 } // namespace 22 DevToolsAgentHostImpl()23DevToolsAgentHostImpl::DevToolsAgentHostImpl() 24 : close_listener_(NULL), 25 id_(base::GenerateGUID()) { 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 27 g_instances.Get()[id_] = this; 28 } 29 ~DevToolsAgentHostImpl()30DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 32 g_instances.Get().erase(g_instances.Get().find(id_)); 33 } 34 35 //static GetForId(const std::string & id)36scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( 37 const std::string& id) { 38 if (g_instances == NULL) 39 return NULL; 40 Instances::iterator it = g_instances.Get().find(id); 41 if (it == g_instances.Get().end()) 42 return NULL; 43 return it->second; 44 } 45 46 //static Create(DevToolsExternalAgentProxyDelegate * delegate)47scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( 48 DevToolsExternalAgentProxyDelegate* delegate) { 49 return new ForwardingAgentHost(delegate); 50 } 51 IsAttached()52bool DevToolsAgentHostImpl::IsAttached() { 53 return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this); 54 } 55 InspectElement(int x,int y)56void DevToolsAgentHostImpl::InspectElement(int x, int y) { 57 } 58 GetId()59std::string DevToolsAgentHostImpl::GetId() { 60 return id_; 61 } 62 GetRenderViewHost()63RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() { 64 return NULL; 65 } 66 DisconnectRenderViewHost()67void DevToolsAgentHostImpl::DisconnectRenderViewHost() {} 68 ConnectRenderViewHost(RenderViewHost * rvh)69void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost* rvh) {} 70 IsWorker() const71bool DevToolsAgentHostImpl::IsWorker() const { 72 return false; 73 } 74 NotifyCloseListener()75void DevToolsAgentHostImpl::NotifyCloseListener() { 76 if (close_listener_) { 77 scoped_refptr<DevToolsAgentHostImpl> protect(this); 78 close_listener_->AgentHostClosing(this); 79 close_listener_ = NULL; 80 } 81 } 82 83 } // namespace content 84