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/devtools_manager.h"
8 #include "content/browser/devtools/shared_worker_devtools_agent_host.h"
9 #include "content/browser/shared_worker/shared_worker_instance.h"
10 #include "content/public/browser/browser_thread.h"
15 SharedWorkerDevToolsManager
* SharedWorkerDevToolsManager::GetInstance() {
16 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
17 return Singleton
<SharedWorkerDevToolsManager
>::get();
20 bool SharedWorkerDevToolsManager::WorkerCreated(
21 int worker_process_id
,
23 const SharedWorkerInstance
& instance
) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
25 const WorkerId
id(worker_process_id
, worker_route_id
);
26 AgentHostMap::iterator it
= FindExistingWorkerAgentHost(instance
);
27 if (it
== workers().end()) {
28 workers()[id
] = new SharedWorkerDevToolsAgentHost(id
, instance
);
29 DevToolsManager::GetInstance()->AgentHostChanged(workers()[id
]);
32 WorkerRestarted(id
, it
);
36 SharedWorkerDevToolsManager::AgentHostMap::iterator
37 SharedWorkerDevToolsManager::FindExistingWorkerAgentHost(
38 const SharedWorkerInstance
& instance
) {
39 AgentHostMap::iterator it
= workers().begin();
40 for (; it
!= workers().end(); ++it
) {
41 if (static_cast<SharedWorkerDevToolsAgentHost
*>(
42 it
->second
)->Matches(instance
))
48 SharedWorkerDevToolsManager::SharedWorkerDevToolsManager() {
51 SharedWorkerDevToolsManager::~SharedWorkerDevToolsManager() {
54 void SharedWorkerDevToolsManager::ResetForTesting() {
58 } // namespace content