| 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/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "content/browser/bad_message.h" | 25 #include "content/browser/bad_message.h" |
| 26 #include "content/browser/child_process_security_policy_impl.h" | 26 #include "content/browser/child_process_security_policy_impl.h" |
| 27 #include "content/browser/message_port_message_filter.h" | 27 #include "content/browser/message_port_message_filter.h" |
| 28 #include "content/browser/message_port_service.h" | 28 #include "content/browser/message_port_service.h" |
| 29 #include "content/browser/service_worker/embedded_worker_instance.h" | 29 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 30 #include "content/browser/service_worker/embedded_worker_registry.h" | 30 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 31 #include "content/browser/service_worker/embedded_worker_status.h" | 31 #include "content/browser/service_worker/embedded_worker_status.h" |
| 32 #include "content/browser/service_worker/service_worker_client_utils.h" | 32 #include "content/browser/service_worker/service_worker_client_utils.h" |
| 33 #include "content/browser/service_worker/service_worker_context_core.h" | 33 #include "content/browser/service_worker/service_worker_context_core.h" |
| 34 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 34 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 35 #include "content/browser/service_worker/service_worker_global_scope_host_impl.h
" |
| 35 #include "content/browser/service_worker/service_worker_metrics.h" | 36 #include "content/browser/service_worker/service_worker_metrics.h" |
| 36 #include "content/browser/service_worker/service_worker_registration.h" | 37 #include "content/browser/service_worker/service_worker_registration.h" |
| 37 #include "content/common/service_worker/embedded_worker_messages.h" | 38 #include "content/common/service_worker/embedded_worker_messages.h" |
| 38 #include "content/common/service_worker/service_worker_messages.h" | 39 #include "content/common/service_worker/service_worker_messages.h" |
| 39 #include "content/common/service_worker/service_worker_type_converters.h" | 40 #include "content/common/service_worker/service_worker_type_converters.h" |
| 40 #include "content/common/service_worker/service_worker_utils.h" | 41 #include "content/common/service_worker/service_worker_utils.h" |
| 41 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/content_browser_client.h" | 43 #include "content/public/browser/content_browser_client.h" |
| 43 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/common/content_client.h" | 45 #include "content/public/common/content_client.h" |
| 45 #include "content/public/common/content_switches.h" | 46 #include "content/public/common/content_switches.h" |
| 46 #include "content/public/common/result_codes.h" | 47 #include "content/public/common/result_codes.h" |
| 47 #include "mojo/common/common_type_converters.h" | 48 #include "mojo/common/common_type_converters.h" |
| 48 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
| 49 #include "net/http/http_response_info.h" | 50 #include "net/http/http_response_info.h" |
| 51 #include "services/shell/public/cpp/interface_registry.h" |
| 50 | 52 |
| 51 namespace content { | 53 namespace content { |
| 52 | 54 |
| 53 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 55 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 // Time to wait until stopping an idle worker. | 59 // Time to wait until stopping an idle worker. |
| 58 const int kIdleWorkerTimeoutSeconds = 30; | 60 const int kIdleWorkerTimeoutSeconds = 30; |
| 59 | 61 |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 764 } |
| 763 } | 765 } |
| 764 | 766 |
| 765 void ServiceWorkerVersion::OnThreadStarted() { | 767 void ServiceWorkerVersion::OnThreadStarted() { |
| 766 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status()); | 768 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status()); |
| 767 // Activate ping/pong now that JavaScript execution will start. | 769 // Activate ping/pong now that JavaScript execution will start. |
| 768 ping_controller_->Activate(); | 770 ping_controller_->Activate(); |
| 769 } | 771 } |
| 770 | 772 |
| 771 void ServiceWorkerVersion::OnStarting() { | 773 void ServiceWorkerVersion::OnStarting() { |
| 774 // Setup mojo services |
| 775 embedded_worker_->GetInterfaceRegistry()->AddInterface( |
| 776 base::Bind(&ServiceWorkerGlobalScopeHostImpl::Create, |
| 777 weak_factory_.GetWeakPtr())); |
| 778 |
| 772 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 779 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 773 } | 780 } |
| 774 | 781 |
| 775 void ServiceWorkerVersion::OnStarted() { | 782 void ServiceWorkerVersion::OnStarted() { |
| 776 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); | 783 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); |
| 777 RestartTick(&idle_time_); | 784 RestartTick(&idle_time_); |
| 778 | 785 |
| 786 base::WeakPtr<blink::mojom::ServiceWorkerGlobalScopeClient> client = |
| 787 GetMojoService<blink::mojom::ServiceWorkerGlobalScopeClient>(); |
| 788 client->DispatchPingEvent("hello client!"); |
| 789 |
| 779 // Fire all start callbacks. | 790 // Fire all start callbacks. |
| 780 scoped_refptr<ServiceWorkerVersion> protect(this); | 791 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 781 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); | 792 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); |
| 782 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 793 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| 783 } | 794 } |
| 784 | 795 |
| 785 void ServiceWorkerVersion::OnStopping() { | 796 void ServiceWorkerVersion::OnStopping() { |
| 786 DCHECK(stop_time_.is_null()); | 797 DCHECK(stop_time_.is_null()); |
| 787 RestartTick(&stop_time_); | 798 RestartTick(&stop_time_); |
| 788 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::StopWorker", | 799 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::StopWorker", |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 return; | 966 return; |
| 956 } | 967 } |
| 957 | 968 |
| 958 embedded_worker_->SendMessage( | 969 embedded_worker_->SendMessage( |
| 959 ServiceWorkerMsg_DidGetClients(request_id, *clients)); | 970 ServiceWorkerMsg_DidGetClients(request_id, *clients)); |
| 960 } | 971 } |
| 961 | 972 |
| 962 void ServiceWorkerVersion::OnSimpleEventResponse( | 973 void ServiceWorkerVersion::OnSimpleEventResponse( |
| 963 int request_id, | 974 int request_id, |
| 964 blink::WebServiceWorkerEventResult result) { | 975 blink::WebServiceWorkerEventResult result) { |
| 976 ServiceWorkerStatusCode status = |
| 977 SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; |
| 978 if (result == blink::WebServiceWorkerEventResultCompleted) |
| 979 status = SERVICE_WORKER_OK; |
| 980 OnSimpleEventResponse(request_id, status); |
| 981 } |
| 982 |
| 983 void ServiceWorkerVersion::OnSimpleEventResponse( |
| 984 int request_id, |
| 985 ServiceWorkerStatusCode status) { |
| 965 // Copy error callback before calling FinishRequest. | 986 // Copy error callback before calling FinishRequest. |
| 966 PendingRequest* request = pending_requests_.Lookup(request_id); | 987 PendingRequest* request = pending_requests_.Lookup(request_id); |
| 967 DCHECK(request) << "Invalid request id"; | 988 DCHECK(request) << "Invalid request id"; |
| 968 StatusCallback callback = request->error_callback; | 989 StatusCallback callback = request->error_callback; |
| 969 | 990 FinishRequest(request_id, status == SERVICE_WORKER_OK); |
| 970 FinishRequest(request_id, | |
| 971 result == blink::WebServiceWorkerEventResultCompleted); | |
| 972 | |
| 973 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
| 974 if (result == blink::WebServiceWorkerEventResultRejected) | |
| 975 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 976 callback.Run(status); | 991 callback.Run(status); |
| 977 } | 992 } |
| 978 | 993 |
| 979 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { | 994 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { |
| 980 // Just abort if we are shutting down. | 995 // Just abort if we are shutting down. |
| 981 if (!context_) | 996 if (!context_) |
| 982 return; | 997 return; |
| 983 | 998 |
| 984 if (!url.is_valid()) { | 999 if (!url.is_valid()) { |
| 985 DVLOG(1) << "Received unexpected invalid URL from renderer process."; | 1000 DVLOG(1) << "Received unexpected invalid URL from renderer process."; |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 if (should_exclude_from_uma_ || | 1752 if (should_exclude_from_uma_ || |
| 1738 running_status() != EmbeddedWorkerStatus::RUNNING || | 1753 running_status() != EmbeddedWorkerStatus::RUNNING || |
| 1739 idle_time_.is_null()) { | 1754 idle_time_.is_null()) { |
| 1740 return; | 1755 return; |
| 1741 } | 1756 } |
| 1742 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1757 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1743 idle_time_); | 1758 idle_time_); |
| 1744 } | 1759 } |
| 1745 | 1760 |
| 1746 } // namespace content | 1761 } // namespace content |
| OLD | NEW |