| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 class EmbeddedWorkerRegistry; | 43 class EmbeddedWorkerRegistry; |
| 44 struct EmbeddedWorkerStartParams; | 44 struct EmbeddedWorkerStartParams; |
| 45 class ServiceWorkerContextCore; | 45 class ServiceWorkerContextCore; |
| 46 | 46 |
| 47 // This gives an interface to control one EmbeddedWorker instance, which | 47 // This gives an interface to control one EmbeddedWorker instance, which |
| 48 // may be 'in-waiting' or running in one of the child processes added by | 48 // may be 'in-waiting' or running in one of the child processes added by |
| 49 // AddProcessReference(). | 49 // AddProcessReference(). |
| 50 class CONTENT_EXPORT EmbeddedWorkerInstance | 50 class CONTENT_EXPORT EmbeddedWorkerInstance |
| 51 : NON_EXPORTED_BASE(public mojom::EmbeddedWorkerInstanceHost) { | 51 : NON_EXPORTED_BASE(public mojom::EmbeddedWorkerInstanceHost) { |
| 52 public: | 52 public: |
| 53 class DevToolsProxy; |
| 53 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 54 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 54 | 55 |
| 55 // This enum is used in UMA histograms. Append-only. | 56 // This enum is used in UMA histograms. Append-only. |
| 56 enum StartingPhase { | 57 enum StartingPhase { |
| 57 NOT_STARTING, | 58 NOT_STARTING, |
| 58 ALLOCATING_PROCESS, | 59 ALLOCATING_PROCESS, |
| 59 REGISTERING_TO_DEVTOOLS, | 60 REGISTERING_TO_DEVTOOLS, |
| 60 SENT_START_WORKER, | 61 SENT_START_WORKER, |
| 61 SCRIPT_DOWNLOADING, | 62 SCRIPT_DOWNLOADING, |
| 62 SCRIPT_LOADED, | 63 SCRIPT_LOADED, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 static std::string StatusToString(EmbeddedWorkerStatus status); | 186 static std::string StatusToString(EmbeddedWorkerStatus status); |
| 186 static std::string StartingPhaseToString(StartingPhase phase); | 187 static std::string StartingPhaseToString(StartingPhase phase); |
| 187 | 188 |
| 188 void Detach(); | 189 void Detach(); |
| 189 | 190 |
| 190 base::WeakPtr<EmbeddedWorkerInstance> AsWeakPtr(); | 191 base::WeakPtr<EmbeddedWorkerInstance> AsWeakPtr(); |
| 191 | 192 |
| 192 private: | 193 private: |
| 193 typedef base::ObserverList<Listener> ListenerList; | 194 typedef base::ObserverList<Listener> ListenerList; |
| 194 class DevToolsProxy; | |
| 195 class StartTask; | 195 class StartTask; |
| 196 class WorkerProcessHandle; | 196 class WorkerProcessHandle; |
| 197 friend class EmbeddedWorkerRegistry; | 197 friend class EmbeddedWorkerRegistry; |
| 198 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); | 198 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StartAndStop); |
| 199 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); | 199 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, DetachDuringStart); |
| 200 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); | 200 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, StopDuringStart); |
| 201 | 201 |
| 202 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). | 202 // Constructor is called via EmbeddedWorkerRegistry::CreateWorker(). |
| 203 // This instance holds a ref of |registry|. | 203 // This instance holds a ref of |registry|. |
| 204 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, | 204 EmbeddedWorkerInstance(base::WeakPtr<ServiceWorkerContextCore> context, |
| 205 int embedded_worker_id); | 205 int embedded_worker_id); |
| 206 | 206 |
| 207 // Called back from StartTask after a process is allocated on the UI thread. | 207 // Called back from StartTask after a process is allocated on the UI thread. |
| 208 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, | 208 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, |
| 209 ServiceWorkerMetrics::StartSituation start_situation); | 209 ServiceWorkerMetrics::StartSituation start_situation); |
| 210 | 210 |
| 211 // Called back from StartTask after the worker is registered to | 211 // Called back from StartTask after the worker is registered to |
| 212 // WorkerDevToolsManager. | 212 // WorkerDevToolsManager. |
| 213 void OnRegisteredToDevToolsManager(bool is_new_process, | 213 void OnRegisteredToDevToolsManager( |
| 214 int worker_devtools_agent_route_id, | 214 bool is_new_process, |
| 215 bool wait_for_debugger); | 215 std::unique_ptr<DevToolsProxy> devtools_proxy, |
| 216 bool wait_for_debugger); |
| 216 | 217 |
| 217 // Sends StartWorker message via Mojo. | 218 // Sends StartWorker message via Mojo. |
| 218 ServiceWorkerStatusCode SendStartWorker( | 219 ServiceWorkerStatusCode SendStartWorker( |
| 219 std::unique_ptr<EmbeddedWorkerStartParams> params); | 220 std::unique_ptr<EmbeddedWorkerStartParams> params); |
| 220 | 221 |
| 221 // Called back from StartTask after a start worker message is sent. | 222 // Called back from StartTask after a start worker message is sent. |
| 222 void OnStartWorkerMessageSent(); | 223 void OnStartWorkerMessageSent(); |
| 223 | 224 |
| 224 // Implements mojom::EmbeddedWorkerInstanceHost. | 225 // Implements mojom::EmbeddedWorkerInstanceHost. |
| 225 // These functions all run on the IO thread. | 226 // These functions all run on the IO thread. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 base::TimeTicks step_time_; | 313 base::TimeTicks step_time_; |
| 313 | 314 |
| 314 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 315 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 315 | 316 |
| 316 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 317 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 317 }; | 318 }; |
| 318 | 319 |
| 319 } // namespace content | 320 } // namespace content |
| 320 | 321 |
| 321 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |