| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/devtools/devtools_agent_host_impl.h" | 5 #include "content/browser/devtools/devtools_agent_host_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "content/common/devtools_messages.h" | |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 16 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
| 18 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 17 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
| 19 } // namespace | 18 } // namespace |
| 20 | 19 |
| 21 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 20 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
| 22 : close_listener_(NULL), | 21 : close_listener_(NULL), |
| 23 id_(base::GenerateGUID()) { | 22 id_(base::GenerateGUID()) { |
| 24 g_instances.Get()[id_] = this; | 23 g_instances.Get()[id_] = this; |
| 25 } | 24 } |
| 26 | 25 |
| 27 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 26 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
| 28 g_instances.Get().erase(g_instances.Get().find(id_)); | 27 g_instances.Get().erase(g_instances.Get().find(id_)); |
| 29 } | 28 } |
| 30 | 29 |
| 31 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 30 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
| 32 const std::string& id) { | 31 const std::string& id) { |
| 33 if (g_instances == NULL) | 32 if (g_instances == NULL) |
| 34 return NULL; | 33 return NULL; |
| 35 Instances::iterator it = g_instances.Get().find(id); | 34 Instances::iterator it = g_instances.Get().find(id); |
| 36 if (it == g_instances.Get().end()) | 35 if (it == g_instances.Get().end()) |
| 37 return NULL; | 36 return NULL; |
| 38 return it->second; | 37 return it->second; |
| 39 } | 38 } |
| 40 | 39 |
| 41 void DevToolsAgentHostImpl::Attach() { | |
| 42 SendMessageToAgent(new DevToolsAgentMsg_Attach(MSG_ROUTING_NONE)); | |
| 43 NotifyClientAttaching(); | |
| 44 } | |
| 45 | |
| 46 void DevToolsAgentHostImpl::Reattach(const std::string& saved_agent_state) { | |
| 47 SendMessageToAgent(new DevToolsAgentMsg_Reattach( | |
| 48 MSG_ROUTING_NONE, | |
| 49 saved_agent_state)); | |
| 50 NotifyClientAttaching(); | |
| 51 } | |
| 52 | |
| 53 void DevToolsAgentHostImpl::Detach() { | |
| 54 SendMessageToAgent(new DevToolsAgentMsg_Detach(MSG_ROUTING_NONE)); | |
| 55 NotifyClientDetaching(); | |
| 56 } | |
| 57 | |
| 58 void DevToolsAgentHostImpl::DispatchOnInspectorBackend( | |
| 59 const std::string& message) { | |
| 60 SendMessageToAgent(new DevToolsAgentMsg_DispatchOnInspectorBackend( | |
| 61 MSG_ROUTING_NONE, message)); | |
| 62 } | |
| 63 | |
| 64 void DevToolsAgentHostImpl::InspectElement(int x, int y) { | 40 void DevToolsAgentHostImpl::InspectElement(int x, int y) { |
| 65 SendMessageToAgent(new DevToolsAgentMsg_InspectElement(MSG_ROUTING_NONE, | |
| 66 x, y)); | |
| 67 } | 41 } |
| 68 | 42 |
| 69 std::string DevToolsAgentHostImpl::GetId() { | 43 std::string DevToolsAgentHostImpl::GetId() { |
| 70 return id_; | 44 return id_; |
| 71 } | 45 } |
| 72 | 46 |
| 73 RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() { | 47 RenderViewHost* DevToolsAgentHostImpl::GetRenderViewHost() { |
| 74 return NULL; | 48 return NULL; |
| 75 } | 49 } |
| 76 | 50 |
| 77 void DevToolsAgentHostImpl::NotifyCloseListener() { | 51 void DevToolsAgentHostImpl::NotifyCloseListener() { |
| 78 if (close_listener_) { | 52 if (close_listener_) { |
| 79 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 53 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
| 80 close_listener_->AgentHostClosing(this); | 54 close_listener_->AgentHostClosing(this); |
| 81 close_listener_ = NULL; | 55 close_listener_ = NULL; |
| 82 } | 56 } |
| 83 } | 57 } |
| 84 | 58 |
| 85 } // namespace content | 59 } // namespace content |
| OLD | NEW |