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_)); |
40 } | 54 } |
41 | 55 |
42 //static | 56 // static |
43 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 57 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
44 const std::string& id) { | 58 const std::string& id) { |
45 if (g_instances == NULL) | 59 if (g_instances == NULL) |
46 return NULL; | 60 return NULL; |
47 Instances::iterator it = g_instances.Get().find(id); | 61 Instances::iterator it = g_instances.Get().find(id); |
48 if (it == g_instances.Get().end()) | 62 if (it == g_instances.Get().end()) |
49 return NULL; | 63 return NULL; |
50 return it->second; | 64 return it->second; |
51 } | 65 } |
52 | 66 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 (*it)->Run(agent_host, attached); | 187 (*it)->Run(agent_host, attached); |
174 } | 188 } |
175 | 189 |
176 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | 190 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
177 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); | 191 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); |
178 if (manager->delegate()) | 192 if (manager->delegate()) |
179 manager->delegate()->Inspect(browser_context, this); | 193 manager->delegate()->Inspect(browser_context, this); |
180 } | 194 } |
181 | 195 |
182 } // namespace content | 196 } // namespace content |
OLD | NEW |