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 10 matching lines...) Expand all Loading... |
21 #include "content/common/service_worker/embedded_worker_settings.h" | 21 #include "content/common/service_worker/embedded_worker_settings.h" |
22 #include "content/common/service_worker/embedded_worker_start_params.h" | 22 #include "content/common/service_worker/embedded_worker_start_params.h" |
23 #include "content/common/service_worker/service_worker_types.h" | 23 #include "content/common/service_worker/service_worker_types.h" |
24 #include "content/common/service_worker/service_worker_utils.h" | 24 #include "content/common/service_worker/service_worker_utils.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/common/child_process_host.h" | 28 #include "content/public/common/child_process_host.h" |
29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
30 #include "ipc/ipc_message.h" | 30 #include "ipc/ipc_message.h" |
| 31 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // When a service worker version's failure count exceeds | 38 // When a service worker version's failure count exceeds |
38 // |kMaxSameProcessFailureCount|, the embedded worker is forced to start in a | 39 // |kMaxSameProcessFailureCount|, the embedded worker is forced to start in a |
39 // new process. | 40 // new process. |
40 const int kMaxSameProcessFailureCount = 2; | 41 const int kMaxSameProcessFailureCount = 2; |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 observer.OnStopping(); | 508 observer.OnStopping(); |
508 return true; | 509 return true; |
509 } | 510 } |
510 | 511 |
511 void EmbeddedWorkerInstance::StopIfIdle() { | 512 void EmbeddedWorkerInstance::StopIfIdle() { |
512 if (devtools_attached_) { | 513 if (devtools_attached_) { |
513 if (devtools_proxy_) { | 514 if (devtools_proxy_) { |
514 // Check ShouldNotifyWorkerStopIgnored not to show the same message | 515 // Check ShouldNotifyWorkerStopIgnored not to show the same message |
515 // multiple times in DevTools. | 516 // multiple times in DevTools. |
516 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) { | 517 if (devtools_proxy_->ShouldNotifyWorkerStopIgnored()) { |
517 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_DEBUG, | 518 AddMessageToConsole(blink::WebConsoleMessage::LevelDebug, |
518 kServiceWorkerTerminationCanceledMesage); | 519 kServiceWorkerTerminationCanceledMesage); |
519 devtools_proxy_->WorkerStopIgnoredNotified(); | 520 devtools_proxy_->WorkerStopIgnoredNotified(); |
520 } | 521 } |
521 } | 522 } |
522 return; | 523 return; |
523 } | 524 } |
524 Stop(); | 525 Stop(); |
525 } | 526 } |
526 | 527 |
527 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( | 528 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( |
528 const IPC::Message& message) { | 529 const IPC::Message& message) { |
529 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); | 530 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); |
530 if (status_ != EmbeddedWorkerStatus::RUNNING && | 531 if (status_ != EmbeddedWorkerStatus::RUNNING && |
531 status_ != EmbeddedWorkerStatus::STARTING) { | 532 status_ != EmbeddedWorkerStatus::STARTING) { |
532 return SERVICE_WORKER_ERROR_IPC_FAILED; | 533 return SERVICE_WORKER_ERROR_IPC_FAILED; |
533 } | 534 } |
534 return registry_->Send(process_id(), | 535 return registry_->Send(process_id(), |
535 new EmbeddedWorkerContextMsg_MessageToWorker( | 536 new EmbeddedWorkerContextMsg_MessageToWorker( |
536 thread_id_, embedded_worker_id_, message)); | 537 thread_id_, embedded_worker_id_, message)); |
537 } | 538 } |
538 | 539 |
539 void EmbeddedWorkerInstance::ResumeAfterDownload() { | 540 void EmbeddedWorkerInstance::ResumeAfterDownload() { |
540 if (process_id() == ChildProcessHost::kInvalidUniqueID || | 541 if (process_id() == ChildProcessHost::kInvalidUniqueID || |
541 status_ != EmbeddedWorkerStatus::STARTING) { | 542 status_ != EmbeddedWorkerStatus::STARTING) { |
542 return; | 543 return; |
543 } | 544 } |
544 registry_->Send(process_id(), new EmbeddedWorkerMsg_ResumeAfterDownload( | 545 DCHECK(client_.is_bound()); |
545 embedded_worker_id_)); | 546 client_->ResumeAfterDownload(); |
546 } | 547 } |
547 | 548 |
548 EmbeddedWorkerInstance::EmbeddedWorkerInstance( | 549 EmbeddedWorkerInstance::EmbeddedWorkerInstance( |
549 base::WeakPtr<ServiceWorkerContextCore> context, | 550 base::WeakPtr<ServiceWorkerContextCore> context, |
550 int embedded_worker_id) | 551 int embedded_worker_id) |
551 : context_(context), | 552 : context_(context), |
552 registry_(context->embedded_worker_registry()), | 553 registry_(context->embedded_worker_registry()), |
553 embedded_worker_id_(embedded_worker_id), | 554 embedded_worker_id_(embedded_worker_id), |
554 status_(EmbeddedWorkerStatus::STOPPED), | 555 status_(EmbeddedWorkerStatus::STOPPED), |
555 starting_phase_(NOT_STARTING), | 556 starting_phase_(NOT_STARTING), |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 861 |
861 base::TimeDelta EmbeddedWorkerInstance::UpdateStepTime() { | 862 base::TimeDelta EmbeddedWorkerInstance::UpdateStepTime() { |
862 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 863 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
863 DCHECK(!step_time_.is_null()); | 864 DCHECK(!step_time_.is_null()); |
864 base::TimeTicks now = base::TimeTicks::Now(); | 865 base::TimeTicks now = base::TimeTicks::Now(); |
865 base::TimeDelta duration = now - step_time_; | 866 base::TimeDelta duration = now - step_time_; |
866 step_time_ = now; | 867 step_time_ = now; |
867 return duration; | 868 return duration; |
868 } | 869 } |
869 | 870 |
870 void EmbeddedWorkerInstance::AddMessageToConsole(ConsoleMessageLevel level, | 871 void EmbeddedWorkerInstance::AddMessageToConsole( |
871 const std::string& message) { | 872 blink::WebConsoleMessage::Level level, |
| 873 const std::string& message) { |
872 if (status_ != EmbeddedWorkerStatus::RUNNING && | 874 if (status_ != EmbeddedWorkerStatus::RUNNING && |
873 status_ != EmbeddedWorkerStatus::STARTING) { | 875 status_ != EmbeddedWorkerStatus::STARTING) { |
874 return; | 876 return; |
875 } | 877 } |
876 registry_->Send(process_id(), new EmbeddedWorkerMsg_AddMessageToConsole( | 878 DCHECK(client_.is_bound()); |
877 embedded_worker_id_, level, message)); | 879 client_->AddMessageToConsole(level, message); |
878 } | 880 } |
879 | 881 |
880 // static | 882 // static |
881 std::string EmbeddedWorkerInstance::StatusToString( | 883 std::string EmbeddedWorkerInstance::StatusToString( |
882 EmbeddedWorkerStatus status) { | 884 EmbeddedWorkerStatus status) { |
883 switch (status) { | 885 switch (status) { |
884 case EmbeddedWorkerStatus::STOPPED: | 886 case EmbeddedWorkerStatus::STOPPED: |
885 return "STOPPED"; | 887 return "STOPPED"; |
886 case EmbeddedWorkerStatus::STARTING: | 888 case EmbeddedWorkerStatus::STARTING: |
887 return "STARTING"; | 889 return "STARTING"; |
(...skipping 30 matching lines...) Expand all Loading... |
918 case SCRIPT_READ_FINISHED: | 920 case SCRIPT_READ_FINISHED: |
919 return "Script read finished"; | 921 return "Script read finished"; |
920 case STARTING_PHASE_MAX_VALUE: | 922 case STARTING_PHASE_MAX_VALUE: |
921 NOTREACHED(); | 923 NOTREACHED(); |
922 } | 924 } |
923 NOTREACHED() << phase; | 925 NOTREACHED() << phase; |
924 return std::string(); | 926 return std::string(); |
925 } | 927 } |
926 | 928 |
927 } // namespace content | 929 } // namespace content |
OLD | NEW |