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 { |
| 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. | |
| 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; |
|
yurys
2014/03/13 09:06:52
SharedWorkerDevtoolsAgentHost -> SharedWorkerDevTo
horo
2014/03/14 08:53:20
Done.
| |
| 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 // Called on the UI thread. | 33 static bool HasDevToolsAgentHostForWorker(int worker_process_id, |
| 36 static bool HasDevToolsAgentHostForWorker( | 34 int worker_route_id); |
| 37 int worker_process_id, | 35 |
| 38 int worker_route_id); | 36 void WorkerCreated(int worker_process_id, |
| 37 int worker_route_id, | |
| 38 const GURL& url, | |
| 39 const base::string16& name); | |
| 40 void WorkerDestroyed(int worker_process_id, int worker_route_id); | |
| 41 void WorkerContextStarted(int worker_process_id, int worker_route_id); | |
| 39 | 42 |
| 40 void ForwardToDevToolsClient(int worker_process_id, | 43 void ForwardToDevToolsClient(int worker_process_id, |
| 41 int worker_route_id, | 44 int worker_route_id, |
| 42 const std::string& message); | 45 const std::string& message); |
| 43 void SaveAgentRuntimeState(int worker_process_id, | 46 void SaveAgentRuntimeState(int worker_process_id, |
| 44 int worker_route_id, | 47 int worker_route_id, |
| 45 const std::string& state); | 48 const std::string& state); |
| 46 | 49 |
| 47 // Called on the IO thread. | 50 private: |
| 48 void WorkerCreated( | 51 friend struct DefaultSingletonTraits<SharedWorkerDevToolsManager>; |
| 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); | |
| 53 | 52 |
| 54 private: | 53 SharedWorkerDevToolsManager(); |
| 55 friend struct DefaultSingletonTraits<WorkerDevToolsManager>; | 54 virtual ~SharedWorkerDevToolsManager(); |
| 56 class DetachedClientHosts; | |
| 57 struct InspectedWorker; | |
| 58 typedef std::list<InspectedWorker> InspectedWorkersList; | |
| 59 | 55 |
| 60 WorkerDevToolsManager(); | 56 bool ConnectDevToolsAgentHostToWorker(const WorkerId& worker_id); |
| 61 virtual ~WorkerDevToolsManager(); | 57 void RemoveInspectedWorkerData(const WorkerId& worker_id); |
| 62 | 58 |
| 63 void RemoveInspectedWorkerData(const WorkerId& id); | 59 struct WorkerInfo; |
| 64 InspectedWorkersList::iterator FindInspectedWorker(int host_id, int route_id); | 60 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
| 65 | 61 |
| 66 void ConnectDevToolsAgentHostToWorker(int worker_process_id, | 62 WorkerInfoMap::iterator FindTerminatedWorker(const GURL& url, |
| 67 int worker_route_id); | 63 const base::string16& name); |
| 68 void ForwardToWorkerDevToolsAgent(int worker_process_host_id, | |
| 69 int worker_route_id, | |
| 70 const IPC::Message& message); | |
| 71 static void ForwardToDevToolsClientOnUIThread( | |
| 72 int worker_process_id, | |
| 73 int worker_route_id, | |
| 74 const std::string& message); | |
| 75 static void SaveAgentRuntimeStateOnUIThread( | |
| 76 int worker_process_id, | |
| 77 int worker_route_id, | |
| 78 const std::string& state); | |
| 79 static void NotifyConnectionFailedOnIOThread(int worker_process_id, | |
| 80 int worker_route_id); | |
| 81 static void NotifyConnectionFailedOnUIThread(int worker_process_id, | |
| 82 int worker_route_id); | |
| 83 static void SendResumeToWorker(const WorkerId& id); | |
| 84 | 64 |
| 85 InspectedWorkersList inspected_workers_; | 65 WorkerInfoMap uninspected_workers_; |
| 66 WorkerInfoMap inspected_workers_; | |
| 67 WorkerInfoMap terminated_workers_; | |
| 68 WorkerInfoMap paused_workers_; | |
| 86 | 69 |
| 87 struct TerminatedInspectedWorker; | 70 DISALLOW_COPY_AND_ASSIGN(SharedWorkerDevToolsManager); |
| 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 | |
| 96 // thread. | |
| 97 TerminatedInspectedWorkers terminated_workers_; | |
| 98 | |
| 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 | |
| 105 // worker. | |
| 106 // - Existing DevTools client was reattached to the new worker. | |
| 107 PausedWorkers paused_workers_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(WorkerDevToolsManager); | |
| 110 }; | 71 }; |
| 111 | 72 |
| 112 } // namespace content | 73 } // namespace content |
| 113 | 74 |
| 114 #endif // CONTENT_BROWSER_DEVTOOLS_WORKER_DEVTOOLS_MANAGER_H_ | 75 #endif // CONTENT_BROWSER_DEVTOOLS_SHARED_WORKER_DEVTOOLS_MANAGER_H_ |
| OLD | NEW |