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