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