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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_
12 #include "base/basictypes.h"
13 #include "base/memory/singleton.h"
14 #include "content/browser/worker_host/worker_process_host.h"
15 #include "content/common/content_export.h"
19 class DevToolsAgentHost;
21 // All methods are supposed to be called on the IO thread.
22 class WorkerDevToolsManager {
24 typedef std::pair<int, int> WorkerId;
25 class WorkerDevToolsAgentHost;
27 // Returns the WorkerDevToolsManager singleton.
28 static WorkerDevToolsManager* GetInstance();
30 // Called on the UI thread.
31 static DevToolsAgentHost* GetDevToolsAgentHostForWorker(
32 int worker_process_id,
35 // Called on the UI thread.
36 static bool HasDevToolsAgentHostForWorker(
37 int worker_process_id,
40 void ForwardToDevToolsClient(int worker_process_id,
42 const std::string& message);
43 void SaveAgentRuntimeState(int worker_process_id,
45 const std::string& state);
47 // Called on the IO thread.
49 WorkerProcessHost* process,
50 const WorkerProcessHost::WorkerInstance& instance);
51 void WorkerDestroyed(WorkerProcessHost* process, int worker_route_id);
52 void WorkerContextStarted(WorkerProcessHost* process, int worker_route_id);
55 friend struct DefaultSingletonTraits<WorkerDevToolsManager>;
56 class DetachedClientHosts;
57 struct InspectedWorker;
58 typedef std::list<InspectedWorker> InspectedWorkersList;
60 WorkerDevToolsManager();
61 virtual ~WorkerDevToolsManager();
63 void RemoveInspectedWorkerData(const WorkerId& id);
64 InspectedWorkersList::iterator FindInspectedWorker(int host_id, int route_id);
66 void ConnectDevToolsAgentHostToWorker(int worker_process_id,
68 void ForwardToWorkerDevToolsAgent(int worker_process_host_id,
70 const IPC::Message& message);
71 static void ForwardToDevToolsClientOnUIThread(
72 int worker_process_id,
74 const std::string& message);
75 static void SaveAgentRuntimeStateOnUIThread(
76 int worker_process_id,
78 const std::string& state);
79 static void NotifyConnectionFailedOnIOThread(int worker_process_id,
81 static void NotifyConnectionFailedOnUIThread(int worker_process_id,
83 static void SendResumeToWorker(const WorkerId& id);
85 InspectedWorkersList inspected_workers_;
87 struct TerminatedInspectedWorker;
88 typedef std::list<TerminatedInspectedWorker> TerminatedInspectedWorkers;
89 // List of terminated workers for which there may be a devtools client on
90 // the UI thread. Worker entry is added into this list when inspected worker
91 // is terminated and will be removed in one of two cases:
92 // - shared worker with the same URL and name is started(in wich case we will
93 // try to reattach existing DevTools client to the new worker).
94 // - DevTools client which was inspecting terminated worker is closed on the
95 // UI thread and and WorkerDevToolsManager is notified about that on the IO
97 TerminatedInspectedWorkers terminated_workers_;
99 typedef std::map<WorkerId, WorkerId> PausedWorkers;
100 // Map from old to new worker id for the inspected workers that have been
101 // terminated and started again in paused state. Worker data will be removed
102 // from this list in one of two cases:
103 // - DevTools client is closed on the UI thread, WorkerDevToolsManager was
104 // notified about that on the IO thread and sent "resume" message to the
106 // - Existing DevTools client was reattached to the new worker.
107 PausedWorkers paused_workers_;
109 DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManager);
112 } // namespace content
114 #endif // CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_