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 #include "content/browser/service_worker/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 EmbeddedWorkerInstance* instance_; | 321 EmbeddedWorkerInstance* instance_; |
322 | 322 |
323 StatusCallback start_callback_; | 323 StatusCallback start_callback_; |
324 ProcessAllocationState state_; | 324 ProcessAllocationState state_; |
325 | 325 |
326 base::WeakPtrFactory<StartTask> weak_factory_; | 326 base::WeakPtrFactory<StartTask> weak_factory_; |
327 | 327 |
328 DISALLOW_COPY_AND_ASSIGN(StartTask); | 328 DISALLOW_COPY_AND_ASSIGN(StartTask); |
329 }; | 329 }; |
330 | 330 |
331 bool EmbeddedWorkerInstance::Listener::OnMessageReceived( | |
332 const IPC::Message& message) { | |
333 return false; | |
334 } | |
335 | |
336 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { | 331 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { |
337 DCHECK(status_ == STOPPING || status_ == STOPPED) << status_; | 332 DCHECK(status_ == STOPPING || status_ == STOPPED) << status_; |
338 devtools_proxy_.reset(); | 333 devtools_proxy_.reset(); |
339 if (registry_->GetWorker(embedded_worker_id_)) | 334 if (registry_->GetWorker(embedded_worker_id_)) |
340 registry_->RemoveWorker(process_id(), embedded_worker_id_); | 335 registry_->RemoveWorker(process_id(), embedded_worker_id_); |
341 process_handle_.reset(); | 336 process_handle_.reset(); |
342 } | 337 } |
343 | 338 |
344 void EmbeddedWorkerInstance::Start(int64_t service_worker_version_id, | 339 void EmbeddedWorkerInstance::Start(int64_t service_worker_version_id, |
345 const GURL& scope, | 340 const GURL& scope, |
346 const GURL& script_url, | 341 const GURL& script_url, |
347 const StatusCallback& callback, | 342 const StatusCallback& callback) { |
348 bool pause_after_download) { | |
349 if (!context_) { | 343 if (!context_) { |
350 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 344 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
351 // |this| may be destroyed by the callback. | 345 // |this| may be destroyed by the callback. |
352 return; | 346 return; |
353 } | 347 } |
354 DCHECK(status_ == STOPPED); | 348 DCHECK(status_ == STOPPED); |
355 | 349 |
356 // TODO(horo): If we will see crashes here, we have to find the root cause of | 350 // TODO(horo): If we will see crashes here, we have to find the root cause of |
357 // the invalid version ID. Otherwise change CHECK to DCHECK. | 351 // the invalid version ID. Otherwise change CHECK to DCHECK. |
358 CHECK_NE(service_worker_version_id, kInvalidServiceWorkerVersionId); | 352 CHECK_NE(service_worker_version_id, kInvalidServiceWorkerVersionId); |
359 start_timing_ = base::TimeTicks::Now(); | 353 start_timing_ = base::TimeTicks::Now(); |
360 status_ = STARTING; | 354 status_ = STARTING; |
361 starting_phase_ = ALLOCATING_PROCESS; | 355 starting_phase_ = ALLOCATING_PROCESS; |
362 network_accessed_for_script_ = false; | 356 network_accessed_for_script_ = false; |
363 service_registry_.reset(new ServiceRegistryImpl()); | 357 service_registry_.reset(new ServiceRegistryImpl()); |
364 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarting()); | 358 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarting()); |
365 | 359 |
366 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( | 360 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( |
367 new EmbeddedWorkerMsg_StartWorker_Params()); | 361 new EmbeddedWorkerMsg_StartWorker_Params()); |
368 params->embedded_worker_id = embedded_worker_id_; | 362 params->embedded_worker_id = embedded_worker_id_; |
369 params->service_worker_version_id = service_worker_version_id; | 363 params->service_worker_version_id = service_worker_version_id; |
370 params->scope = scope; | 364 params->scope = scope; |
371 params->script_url = script_url; | 365 params->script_url = script_url; |
372 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; | 366 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; |
373 params->wait_for_debugger = false; | 367 params->wait_for_debugger = false; |
374 params->pause_after_download = pause_after_download; | |
375 params->v8_cache_options = GetV8CacheOptions(); | 368 params->v8_cache_options = GetV8CacheOptions(); |
376 | 369 |
377 inflight_start_task_.reset(new StartTask(this)); | 370 inflight_start_task_.reset(new StartTask(this)); |
378 inflight_start_task_->Start(std::move(params), callback); | 371 inflight_start_task_->Start(std::move(params), callback); |
379 } | 372 } |
380 | 373 |
381 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { | 374 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
382 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; | 375 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; |
383 | 376 |
384 // Abort an inflight start task. | 377 // Abort an inflight start task. |
(...skipping 27 matching lines...) Expand all Loading... |
412 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( | 405 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( |
413 const IPC::Message& message) { | 406 const IPC::Message& message) { |
414 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); | 407 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); |
415 if (status_ != RUNNING && status_ != STARTING) | 408 if (status_ != RUNNING && status_ != STARTING) |
416 return SERVICE_WORKER_ERROR_IPC_FAILED; | 409 return SERVICE_WORKER_ERROR_IPC_FAILED; |
417 return registry_->Send(process_id(), | 410 return registry_->Send(process_id(), |
418 new EmbeddedWorkerContextMsg_MessageToWorker( | 411 new EmbeddedWorkerContextMsg_MessageToWorker( |
419 thread_id_, embedded_worker_id_, message)); | 412 thread_id_, embedded_worker_id_, message)); |
420 } | 413 } |
421 | 414 |
422 void EmbeddedWorkerInstance::ResumeAfterDownload() { | |
423 if (process_id() == ChildProcessHost::kInvalidUniqueID || status_ != STARTING) | |
424 return; | |
425 registry_->Send(process_id(), new EmbeddedWorkerMsg_ResumeAfterDownload( | |
426 embedded_worker_id_)); | |
427 } | |
428 | |
429 ServiceRegistry* EmbeddedWorkerInstance::GetServiceRegistry() { | 415 ServiceRegistry* EmbeddedWorkerInstance::GetServiceRegistry() { |
430 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; | 416 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; |
431 return service_registry_.get(); | 417 return service_registry_.get(); |
432 } | 418 } |
433 | 419 |
434 EmbeddedWorkerInstance::EmbeddedWorkerInstance( | 420 EmbeddedWorkerInstance::EmbeddedWorkerInstance( |
435 base::WeakPtr<ServiceWorkerContextCore> context, | 421 base::WeakPtr<ServiceWorkerContextCore> context, |
436 int embedded_worker_id) | 422 int embedded_worker_id) |
437 : context_(context), | 423 : context_(context), |
438 registry_(context->embedded_worker_registry()), | 424 registry_(context->embedded_worker_registry()), |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 case SCRIPT_READ_FINISHED: | 703 case SCRIPT_READ_FINISHED: |
718 return "Script read finished"; | 704 return "Script read finished"; |
719 case STARTING_PHASE_MAX_VALUE: | 705 case STARTING_PHASE_MAX_VALUE: |
720 NOTREACHED(); | 706 NOTREACHED(); |
721 } | 707 } |
722 NOTREACHED() << phase; | 708 NOTREACHED() << phase; |
723 return std::string(); | 709 return std::string(); |
724 } | 710 } |
725 | 711 |
726 } // namespace content | 712 } // namespace content |
OLD | NEW |