Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 2936623002: Implement dumb URLLoader{Factory} for ServiceWorker script loading (for try)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 ServiceWorkerMetrics::EventType event_type) 839 ServiceWorkerMetrics::EventType event_type)
840 : error_callback(callback), 840 : error_callback(callback),
841 start_time(time), 841 start_time(time),
842 start_time_ticks(time_ticks), 842 start_time_ticks(time_ticks),
843 event_type(event_type) {} 843 event_type(event_type) {}
844 844
845 ServiceWorkerVersion::PendingRequest::~PendingRequest() {} 845 ServiceWorkerVersion::PendingRequest::~PendingRequest() {}
846 846
847 void ServiceWorkerVersion::OnThreadStarted() { 847 void ServiceWorkerVersion::OnThreadStarted() {
848 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status()); 848 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status());
849 DCHECK(provider_host_);
850 provider_host_->SetReadyToSendMessagesToWorker(
851 embedded_worker()->thread_id());
849 // Activate ping/pong now that JavaScript execution will start. 852 // Activate ping/pong now that JavaScript execution will start.
850 ping_controller_->Activate(); 853 ping_controller_->Activate();
851 } 854 }
852 855
853 void ServiceWorkerVersion::OnStarting() { 856 void ServiceWorkerVersion::OnStarting() {
854 for (auto& observer : listeners_) 857 for (auto& observer : listeners_)
855 observer.OnRunningStateChanged(this); 858 observer.OnRunningStateChanged(this);
856 } 859 }
857 860
861 void ServiceWorkerVersion::OnStartWorkerMessageSent() {
862 DCHECK(pending_provider_host_);
863 context()->AddProviderHost(std::move(pending_provider_host_));
864 }
865
858 void ServiceWorkerVersion::OnStarted() { 866 void ServiceWorkerVersion::OnStarted() {
859 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); 867 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status());
860 RestartTick(&idle_time_); 868 RestartTick(&idle_time_);
861 869
862 // Fire all start callbacks. 870 // Fire all start callbacks.
863 scoped_refptr<ServiceWorkerVersion> protect(this); 871 scoped_refptr<ServiceWorkerVersion> protect(this);
864 FinishStartWorker(SERVICE_WORKER_OK); 872 FinishStartWorker(SERVICE_WORKER_OK);
865 for (auto& observer : listeners_) 873 for (auto& observer : listeners_)
866 observer.OnRunningStateChanged(this); 874 observer.OnRunningStateChanged(this);
867 } 875 }
(...skipping 28 matching lines...) Expand all
896 904
897 void ServiceWorkerVersion::OnDetached(EmbeddedWorkerStatus old_status) { 905 void ServiceWorkerVersion::OnDetached(EmbeddedWorkerStatus old_status) {
898 if (IsInstalled(status())) { 906 if (IsInstalled(status())) {
899 ServiceWorkerMetrics::RecordWorkerStopped( 907 ServiceWorkerMetrics::RecordWorkerStopped(
900 ServiceWorkerMetrics::StopStatus::DETACH_BY_REGISTRY); 908 ServiceWorkerMetrics::StopStatus::DETACH_BY_REGISTRY);
901 } 909 }
902 OnStoppedInternal(old_status); 910 OnStoppedInternal(old_status);
903 } 911 }
904 912
905 void ServiceWorkerVersion::OnScriptLoaded() { 913 void ServiceWorkerVersion::OnScriptLoaded() {
906 DCHECK(GetMainScriptHttpResponseInfo() || 914 DCHECK(GetMainScriptHttpResponseInfo());
907 // TODO(scottmg|falken): This DCHECK is currently triggered in
908 // --network-service because ServiceWorkerReadFromCacheJob isn't being
909 // used to retrieve the service worker js. This should be removed once
910 // that's done.
911 (IsBrowserSideNavigationEnabled() &&
912 base::CommandLine::ForCurrentProcess()->HasSwitch(
913 switches::kEnableNetworkService)));
914 if (IsInstalled(status())) 915 if (IsInstalled(status()))
915 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.ScriptLoadSuccess", true); 916 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.ScriptLoadSuccess", true);
916 } 917 }
917 918
918 void ServiceWorkerVersion::OnScriptLoadFailed() { 919 void ServiceWorkerVersion::OnScriptLoadFailed() {
919 if (IsInstalled(status())) 920 if (IsInstalled(status()))
920 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.ScriptLoadSuccess", false); 921 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.ScriptLoadSuccess", false);
921 } 922 }
922 923
923 void ServiceWorkerVersion::OnRegisteredToDevToolsManager() { 924 void ServiceWorkerVersion::OnRegisteredToDevToolsManager() {
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status()); 1459 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status());
1459 1460
1460 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) { 1461 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) {
1461 DCHECK(!event_recorder_); 1462 DCHECK(!event_recorder_);
1462 event_recorder_ = 1463 event_recorder_ =
1463 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>(); 1464 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>();
1464 } 1465 }
1465 1466
1466 StartTimeoutTimer(); 1467 StartTimeoutTimer();
1467 1468
1469 DCHECK(!pending_provider_host_);
1470 pending_provider_host_ =
1471 ServiceWorkerProviderHost::PreCreateForController(this, context());
1472 provider_host_ = pending_provider_host_->AsWeakPtr();
1473
1468 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); 1474 auto params = base::MakeUnique<EmbeddedWorkerStartParams>();
1469 params->service_worker_version_id = version_id_; 1475 params->service_worker_version_id = version_id_;
1470 params->scope = scope_; 1476 params->scope = scope_;
1471 params->script_url = script_url_; 1477 params->script_url = script_url_;
1472 params->is_installed = IsInstalled(status_); 1478 params->is_installed = IsInstalled(status_);
1473 params->pause_after_download = pause_after_download_; 1479 params->pause_after_download = pause_after_download_;
1474 1480
1475 embedded_worker_->Start( 1481 embedded_worker_->Start(
1476 std::move(params), mojo::MakeRequest(&event_dispatcher_), 1482 std::move(params), pending_provider_host_->AsWeakPtr(),
1483 mojo::MakeRequest(&event_dispatcher_),
1477 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 1484 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
1478 weak_factory_.GetWeakPtr())); 1485 weak_factory_.GetWeakPtr()));
1479 event_dispatcher_.set_connection_error_handler(base::Bind( 1486 event_dispatcher_.set_connection_error_handler(base::Bind(
1480 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr())); 1487 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr()));
1481 } 1488 }
1482 1489
1483 void ServiceWorkerVersion::StartTimeoutTimer() { 1490 void ServiceWorkerVersion::StartTimeoutTimer() {
1484 DCHECK(!timeout_timer_.IsRunning()); 1491 DCHECK(!timeout_timer_.IsRunning());
1485 1492
1486 if (embedded_worker_->devtools_attached()) { 1493 if (embedded_worker_->devtools_attached()) {
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 1854
1848 void ServiceWorkerVersion::CleanUpExternalRequest( 1855 void ServiceWorkerVersion::CleanUpExternalRequest(
1849 const std::string& request_uuid, 1856 const std::string& request_uuid,
1850 ServiceWorkerStatusCode status) { 1857 ServiceWorkerStatusCode status) {
1851 if (status == SERVICE_WORKER_OK) 1858 if (status == SERVICE_WORKER_OK)
1852 return; 1859 return;
1853 external_request_uuid_to_request_id_.erase(request_uuid); 1860 external_request_uuid_to_request_id_.erase(request_uuid);
1854 } 1861 }
1855 1862
1856 } // namespace content 1863 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698