| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); | 105 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 ~EmbeddedWorkerInstance(); | 108 ~EmbeddedWorkerInstance(); |
| 109 | 109 |
| 110 // Starts the worker. It is invalid to call this when the worker is not in | 110 // Starts the worker. It is invalid to call this when the worker is not in |
| 111 // STOPPED status. |callback| is invoked after the worker script has been | 111 // STOPPED status. |callback| is invoked after the worker script has been |
| 112 // started and evaluated, or when an error occurs. | 112 // started and evaluated, or when an error occurs. |
| 113 // |params| should be populated with service worker version info needed | 113 // |params| should be populated with service worker version info needed |
| 114 // to start the worker. | 114 // to start the worker. |
| 115 void Start(std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 115 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, |
| 116 const StatusCallback& callback); | 116 const StatusCallback& callback); |
| 117 | 117 |
| 118 // Stops the worker. It is invalid to call this when the worker is | 118 // Stops the worker. It is invalid to call this when the worker is |
| 119 // not in STARTING or RUNNING status. | 119 // not in STARTING or RUNNING status. |
| 120 // This returns false if stopping a worker fails immediately, e.g. when | 120 // This returns false if stopping a worker fails immediately, e.g. when |
| 121 // IPC couldn't be sent to the worker. | 121 // IPC couldn't be sent to the worker. |
| 122 ServiceWorkerStatusCode Stop(); | 122 ServiceWorkerStatusCode Stop(); |
| 123 | 123 |
| 124 // Stops the worker if the worker is not being debugged (i.e. devtools is | 124 // Stops the worker if the worker is not being debugged (i.e. devtools is |
| 125 // not attached). This method is called by a stop-worker timer to kill | 125 // 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... |
| 217 // Called back from StartTask after a process is allocated on the UI thread. | 217 // Called back from StartTask after a process is allocated on the UI thread. |
| 218 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, | 218 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, |
| 219 ServiceWorkerMetrics::StartSituation start_situation); | 219 ServiceWorkerMetrics::StartSituation start_situation); |
| 220 | 220 |
| 221 // Called back from StartTask after the worker is registered to | 221 // Called back from StartTask after the worker is registered to |
| 222 // WorkerDevToolsManager. | 222 // WorkerDevToolsManager. |
| 223 void OnRegisteredToDevToolsManager(bool is_new_process, | 223 void OnRegisteredToDevToolsManager(bool is_new_process, |
| 224 int worker_devtools_agent_route_id, | 224 int worker_devtools_agent_route_id, |
| 225 bool wait_for_debugger); | 225 bool wait_for_debugger); |
| 226 | 226 |
| 227 // Sends StartWorker message via Mojo. |
| 228 void SendMojoStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params); |
| 229 |
| 227 // Called back from StartTask after a start worker message is sent. | 230 // Called back from StartTask after a start worker message is sent. |
| 228 void OnStartWorkerMessageSent(); | 231 void OnStartWorkerMessageSent(); |
| 229 | 232 |
| 230 // Called back from Registry when the worker instance has ack'ed that | 233 // Called back from Registry when the worker instance has ack'ed that |
| 231 // it is ready for inspection. | 234 // it is ready for inspection. |
| 232 void OnReadyForInspection(); | 235 void OnReadyForInspection(); |
| 233 | 236 |
| 234 // Called back from Registry when the worker instance has ack'ed that | 237 // Called back from Registry when the worker instance has ack'ed that |
| 235 // it finished loading the script. | 238 // it finished loading the script. |
| 236 void OnScriptLoaded(); | 239 void OnScriptLoaded(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 302 |
| 300 // Unique within an EmbeddedWorkerRegistry. | 303 // Unique within an EmbeddedWorkerRegistry. |
| 301 const int embedded_worker_id_; | 304 const int embedded_worker_id_; |
| 302 | 305 |
| 303 EmbeddedWorkerStatus status_; | 306 EmbeddedWorkerStatus status_; |
| 304 StartingPhase starting_phase_; | 307 StartingPhase starting_phase_; |
| 305 | 308 |
| 306 // Current running information. | 309 // Current running information. |
| 307 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 310 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
| 308 int thread_id_; | 311 int thread_id_; |
| 312 |
| 313 // These are connected to the renderer process after OnThreadStarted. |
| 309 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 314 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; |
| 310 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | 315 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; |
| 316 // |client_| is used to send messages to the renderer process. |
| 317 mojom::EmbeddedWorkerInstanceClientPtr client_; |
| 311 | 318 |
| 312 // Whether devtools is attached or not. | 319 // Whether devtools is attached or not. |
| 313 bool devtools_attached_; | 320 bool devtools_attached_; |
| 314 | 321 |
| 315 // True if the script load request accessed the network. If the script was | 322 // True if the script load request accessed the network. If the script was |
| 316 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 323 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
| 317 bool network_accessed_for_script_; | 324 bool network_accessed_for_script_; |
| 318 | 325 |
| 319 ListenerList listener_list_; | 326 ListenerList listener_list_; |
| 320 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 327 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
| 321 | 328 |
| 322 std::unique_ptr<StartTask> inflight_start_task_; | 329 std::unique_ptr<StartTask> inflight_start_task_; |
| 323 | 330 |
| 324 // This is valid only after a process is allocated for the worker. | 331 // This is valid only after a process is allocated for the worker. |
| 325 ServiceWorkerMetrics::StartSituation start_situation_ = | 332 ServiceWorkerMetrics::StartSituation start_situation_ = |
| 326 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 333 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
| 327 | 334 |
| 328 // Used for UMA. The start time of the current start sequence step. | 335 // Used for UMA. The start time of the current start sequence step. |
| 329 base::TimeTicks step_time_; | 336 base::TimeTicks step_time_; |
| 330 | 337 |
| 331 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 338 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 332 | 339 |
| 333 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 340 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 334 }; | 341 }; |
| 335 | 342 |
| 336 } // namespace content | 343 } // namespace content |
| 337 | 344 |
| 338 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 345 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |