| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "content/browser/service_worker/embedded_worker_status.h" | 23 #include "content/browser/service_worker/embedded_worker_status.h" |
| 24 #include "content/browser/service_worker/service_worker_metrics.h" | 24 #include "content/browser/service_worker/service_worker_metrics.h" |
| 25 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
| 26 #include "content/common/service_worker/embedded_worker.mojom.h" |
| 26 #include "content/common/service_worker/service_worker_status_code.h" | 27 #include "content/common/service_worker/service_worker_status_code.h" |
| 27 #include "content/public/common/console_message_level.h" | 28 #include "content/public/common/console_message_level.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 // Windows headers will redefine SendMessage. | 31 // Windows headers will redefine SendMessage. |
| 31 #ifdef SendMessage | 32 #ifdef SendMessage |
| 32 #undef SendMessage | 33 #undef SendMessage |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 struct EmbeddedWorkerMsg_StartWorker_Params; | |
| 36 | |
| 37 namespace IPC { | 36 namespace IPC { |
| 38 class Message; | 37 class Message; |
| 39 } | 38 } |
| 40 | 39 |
| 41 namespace shell { | 40 namespace shell { |
| 42 class InterfaceProvider; | 41 class InterfaceProvider; |
| 43 class InterfaceRegistry; | 42 class InterfaceRegistry; |
| 44 } | 43 } |
| 45 | 44 |
| 46 namespace content { | 45 namespace content { |
| 47 | 46 |
| 48 class EmbeddedWorkerRegistry; | 47 class EmbeddedWorkerRegistry; |
| 48 struct EmbeddedWorkerStartParams; |
| 49 class MessagePortMessageFilter; | 49 class MessagePortMessageFilter; |
| 50 class ServiceWorkerContextCore; | 50 class ServiceWorkerContextCore; |
| 51 | 51 |
| 52 // This gives an interface to control one EmbeddedWorker instance, which | 52 // This gives an interface to control one EmbeddedWorker instance, which |
| 53 // may be 'in-waiting' or running in one of the child processes added by | 53 // may be 'in-waiting' or running in one of the child processes added by |
| 54 // AddProcessReference(). | 54 // AddProcessReference(). |
| 55 class CONTENT_EXPORT EmbeddedWorkerInstance { | 55 class CONTENT_EXPORT EmbeddedWorkerInstance { |
| 56 public: | 56 public: |
| 57 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 57 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 58 | 58 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); | 104 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 ~EmbeddedWorkerInstance(); | 107 ~EmbeddedWorkerInstance(); |
| 108 | 108 |
| 109 // Starts the worker. It is invalid to call this when the worker is not in | 109 // Starts the worker. It is invalid to call this when the worker is not in |
| 110 // STOPPED status. |callback| is invoked after the worker script has been | 110 // STOPPED status. |callback| is invoked after the worker script has been |
| 111 // started and evaluated, or when an error occurs. | 111 // started and evaluated, or when an error occurs. |
| 112 // |params| should be populated with service worker version info needed | 112 // |params| should be populated with service worker version info needed |
| 113 // to start the worker. | 113 // to start the worker. |
| 114 void Start(std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 114 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, |
| 115 const StatusCallback& callback); | 115 const StatusCallback& callback); |
| 116 | 116 |
| 117 // Stops the worker. It is invalid to call this when the worker is | 117 // Stops the worker. It is invalid to call this when the worker is |
| 118 // not in STARTING or RUNNING status. | 118 // not in STARTING or RUNNING status. |
| 119 // This returns false if stopping a worker fails immediately, e.g. when | 119 // This returns false if stopping a worker fails immediately, e.g. when |
| 120 // IPC couldn't be sent to the worker. | 120 // IPC couldn't be sent to the worker. |
| 121 ServiceWorkerStatusCode Stop(); | 121 ServiceWorkerStatusCode Stop(); |
| 122 | 122 |
| 123 // Stops the worker if the worker is not being debugged (i.e. devtools is | 123 // Stops the worker if the worker is not being debugged (i.e. devtools is |
| 124 // not attached). This method is called by a stop-worker timer to kill | 124 // not attached). This method is called by a stop-worker timer to kill |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // Called back from StartTask after a process is allocated on the UI thread. | 216 // Called back from StartTask after a process is allocated on the UI thread. |
| 217 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, | 217 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, |
| 218 ServiceWorkerMetrics::StartSituation start_situation); | 218 ServiceWorkerMetrics::StartSituation start_situation); |
| 219 | 219 |
| 220 // Called back from StartTask after the worker is registered to | 220 // Called back from StartTask after the worker is registered to |
| 221 // WorkerDevToolsManager. | 221 // WorkerDevToolsManager. |
| 222 void OnRegisteredToDevToolsManager(bool is_new_process, | 222 void OnRegisteredToDevToolsManager(bool is_new_process, |
| 223 int worker_devtools_agent_route_id, | 223 int worker_devtools_agent_route_id, |
| 224 bool wait_for_debugger); | 224 bool wait_for_debugger); |
| 225 | 225 |
| 226 // Sends StartWorker message via Mojo. |
| 227 void SendMojoStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params); |
| 228 |
| 226 // Called back from StartTask after a start worker message is sent. | 229 // Called back from StartTask after a start worker message is sent. |
| 227 void OnStartWorkerMessageSent(); | 230 void OnStartWorkerMessageSent(); |
| 228 | 231 |
| 229 // Called back from Registry when the worker instance has ack'ed that | 232 // Called back from Registry when the worker instance has ack'ed that |
| 230 // it is ready for inspection. | 233 // it is ready for inspection. |
| 231 void OnReadyForInspection(); | 234 void OnReadyForInspection(); |
| 232 | 235 |
| 233 // Called back from Registry when the worker instance has ack'ed that | 236 // Called back from Registry when the worker instance has ack'ed that |
| 234 // it finished loading the script. | 237 // it finished loading the script. |
| 235 void OnScriptLoaded(); | 238 void OnScriptLoaded(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 301 |
| 299 // Unique within an EmbeddedWorkerRegistry. | 302 // Unique within an EmbeddedWorkerRegistry. |
| 300 const int embedded_worker_id_; | 303 const int embedded_worker_id_; |
| 301 | 304 |
| 302 EmbeddedWorkerStatus status_; | 305 EmbeddedWorkerStatus status_; |
| 303 StartingPhase starting_phase_; | 306 StartingPhase starting_phase_; |
| 304 | 307 |
| 305 // Current running information. | 308 // Current running information. |
| 306 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 309 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
| 307 int thread_id_; | 310 int thread_id_; |
| 311 |
| 312 // These are connected to the renderer process after OnThreadStarted. |
| 308 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 313 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; |
| 309 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | 314 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; |
| 315 // |client_| is used to send messages to the renderer process. |
| 316 mojom::EmbeddedWorkerInstanceClientPtr client_; |
| 310 | 317 |
| 311 // Whether devtools is attached or not. | 318 // Whether devtools is attached or not. |
| 312 bool devtools_attached_; | 319 bool devtools_attached_; |
| 313 | 320 |
| 314 // True if the script load request accessed the network. If the script was | 321 // True if the script load request accessed the network. If the script was |
| 315 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 322 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
| 316 bool network_accessed_for_script_; | 323 bool network_accessed_for_script_; |
| 317 | 324 |
| 318 ListenerList listener_list_; | 325 ListenerList listener_list_; |
| 319 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 326 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
| 320 | 327 |
| 321 std::unique_ptr<StartTask> inflight_start_task_; | 328 std::unique_ptr<StartTask> inflight_start_task_; |
| 322 | 329 |
| 323 // This is valid only after a process is allocated for the worker. | 330 // This is valid only after a process is allocated for the worker. |
| 324 ServiceWorkerMetrics::StartSituation start_situation_ = | 331 ServiceWorkerMetrics::StartSituation start_situation_ = |
| 325 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 332 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
| 326 | 333 |
| 327 // Used for UMA. The start time of the current start sequence step. | 334 // Used for UMA. The start time of the current start sequence step. |
| 328 base::TimeTicks step_time_; | 335 base::TimeTicks step_time_; |
| 329 | 336 |
| 330 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 337 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 331 | 338 |
| 332 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 339 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 333 }; | 340 }; |
| 334 | 341 |
| 335 } // namespace content | 342 } // namespace content |
| 336 | 343 |
| 337 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 344 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |