Home | History | Annotate | Download | only in devtools
      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 
     23 DevToolsAgentHostImpl::DevToolsAgentHostImpl()
     24     : close_listener_(NULL),
     25       id_(base::GenerateGUID()) {
     26   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     27   g_instances.Get()[id_] = this;
     28 }
     29 
     30 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
     31   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     32   g_instances.Get().erase(g_instances.Get().find(id_));
     33 }
     34 
     35 //static
     36 scoped_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
     47 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create(
     48     DevToolsExternalAgentProxyDelegate* delegate) {
     49   return new ForwardingAgentHost(delegate);
     50 }
     51 
     52 bool DevToolsAgentHostImpl::IsAttached() {
     53   return !!DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(this);
     54 }
     55 
     56 void DevToolsAgentHostImpl::InspectElement(int x, int y) {
     57 }
     58 
     59 std::string DevToolsAgentHostImpl::GetId() {
     60   return id_;
     61 }
     62 
     63 RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() {
     64   return NULL;
     65 }
     66 
     67 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {}
     68 
     69 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost* rvh) {}
     70 
     71 bool DevToolsAgentHostImpl::IsWorker() const {
     72   return false;
     73 }
     74 
     75 void 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