| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "content/browser/devtools/devtools_manager_impl.h" | 13 #include "content/browser/devtools/devtools_manager_impl.h" |
| 14 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
| 14 #include "content/browser/devtools/forwarding_agent_host.h" | 15 #include "content/browser/devtools/forwarding_agent_host.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/devtools_manager_delegate.h" | 17 #include "content/public/browser/devtools_manager_delegate.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 22 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
| 22 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 23 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
| 23 | 24 |
| 24 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> | 25 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> |
| 25 AgentStateCallbacks; | 26 AgentStateCallbacks; |
| 26 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = | 27 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = |
| 27 LAZY_INSTANCE_INITIALIZER; | 28 LAZY_INSTANCE_INITIALIZER; |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 31 // static |
| 32 DevToolsAgentHost::List DevToolsAgentHost::GetOrCreateAll() { |
| 33 List result = EmbeddedWorkerDevToolsManager::GetInstance() |
| 34 ->GetOrCreateAllAgentHosts(); |
| 35 std::vector<WebContents*> wc_list = |
| 36 DevToolsAgentHostImpl::GetInspectableWebContents(); |
| 37 for (std::vector<WebContents*>::iterator it = wc_list.begin(); |
| 38 it != wc_list.end(); ++it) { |
| 39 result.push_back(GetOrCreateFor(*it)); |
| 40 } |
| 41 return result; |
| 42 } |
| 43 |
| 30 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 44 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
| 31 : id_(base::GenerateGUID()), | 45 : id_(base::GenerateGUID()), |
| 32 client_(NULL) { | 46 client_(NULL) { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 34 g_instances.Get()[id_] = this; | 48 g_instances.Get()[id_] = this; |
| 35 } | 49 } |
| 36 | 50 |
| 37 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 51 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 g_instances.Get().erase(g_instances.Get().find(id_)); | 53 g_instances.Get().erase(g_instances.Get().find(id_)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void DevToolsAgentHostImpl::DisconnectWebContents() { | 110 void DevToolsAgentHostImpl::DisconnectWebContents() { |
| 97 } | 111 } |
| 98 | 112 |
| 99 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { | 113 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { |
| 100 } | 114 } |
| 101 | 115 |
| 102 bool DevToolsAgentHostImpl::IsWorker() const { | 116 bool DevToolsAgentHostImpl::IsWorker() const { |
| 103 return false; | 117 return false; |
| 104 } | 118 } |
| 105 | 119 |
| 120 GURL DevToolsAgentHostImpl::GetURL() { |
| 121 return GURL(); |
| 122 } |
| 123 |
| 106 void DevToolsAgentHostImpl::HostClosed() { | 124 void DevToolsAgentHostImpl::HostClosed() { |
| 107 if (!client_) | 125 if (!client_) |
| 108 return; | 126 return; |
| 109 | 127 |
| 110 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 128 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
| 111 client_->AgentHostClosed(this, false); | 129 client_->AgentHostClosed(this, false); |
| 112 client_ = NULL; | 130 client_ = NULL; |
| 113 DevToolsManagerImpl::GetInstance()->OnClientDetached(); | 131 DevToolsManagerImpl::GetInstance()->OnClientDetached(); |
| 114 } | 132 } |
| 115 | 133 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 (*it)->Run(agent_host, attached); | 187 (*it)->Run(agent_host, attached); |
| 170 } | 188 } |
| 171 | 189 |
| 172 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | 190 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
| 173 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); | 191 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); |
| 174 if (manager->delegate()) | 192 if (manager->delegate()) |
| 175 manager->delegate()->Inspect(browser_context, this); | 193 manager->delegate()->Inspect(browser_context, this); |
| 176 } | 194 } |
| 177 | 195 |
| 178 } // namespace content | 196 } // namespace content |
| OLD | NEW |