1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/devtools/shared_worker_devtools_manager.h"
7 #include "content/browser/devtools/shared_worker_devtools_agent_host.h"
8 #include "content/browser/shared_worker/shared_worker_instance.h"
9 #include "content/public/browser/browser_thread.h"
14 SharedWorkerDevToolsManager
* SharedWorkerDevToolsManager::GetInstance() {
15 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
16 return Singleton
<SharedWorkerDevToolsManager
>::get();
19 DevToolsAgentHostImpl
*
20 SharedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
21 int worker_process_id
,
22 int worker_route_id
) {
23 AgentHostMap::iterator it
= workers_
.find(
24 WorkerId(worker_process_id
, worker_route_id
));
25 return it
== workers_
.end() ? NULL
: it
->second
;
28 void SharedWorkerDevToolsManager::AddAllAgentHosts(
29 SharedWorkerDevToolsAgentHost::List
* result
) {
30 for (auto& worker
: workers_
) {
31 if (!worker
.second
->IsTerminated())
32 result
->push_back(worker
.second
);
36 bool SharedWorkerDevToolsManager::WorkerCreated(
37 int worker_process_id
,
39 const SharedWorkerInstance
& instance
) {
40 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
41 const WorkerId
id(worker_process_id
, worker_route_id
);
42 AgentHostMap::iterator it
=
43 FindExistingWorkerAgentHost(instance
);
44 if (it
== workers_
.end()) {
45 workers_
[id
] = new SharedWorkerDevToolsAgentHost(id
, instance
);
50 SharedWorkerDevToolsAgentHost
* agent_host
= it
->second
;
51 agent_host
->WorkerRestarted(id
);
53 workers_
[id
] = agent_host
;
57 void SharedWorkerDevToolsManager::WorkerReadyForInspection(
58 int worker_process_id
,
59 int worker_route_id
) {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
61 const WorkerId
id(worker_process_id
, worker_route_id
);
62 AgentHostMap::iterator it
= workers_
.find(id
);
63 DCHECK(it
!= workers_
.end());
64 it
->second
->WorkerReadyForInspection();
67 void SharedWorkerDevToolsManager::WorkerDestroyed(
68 int worker_process_id
,
69 int worker_route_id
) {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
71 const WorkerId
id(worker_process_id
, worker_route_id
);
72 AgentHostMap::iterator it
= workers_
.find(id
);
73 DCHECK(it
!= workers_
.end());
74 scoped_refptr
<SharedWorkerDevToolsAgentHost
> agent_host(it
->second
);
75 agent_host
->WorkerDestroyed();
78 void SharedWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id
) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
82 SharedWorkerDevToolsManager::SharedWorkerDevToolsManager() {
85 SharedWorkerDevToolsManager::~SharedWorkerDevToolsManager() {
88 SharedWorkerDevToolsManager::AgentHostMap::iterator
89 SharedWorkerDevToolsManager::FindExistingWorkerAgentHost(
90 const SharedWorkerInstance
& instance
) {
91 AgentHostMap::iterator it
= workers_
.begin();
92 for (; it
!= workers_
.end(); ++it
) {
93 if (it
->second
->Matches(instance
))
99 void SharedWorkerDevToolsManager::ResetForTesting() {
104 } // namespace content