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/browser/devtools/devtools_manager_impl.h" | 12 #include "content/browser/devtools/devtools_manager_impl.h" |
| 13 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
13 #include "content/browser/devtools/forwarding_agent_host.h" | 14 #include "content/browser/devtools/forwarding_agent_host.h" |
| 15 #include "content/browser/devtools/worker_devtools_manager.h" |
14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/worker_service.h" |
15 | 18 |
16 namespace content { | 19 namespace content { |
17 | 20 |
18 namespace { | 21 namespace { |
| 22 |
19 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 23 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
20 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 24 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
| 25 |
| 26 void CreateSharedWorkers( |
| 27 const DevToolsAgentHost::ListCallback& callback, |
| 28 const std::vector<WorkerService::WorkerInfo>& workers) { |
| 29 DevToolsAgentHost::List result; |
| 30 for (std::vector<WorkerService::WorkerInfo>::const_iterator it = |
| 31 workers.begin(); it != workers.end(); ++it) { |
| 32 result.push_back(WorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 33 it->process_id, it->route_id)); |
| 34 } |
| 35 callback.Run(result); |
| 36 } |
| 37 |
| 38 void GetSharedWorkersInfoOnIO(const DevToolsAgentHost::ListCallback& callback) { |
| 39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 40 base::Bind(&CreateSharedWorkers, callback, |
| 41 WorkerService::GetInstance()->GetWorkers())); |
| 42 } |
| 43 |
21 } // namespace | 44 } // namespace |
22 | 45 |
| 46 void CollectAllHosts(const DevToolsAgentHost::ListCallback& callback, |
| 47 const DevToolsAgentHost::List& workers) { |
| 48 std::vector<RenderViewHost*> rvhs = |
| 49 DevToolsAgentHostImpl::GetValidRenderViewHosts(); |
| 50 DevToolsAgentHost::List result; |
| 51 for (std::vector<RenderViewHost*>::iterator it = rvhs.begin(); |
| 52 it != rvhs.end(); ++it) { |
| 53 result.push_back(DevToolsAgentHost::GetOrCreateFor(*it)); |
| 54 } |
| 55 result.insert(result.end(), workers.begin(), workers.end()); |
| 56 callback.Run(result); |
| 57 } |
| 58 |
| 59 // static |
| 60 void DevToolsAgentHost::GetOrCreateAllHosts( |
| 61 const DevToolsAgentHost::ListCallback& callback) { |
| 62 if (WorkerService::EmbeddedSharedWorkerEnabled()) { |
| 63 EmbeddedWorkerDevToolsManager::GetInstance()->GetOrCreateAllHosts( |
| 64 base::Bind(&CollectAllHosts, callback)); |
| 65 } else { |
| 66 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 67 base::Bind(&GetSharedWorkersInfoOnIO, |
| 68 base::Bind(&CollectAllHosts, callback))); |
| 69 } |
| 70 } |
| 71 |
23 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 72 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
24 : close_listener_(NULL), | 73 : close_listener_(NULL), |
25 id_(base::GenerateGUID()) { | 74 id_(base::GenerateGUID()) { |
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
27 g_instances.Get()[id_] = this; | 76 g_instances.Get()[id_] = this; |
28 } | 77 } |
29 | 78 |
30 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 79 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
32 g_instances.Get().erase(g_instances.Get().find(id_)); | 81 g_instances.Get().erase(g_instances.Get().find(id_)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 114 } |
66 | 115 |
67 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {} | 116 void DevToolsAgentHostImpl::DisconnectRenderViewHost() {} |
68 | 117 |
69 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost* rvh) {} | 118 void DevToolsAgentHostImpl::ConnectRenderViewHost(RenderViewHost* rvh) {} |
70 | 119 |
71 bool DevToolsAgentHostImpl::IsWorker() const { | 120 bool DevToolsAgentHostImpl::IsWorker() const { |
72 return false; | 121 return false; |
73 } | 122 } |
74 | 123 |
| 124 GURL DevToolsAgentHostImpl::GetURL() { |
| 125 return GURL(); |
| 126 } |
| 127 |
75 void DevToolsAgentHostImpl::NotifyCloseListener() { | 128 void DevToolsAgentHostImpl::NotifyCloseListener() { |
76 if (close_listener_) { | 129 if (close_listener_) { |
77 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 130 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
78 close_listener_->AgentHostClosing(this); | 131 close_listener_->AgentHostClosing(this); |
79 close_listener_ = NULL; | 132 close_listener_ = NULL; |
80 } | 133 } |
81 } | 134 } |
82 | 135 |
83 } // namespace content | 136 } // namespace content |
OLD | NEW |