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 #ifndef CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
7 | |
8 #include <list> | |
9 #include <map> | |
10 #include <string> | |
11 | 7 |
12 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/containers/scoped_ptr_hash_map.h" | |
10 #include "base/memory/scoped_vector.h" | |
13 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
14 #include "content/browser/worker_host/worker_process_host.h" | 12 #include "base/strings/string16.h" |
15 #include "content/common/content_export.h" | 13 |
14 class GURL; | |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | |
19 class DevToolsAgentHost; | 17 class DevToolsAgentHost; |
20 | 18 |
21 // All methods are supposed to be called on the IO thread. | 19 // SharedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
22 class WorkerDevToolsManager { | 20 // "enable-embedded-shared-worker" flag is set. |
21 // This class lives in UI thread. | |
kinuko
2014/03/24 12:24:02
nit: in -> on
horo
2014/03/25 06:28:17
Done.
| |
22 class SharedWorkerDevToolsManager { | |
23 public: | 23 public: |
24 typedef std::pair<int, int> WorkerId; | 24 typedef std::pair<int, int> WorkerId; |
25 class WorkerDevToolsAgentHost; | 25 class SharedWorkerDevToolsAgentHost; |
26 | 26 |
27 // Returns the WorkerDevToolsManager singleton. | 27 // Returns the SharedWorkerDevToolsManager singleton. |
28 static WorkerDevToolsManager* GetInstance(); | 28 static SharedWorkerDevToolsManager* GetInstance(); |
29 | 29 |
30 // Called on the UI thread. | 30 static DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
31 static DevToolsAgentHost* GetDevToolsAgentHostForWorker( | 31 int worker_route_id); |
32 int worker_process_id, | |
33 int worker_route_id); | |
34 | 32 |
35 void ForwardToDevToolsClient(int worker_process_id, | 33 static bool HasDevToolsAgentHostForWorker(int worker_process_id, |
36 int worker_route_id, | 34 int worker_route_id); |
37 const std::string& message); | |
38 void SaveAgentRuntimeState(int worker_process_id, | |
39 int worker_route_id, | |
40 const std::string& state); | |
41 | 35 |
42 // Called on the IO thread. | 36 void WorkerCreated(int worker_process_id, |
43 void WorkerCreated( | 37 int worker_route_id, |
44 WorkerProcessHost* process, | 38 const GURL& url, |
45 const WorkerProcessHost::WorkerInstance& instance); | 39 const base::string16& name); |
46 void WorkerDestroyed(WorkerProcessHost* process, int worker_route_id); | 40 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
47 void WorkerContextStarted(WorkerProcessHost* process, int worker_route_id); | 41 void WorkerContextStarted(int worker_process_id, int worker_route_id); |
48 | 42 |
49 private: | 43 private: |
50 friend struct DefaultSingletonTraits<WorkerDevToolsManager>; | 44 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>; |
51 class DetachedClientHosts; | |
52 struct InspectedWorker; | |
53 typedef std::list<InspectedWorker> InspectedWorkersList; | |
54 | 45 |
55 WorkerDevToolsManager(); | 46 SharedWorkerDevToolsManager(); |
56 virtual ~WorkerDevToolsManager(); | 47 virtual ~SharedWorkerDevToolsManager(); |
57 | 48 |
58 void RemoveInspectedWorkerData(const WorkerId& id); | 49 bool ConnectDevToolsAgentHostToWorker(const WorkerId& worker_id); |
59 InspectedWorkersList::iterator FindInspectedWorker(int host_id, int route_id); | 50 void RemoveInspectedWorkerData(const WorkerId& worker_id); |
60 | 51 |
61 void ConnectDevToolsAgentHostToWorker(int worker_process_id, | 52 struct WorkerInfo; |
62 int worker_route_id); | 53 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
63 void ForwardToWorkerDevToolsAgent(int worker_process_host_id, | |
64 int worker_route_id, | |
65 const IPC::Message& message); | |
66 static void ForwardToDevToolsClientOnUIThread( | |
67 int worker_process_id, | |
68 int worker_route_id, | |
69 const std::string& message); | |
70 static void SaveAgentRuntimeStateOnUIThread( | |
71 int worker_process_id, | |
72 int worker_route_id, | |
73 const std::string& state); | |
74 static void NotifyConnectionFailedOnIOThread(int worker_process_id, | |
75 int worker_route_id); | |
76 static void NotifyConnectionFailedOnUIThread(int worker_process_id, | |
77 int worker_route_id); | |
78 static void SendResumeToWorker(const WorkerId& id); | |
79 | 54 |
80 InspectedWorkersList inspected_workers_; | 55 WorkerInfoMap::iterator FindTerminatedWorker(const GURL& url, |
56 const base::string16& name); | |
81 | 57 |
82 struct TerminatedInspectedWorker; | 58 WorkerInfoMap uninspected_workers_; |
83 typedef std::list<TerminatedInspectedWorker> TerminatedInspectedWorkers; | 59 WorkerInfoMap inspected_workers_; |
84 // List of terminated workers for which there may be a devtools client on | 60 |
85 // the UI thread. Worker entry is added into this list when inspected worker | 61 // Map of terminated workers for which there may be a devtools client. Worker |
86 // is terminated and will be removed in one of two cases: | 62 // entry is added into this map when inspected worker is terminated and will |
87 // - shared worker with the same URL and name is started(in wich case we will | 63 // be removed in one of two cases: |
64 // - shared worker with the same URL and name is started (in wich case we will | |
88 // try to reattach existing DevTools client to the new worker). | 65 // try to reattach existing DevTools client to the new worker). |
89 // - DevTools client which was inspecting terminated worker is closed on the | 66 // - DevTools client which was inspecting terminated worker is closed and |
90 // UI thread and and WorkerDevToolsManager is notified about that on the IO | 67 // WorkerDevToolsManager is notified about that. |
91 // thread. | 68 WorkerInfoMap terminated_workers_; |
92 TerminatedInspectedWorkers terminated_workers_; | |
93 | 69 |
94 typedef std::map<WorkerId, WorkerId> PausedWorkers; | 70 // Map of the inspected workers that have been terminated and started again in |
95 // Map from old to new worker id for the inspected workers that have been | 71 // paused state. WorkerId of WorkerInfo in this map is stil the old worker id. |
96 // terminated and started again in paused state. Worker data will be removed | 72 // Worker data will be removed from this list in one of two cases: |
97 // from this list in one of two cases: | 73 // - DevTools client is closed and WorkerDevToolsManager was notified about |
98 // - DevTools client is closed on the UI thread, WorkerDevToolsManager was | 74 // that sent "resume" message to the worker. |
99 // notified about that on the IO thread and sent "resume" message to the | |
100 // worker. | |
101 // - Existing DevTools client was reattached to the new worker. | 75 // - Existing DevTools client was reattached to the new worker. |
102 PausedWorkers paused_workers_; | 76 WorkerInfoMap paused_workers_; |
103 | 77 |
104 DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManager); | 78 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager); |
105 }; | 79 }; |
106 | 80 |
107 } // namespace content | 81 } // namespace content |
108 | 82 |
109 #endif // CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_ | 83 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |