OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
10 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
11 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
14 #include "content/browser/shared_worker/shared_worker_instance.h" | 17 #include "content/browser/shared_worker/shared_worker_instance.h" |
15 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/public/browser/devtools_agent_host.h" |
16 | 20 |
17 namespace content { | 21 namespace content { |
18 | 22 |
19 class DevToolsAgentHost; | |
20 class ServiceWorkerContextCore; | 23 class ServiceWorkerContextCore; |
21 | 24 |
22 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when | 25 // EmbeddedWorkerDevToolsManager is used instead of WorkerDevToolsManager when |
23 // "enable-embedded-shared-worker" flag is set. | 26 // "enable-embedded-shared-worker" flag is set. |
24 // This class lives on UI thread. | 27 // This class lives on UI thread. |
25 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { | 28 class CONTENT_EXPORT EmbeddedWorkerDevToolsManager { |
26 public: | 29 public: |
27 typedef std::pair<int, int> WorkerId; | 30 typedef std::pair<int, int> WorkerId; |
28 class EmbeddedWorkerDevToolsAgentHost; | |
29 | 31 |
30 class ServiceWorkerIdentifier { | 32 class ServiceWorkerIdentifier { |
31 public: | 33 public: |
32 ServiceWorkerIdentifier( | 34 ServiceWorkerIdentifier( |
33 const ServiceWorkerContextCore* const service_worker_context, | 35 const ServiceWorkerContextCore* service_worker_context, |
| 36 base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak, |
34 int64 service_worker_version_id); | 37 int64 service_worker_version_id); |
35 explicit ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); | 38 ServiceWorkerIdentifier(const ServiceWorkerIdentifier& other); |
36 ~ServiceWorkerIdentifier() {} | 39 ~ServiceWorkerIdentifier(); |
37 | 40 |
38 bool Matches(const ServiceWorkerIdentifier& other) const; | 41 bool Matches(const ServiceWorkerIdentifier& other) const; |
39 | 42 |
40 private: | 43 private: |
| 44 friend class EmbeddedWorkerDevToolsManager; |
41 const ServiceWorkerContextCore* const service_worker_context_; | 45 const ServiceWorkerContextCore* const service_worker_context_; |
| 46 const base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak_; |
42 const int64 service_worker_version_id_; | 47 const int64 service_worker_version_id_; |
43 }; | 48 }; |
44 | 49 |
45 // Returns the EmbeddedWorkerDevToolsManager singleton. | 50 // Returns the EmbeddedWorkerDevToolsManager singleton. |
46 static EmbeddedWorkerDevToolsManager* GetInstance(); | 51 static EmbeddedWorkerDevToolsManager* GetInstance(); |
47 | 52 |
48 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 53 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
49 int worker_route_id); | 54 int worker_route_id); |
50 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( | 55 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( |
51 const ServiceWorkerIdentifier& service_worker_id); | 56 const ServiceWorkerIdentifier& service_worker_id); |
52 | 57 |
| 58 void GetOrCreateAllHosts(const DevToolsAgentHost::ListCallback& callback); |
| 59 |
53 // Returns true when the worker must be paused on start because a DevTool | 60 // Returns true when the worker must be paused on start because a DevTool |
54 // window for the same former SharedWorkerInstance is still opened. | 61 // window for the same former SharedWorkerInstance is still opened. |
55 bool SharedWorkerCreated(int worker_process_id, | 62 bool SharedWorkerCreated(int worker_process_id, |
56 int worker_route_id, | 63 int worker_route_id, |
57 const SharedWorkerInstance& instance); | 64 const SharedWorkerInstance& instance); |
58 // Returns true when the worker must be paused on start because a DevTool | 65 // Returns true when the worker must be paused on start because a DevTool |
59 // window for the same former ServiceWorkerIdentifier is still opened or | 66 // window for the same former ServiceWorkerIdentifier is still opened or |
60 // debug-on-start is enabled in chrome://serviceworker-internals. | 67 // debug-on-start is enabled in chrome://serviceworker-internals. |
61 bool ServiceWorkerCreated(int worker_process_id, | 68 bool ServiceWorkerCreated(int worker_process_id, |
62 int worker_route_id, | 69 int worker_route_id, |
(...skipping 15 matching lines...) Expand all Loading... |
78 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); | 85 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
79 | 86 |
80 enum WorkerState { | 87 enum WorkerState { |
81 WORKER_UNINSPECTED, | 88 WORKER_UNINSPECTED, |
82 WORKER_INSPECTED, | 89 WORKER_INSPECTED, |
83 WORKER_TERMINATED, | 90 WORKER_TERMINATED, |
84 WORKER_PAUSED_FOR_DEBUG_ON_START, | 91 WORKER_PAUSED_FOR_DEBUG_ON_START, |
85 WORKER_PAUSED_FOR_REATTACH, | 92 WORKER_PAUSED_FOR_REATTACH, |
86 }; | 93 }; |
87 | 94 |
| 95 class EmbeddedWorkerDevToolsAgentHost; |
| 96 |
88 class WorkerInfo { | 97 class WorkerInfo { |
89 public: | 98 public: |
90 // Creates WorkerInfo for SharedWorker. | 99 // Creates WorkerInfo for SharedWorker. |
91 explicit WorkerInfo(const SharedWorkerInstance& instance); | 100 explicit WorkerInfo(const SharedWorkerInstance& instance); |
92 // Creates WorkerInfo for ServiceWorker. | 101 // Creates WorkerInfo for ServiceWorker. |
93 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id); | 102 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id); |
94 ~WorkerInfo(); | 103 ~WorkerInfo(); |
95 | 104 |
96 WorkerState state() { return state_; } | 105 WorkerState state() { return state_; } |
97 void set_state(WorkerState new_state) { state_ = new_state; } | 106 void set_state(WorkerState new_state) { state_ = new_state; } |
98 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 107 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
99 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { | 108 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
100 agent_host_ = agent_host; | 109 agent_host_ = agent_host; |
101 } | 110 } |
102 bool Matches(const SharedWorkerInstance& other); | 111 bool Matches(const SharedWorkerInstance& other); |
103 bool Matches(const ServiceWorkerIdentifier& other); | 112 bool Matches(const ServiceWorkerIdentifier& other); |
| 113 ServiceWorkerIdentifier* service_worker_id() { |
| 114 return service_worker_id_.get(); |
| 115 } |
104 | 116 |
105 private: | 117 private: |
106 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; | 118 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; |
107 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; | 119 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; |
108 WorkerState state_; | 120 WorkerState state_; |
109 EmbeddedWorkerDevToolsAgentHost* agent_host_; | 121 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
110 }; | 122 }; |
111 | 123 |
112 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 124 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
113 | 125 |
114 EmbeddedWorkerDevToolsManager(); | 126 EmbeddedWorkerDevToolsManager(); |
115 virtual ~EmbeddedWorkerDevToolsManager(); | 127 virtual ~EmbeddedWorkerDevToolsManager(); |
116 | 128 |
117 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); | 129 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
118 | 130 |
119 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( | 131 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
120 const SharedWorkerInstance& instance); | 132 const SharedWorkerInstance& instance); |
121 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( | 133 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( |
122 const ServiceWorkerIdentifier& service_worker_id); | 134 const ServiceWorkerIdentifier& service_worker_id); |
123 | 135 |
124 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); | 136 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); |
125 | 137 |
| 138 DevToolsAgentHost* GetOrCreateAgentHost(int worker_process_id, |
| 139 int worker_route_id, |
| 140 const GURL& url); |
| 141 static void GetServiceWorkerUrlsOnIO( |
| 142 const std::map<WorkerId, ServiceWorkerIdentifier>& ids, |
| 143 const DevToolsAgentHost::ListCallback& callback); |
| 144 static void CreateAgentHosts(const std::map<WorkerId, GURL> url_map, |
| 145 const DevToolsAgentHost::ListCallback& callback); |
| 146 |
126 // Resets to its initial state as if newly created. | 147 // Resets to its initial state as if newly created. |
127 void ResetForTesting(); | 148 void ResetForTesting(); |
128 | 149 |
129 WorkerInfoMap workers_; | 150 WorkerInfoMap workers_; |
130 | 151 |
131 bool debug_service_worker_on_start_; | 152 bool debug_service_worker_on_start_; |
132 | 153 |
133 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); | 154 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
134 }; | 155 }; |
135 | 156 |
136 } // namespace content | 157 } // namespace content |
137 | 158 |
138 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 159 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |