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