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 |
| 21 const char DevToolsAgentHost::kTypeWebContents[] = "web_contents"; |
| 22 const char DevToolsAgentHost::kTypeWorker[] = "worker"; |
| 23 const char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker"; |
| 24 |
20 namespace { | 25 namespace { |
21 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 26 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
22 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 27 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
23 | 28 |
24 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> | 29 typedef std::vector<const DevToolsAgentHost::AgentStateCallback*> |
25 AgentStateCallbacks; | 30 AgentStateCallbacks; |
26 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = | 31 base::LazyInstance<AgentStateCallbacks>::Leaky g_callbacks = |
27 LAZY_INSTANCE_INITIALIZER; | 32 LAZY_INSTANCE_INITIALIZER; |
28 } // namespace | 33 } // namespace |
29 | 34 |
| 35 // static |
| 36 DevToolsAgentHost::List DevToolsAgentHost::GetOrCreateAll() { |
| 37 List result = EmbeddedWorkerDevToolsManager::GetInstance() |
| 38 ->GetOrCreateAllAgentHosts(); |
| 39 std::vector<WebContents*> wc_list = |
| 40 DevToolsAgentHostImpl::GetInspectableWebContents(); |
| 41 for (std::vector<WebContents*>::iterator it = wc_list.begin(); |
| 42 it != wc_list.end(); ++it) { |
| 43 result.push_back(GetOrCreateFor(*it)); |
| 44 } |
| 45 return result; |
| 46 } |
| 47 |
30 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 48 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
31 : id_(base::GenerateGUID()), | 49 : id_(base::GenerateGUID()), |
32 client_(NULL) { | 50 client_(NULL) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 g_instances.Get()[id_] = this; | 52 g_instances.Get()[id_] = this; |
35 } | 53 } |
36 | 54 |
37 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 55 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
39 g_instances.Get().erase(g_instances.Get().find(id_)); | 57 g_instances.Get().erase(g_instances.Get().find(id_)); |
40 } | 58 } |
41 | 59 |
42 //static | 60 // static |
43 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 61 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
44 const std::string& id) { | 62 const std::string& id) { |
45 if (g_instances == NULL) | 63 if (g_instances == NULL) |
46 return NULL; | 64 return NULL; |
47 Instances::iterator it = g_instances.Get().find(id); | 65 Instances::iterator it = g_instances.Get().find(id); |
48 if (it == g_instances.Get().end()) | 66 if (it == g_instances.Get().end()) |
49 return NULL; | 67 return NULL; |
50 return it->second; | 68 return it->second; |
51 } | 69 } |
52 | 70 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 (*it)->Run(agent_host, attached); | 191 (*it)->Run(agent_host, attached); |
174 } | 192 } |
175 | 193 |
176 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { | 194 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { |
177 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); | 195 DevToolsManagerImpl* manager = DevToolsManagerImpl::GetInstance(); |
178 if (manager->delegate()) | 196 if (manager->delegate()) |
179 manager->delegate()->Inspect(browser_context, this); | 197 manager->delegate()->Inspect(browser_context, this); |
180 } | 198 } |
181 | 199 |
182 } // namespace content | 200 } // namespace content |
OLD | NEW |