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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 }; | 43 }; |
44 | 44 |
45 // Returns the EmbeddedWorkerDevToolsManager singleton. | 45 // Returns the EmbeddedWorkerDevToolsManager singleton. |
46 static EmbeddedWorkerDevToolsManager* GetInstance(); | 46 static EmbeddedWorkerDevToolsManager* GetInstance(); |
47 | 47 |
48 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, | 48 DevToolsAgentHost* GetDevToolsAgentHostForWorker(int worker_process_id, |
49 int worker_route_id); | 49 int worker_route_id); |
50 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( | 50 DevToolsAgentHost* GetDevToolsAgentHostForServiceWorker( |
51 const ServiceWorkerIdentifier& service_worker_id); | 51 const ServiceWorkerIdentifier& service_worker_id); |
52 | 52 |
53 // Returns true when the worker must be paused on start. | 53 // Returns true when the worker must be paused on start because a DevTool |
| 54 // window for the same former SharedWorkerInstance is still opened. |
54 bool SharedWorkerCreated(int worker_process_id, | 55 bool SharedWorkerCreated(int worker_process_id, |
55 int worker_route_id, | 56 int worker_route_id, |
56 const SharedWorkerInstance& instance); | 57 const SharedWorkerInstance& instance); |
57 // Returns true when the worker must be paused on start. | 58 // Returns true when the worker must be paused on start because a DevTool |
| 59 // window for the same former ServiceWorkerIdentifier is still opened or |
| 60 // debug-on-start is enabled in chrome://serviceworker-internals. |
58 bool ServiceWorkerCreated(int worker_process_id, | 61 bool ServiceWorkerCreated(int worker_process_id, |
59 int worker_route_id, | 62 int worker_route_id, |
60 const ServiceWorkerIdentifier& service_worker_id); | 63 const ServiceWorkerIdentifier& service_worker_id); |
61 void WorkerContextStarted(int worker_process_id, int worker_route_id); | 64 void WorkerContextStarted(int worker_process_id, int worker_route_id); |
62 void WorkerDestroyed(int worker_process_id, int worker_route_id); | 65 void WorkerDestroyed(int worker_process_id, int worker_route_id); |
63 | 66 |
| 67 void set_debug_service_worker_on_start(bool debug_on_start) { |
| 68 debug_service_worker_on_start_ = debug_on_start; |
| 69 } |
| 70 bool debug_service_worker_on_start() const { |
| 71 return debug_service_worker_on_start_; |
| 72 } |
| 73 |
64 private: | 74 private: |
65 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; | 75 friend struct DefaultSingletonTraits<EmbeddedWorkerDevToolsManager>; |
66 friend class EmbeddedWorkerDevToolsManagerTest; | 76 friend class EmbeddedWorkerDevToolsManagerTest; |
67 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); | 77 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, BasicTest); |
68 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); | 78 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerDevToolsManagerTest, AttachTest); |
69 | 79 |
70 enum WorkerState { | 80 enum WorkerState { |
71 WORKER_UNINSPECTED, | 81 WORKER_UNINSPECTED, |
72 WORKER_INSPECTED, | 82 WORKER_INSPECTED, |
73 WORKER_TERMINATED, | 83 WORKER_TERMINATED, |
74 WORKER_PAUSED, | 84 WORKER_PAUSED_FOR_REATTACH, |
75 }; | 85 }; |
76 | 86 |
77 class WorkerInfo { | 87 class WorkerInfo { |
78 public: | 88 public: |
79 // Creates WorkerInfo for SharedWorker. | 89 // Creates WorkerInfo for SharedWorker. |
80 explicit WorkerInfo(const SharedWorkerInstance& instance); | 90 explicit WorkerInfo(const SharedWorkerInstance& instance); |
81 // Creates WorkerInfo for ServiceWorker. | 91 // Creates WorkerInfo for ServiceWorker. |
82 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id); | 92 explicit WorkerInfo(const ServiceWorkerIdentifier& service_worker_id, |
| 93 bool debug_on_start); |
83 ~WorkerInfo(); | 94 ~WorkerInfo(); |
84 | 95 |
85 WorkerState state() { return state_; } | 96 WorkerState state() { return state_; } |
86 void set_state(WorkerState new_state) { state_ = new_state; } | 97 void set_state(WorkerState new_state) { state_ = new_state; } |
87 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } | 98 EmbeddedWorkerDevToolsAgentHost* agent_host() { return agent_host_; } |
88 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { | 99 void set_agent_host(EmbeddedWorkerDevToolsAgentHost* agent_host) { |
89 agent_host_ = agent_host; | 100 agent_host_ = agent_host; |
90 } | 101 } |
91 bool Matches(const SharedWorkerInstance& other); | 102 bool Matches(const SharedWorkerInstance& other); |
92 bool Matches(const ServiceWorkerIdentifier& other); | 103 bool Matches(const ServiceWorkerIdentifier& other); |
| 104 bool debug_on_start() const { return debug_on_start_; } |
93 | 105 |
94 private: | 106 private: |
95 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; | 107 scoped_ptr<SharedWorkerInstance> shared_worker_instance_; |
96 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; | 108 scoped_ptr<ServiceWorkerIdentifier> service_worker_id_; |
| 109 const bool debug_on_start_; |
97 WorkerState state_; | 110 WorkerState state_; |
98 EmbeddedWorkerDevToolsAgentHost* agent_host_; | 111 EmbeddedWorkerDevToolsAgentHost* agent_host_; |
99 }; | 112 }; |
100 | 113 |
101 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; | 114 typedef base::ScopedPtrHashMap<WorkerId, WorkerInfo> WorkerInfoMap; |
102 | 115 |
103 EmbeddedWorkerDevToolsManager(); | 116 EmbeddedWorkerDevToolsManager(); |
104 virtual ~EmbeddedWorkerDevToolsManager(); | 117 virtual ~EmbeddedWorkerDevToolsManager(); |
105 | 118 |
106 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); | 119 void RemoveInspectedWorkerData(EmbeddedWorkerDevToolsAgentHost* agent_host); |
107 | 120 |
108 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( | 121 WorkerInfoMap::iterator FindExistingSharedWorkerInfo( |
109 const SharedWorkerInstance& instance); | 122 const SharedWorkerInstance& instance); |
110 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( | 123 WorkerInfoMap::iterator FindExistingServiceWorkerInfo( |
111 const ServiceWorkerIdentifier& service_worker_id); | 124 const ServiceWorkerIdentifier& service_worker_id); |
112 | 125 |
113 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); | 126 void MoveToPausedState(const WorkerId& id, const WorkerInfoMap::iterator& it); |
114 | 127 |
115 // Resets to its initial state as if newly created. | 128 // Resets to its initial state as if newly created. |
116 void ResetForTesting(); | 129 void ResetForTesting(); |
117 | 130 |
118 WorkerInfoMap workers_; | 131 WorkerInfoMap workers_; |
119 | 132 |
| 133 bool debug_service_worker_on_start_; |
| 134 |
120 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); | 135 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsManager); |
121 }; | 136 }; |
122 | 137 |
123 } // namespace content | 138 } // namespace content |
124 | 139 |
125 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ | 140 #endif // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_MANAGER_H_ |
OLD | NEW |