| 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/embedded_worker.mojom.h" |
| 27 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
| 27 #include "content/common/service_worker/service_worker_status_code.h" | 28 #include "content/common/service_worker/service_worker_status_code.h" |
| 28 #include "content/public/common/console_message_level.h" | 29 #include "content/public/common/console_message_level.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 // Windows headers will redefine SendMessage. | 32 // Windows headers will redefine SendMessage. |
| 32 #ifdef SendMessage | 33 #ifdef SendMessage |
| 33 #undef SendMessage | 34 #undef SendMessage |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 namespace IPC { | 37 namespace IPC { |
| 37 class Message; | 38 class Message; |
| 38 } | 39 } |
| 39 | 40 |
| 40 namespace service_manager { | |
| 41 class InterfaceProvider; | |
| 42 class InterfaceRegistry; | |
| 43 } | |
| 44 | |
| 45 namespace content { | 41 namespace content { |
| 46 | 42 |
| 47 class EmbeddedWorkerRegistry; | 43 class EmbeddedWorkerRegistry; |
| 48 struct EmbeddedWorkerStartParams; | 44 struct EmbeddedWorkerStartParams; |
| 49 class MessagePortMessageFilter; | 45 class MessagePortMessageFilter; |
| 50 class ServiceWorkerContextCore; | 46 class ServiceWorkerContextCore; |
| 51 | 47 |
| 52 // This gives an interface to control one EmbeddedWorker instance, which | 48 // 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 | 49 // may be 'in-waiting' or running in one of the child processes added by |
| 54 // AddProcessReference(). | 50 // AddProcessReference(). |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void StopIfIdle(); | 123 void StopIfIdle(); |
| 128 | 124 |
| 129 // Sends |message| to the embedded worker running in the child process. | 125 // Sends |message| to the embedded worker running in the child process. |
| 130 // It is invalid to call this while the worker is not in STARTING or RUNNING | 126 // It is invalid to call this while the worker is not in STARTING or RUNNING |
| 131 // status. | 127 // status. |
| 132 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); | 128 ServiceWorkerStatusCode SendMessage(const IPC::Message& message); |
| 133 | 129 |
| 134 // Resumes the worker if it paused after download. | 130 // Resumes the worker if it paused after download. |
| 135 void ResumeAfterDownload(); | 131 void ResumeAfterDownload(); |
| 136 | 132 |
| 137 // Returns the service_manager::InterfaceRegistry and | |
| 138 // service_manager::InterfaceProvider for this | |
| 139 // worker. It is invalid to call this when the worker is not in STARTING or | |
| 140 // RUNNING status. | |
| 141 service_manager::InterfaceRegistry* GetInterfaceRegistry(); | |
| 142 service_manager::InterfaceProvider* GetRemoteInterfaces(); | |
| 143 | |
| 144 int embedded_worker_id() const { return embedded_worker_id_; } | 133 int embedded_worker_id() const { return embedded_worker_id_; } |
| 145 EmbeddedWorkerStatus status() const { return status_; } | 134 EmbeddedWorkerStatus status() const { return status_; } |
| 146 StartingPhase starting_phase() const { | 135 StartingPhase starting_phase() const { |
| 147 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status()); | 136 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status()); |
| 148 return starting_phase_; | 137 return starting_phase_; |
| 149 } | 138 } |
| 150 int process_id() const; | 139 int process_id() const; |
| 151 int thread_id() const { return thread_id_; } | 140 int thread_id() const { return thread_id_; } |
| 152 // This should be called only when the worker instance has a valid process, | 141 // This should be called only when the worker instance has a valid process, |
| 153 // that is, when |process_id()| returns a valid process id. | 142 // that is, when |process_id()| returns a valid process id. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // Unique within an EmbeddedWorkerRegistry. | 294 // Unique within an EmbeddedWorkerRegistry. |
| 306 const int embedded_worker_id_; | 295 const int embedded_worker_id_; |
| 307 | 296 |
| 308 EmbeddedWorkerStatus status_; | 297 EmbeddedWorkerStatus status_; |
| 309 StartingPhase starting_phase_; | 298 StartingPhase starting_phase_; |
| 310 | 299 |
| 311 // Current running information. | 300 // Current running information. |
| 312 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 301 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
| 313 int thread_id_; | 302 int thread_id_; |
| 314 | 303 |
| 315 // These are connected to the renderer process after OnThreadStarted. | |
| 316 std::unique_ptr<service_manager::InterfaceRegistry> interface_registry_; | |
| 317 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces_; | |
| 318 // |client_| is used to send messages to the renderer process. | 304 // |client_| is used to send messages to the renderer process. |
| 319 mojom::EmbeddedWorkerInstanceClientPtr client_; | 305 mojom::EmbeddedWorkerInstanceClientPtr client_; |
| 320 | 306 |
| 307 // TODO(shimazu): Remove this after non-mojo StartWorker is removed. |
| 308 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; |
| 309 |
| 321 // Whether devtools is attached or not. | 310 // Whether devtools is attached or not. |
| 322 bool devtools_attached_; | 311 bool devtools_attached_; |
| 323 | 312 |
| 324 // True if the script load request accessed the network. If the script was | 313 // True if the script load request accessed the network. If the script was |
| 325 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 314 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
| 326 bool network_accessed_for_script_; | 315 bool network_accessed_for_script_; |
| 327 | 316 |
| 328 ListenerList listener_list_; | 317 ListenerList listener_list_; |
| 329 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 318 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
| 330 | 319 |
| 331 std::unique_ptr<StartTask> inflight_start_task_; | 320 std::unique_ptr<StartTask> inflight_start_task_; |
| 332 | 321 |
| 333 // This is valid only after a process is allocated for the worker. | 322 // This is valid only after a process is allocated for the worker. |
| 334 ServiceWorkerMetrics::StartSituation start_situation_ = | 323 ServiceWorkerMetrics::StartSituation start_situation_ = |
| 335 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 324 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
| 336 | 325 |
| 337 // Used for UMA. The start time of the current start sequence step. | 326 // Used for UMA. The start time of the current start sequence step. |
| 338 base::TimeTicks step_time_; | 327 base::TimeTicks step_time_; |
| 339 | 328 |
| 340 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 329 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
| 341 | 330 |
| 342 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 331 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
| 343 }; | 332 }; |
| 344 | 333 |
| 345 } // namespace content | 334 } // namespace content |
| 346 | 335 |
| 347 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 336 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
| OLD | NEW |