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

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

Issue 2958753003: Revert "Create ServiceWorkerProviderHost before starting worker" (Closed)
Patch Set: Created 3 years, 5 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // renderer shutdown like crash. 194 // renderer shutdown like crash.
195 embedded_worker->Detach(); 195 embedded_worker->Detach();
196 break; 196 break;
197 case EmbeddedWorkerStatus::STOPPING: 197 case EmbeddedWorkerStatus::STOPPING:
198 case EmbeddedWorkerStatus::STOPPED: 198 case EmbeddedWorkerStatus::STOPPED:
199 // Do nothing 199 // Do nothing
200 break; 200 break;
201 } 201 }
202 } 202 }
203 203
204 mojom::ServiceWorkerProviderInfoForStartWorkerPtr
205 CompleteProviderHostPreparation(
206 ServiceWorkerVersion* version,
207 std::unique_ptr<ServiceWorkerProviderHost> provider_host,
208 base::WeakPtr<ServiceWorkerContextCore> context,
209 int process_id) {
210 // Caller should ensure |context| is alive when completing StartWorker
211 // preparation.
212 DCHECK(context);
213 auto info =
214 provider_host->CompleteStartWorkerPreparation(process_id, version);
215 context->AddProviderHost(std::move(provider_host));
216 return info;
217 }
218
219 } // namespace 204 } // namespace
220 205
221 constexpr base::TimeDelta ServiceWorkerVersion::kTimeoutTimerDelay; 206 constexpr base::TimeDelta ServiceWorkerVersion::kTimeoutTimerDelay;
222 constexpr base::TimeDelta ServiceWorkerVersion::kStartNewWorkerTimeout; 207 constexpr base::TimeDelta ServiceWorkerVersion::kStartNewWorkerTimeout;
223 constexpr base::TimeDelta ServiceWorkerVersion::kStopWorkerTimeout; 208 constexpr base::TimeDelta ServiceWorkerVersion::kStopWorkerTimeout;
224 209
225 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const { 210 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const {
226 *time = tick_clock_->NowTicks(); 211 *time = tick_clock_->NowTicks();
227 } 212 }
228 213
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 ServiceWorkerMetrics::EventType event_type) 833 ServiceWorkerMetrics::EventType event_type)
849 : error_callback(callback), 834 : error_callback(callback),
850 start_time(time), 835 start_time(time),
851 start_time_ticks(time_ticks), 836 start_time_ticks(time_ticks),
852 event_type(event_type) {} 837 event_type(event_type) {}
853 838
854 ServiceWorkerVersion::PendingRequest::~PendingRequest() {} 839 ServiceWorkerVersion::PendingRequest::~PendingRequest() {}
855 840
856 void ServiceWorkerVersion::OnThreadStarted() { 841 void ServiceWorkerVersion::OnThreadStarted() {
857 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status()); 842 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status());
858 DCHECK(provider_host_);
859 provider_host_->SetReadyToSendMessagesToWorker(
860 embedded_worker()->thread_id());
861 // Activate ping/pong now that JavaScript execution will start. 843 // Activate ping/pong now that JavaScript execution will start.
862 ping_controller_->Activate(); 844 ping_controller_->Activate();
863 } 845 }
864 846
865 void ServiceWorkerVersion::OnStarting() { 847 void ServiceWorkerVersion::OnStarting() {
866 for (auto& observer : listeners_) 848 for (auto& observer : listeners_)
867 observer.OnRunningStateChanged(this); 849 observer.OnRunningStateChanged(this);
868 } 850 }
869 851
870 void ServiceWorkerVersion::OnStarted() { 852 void ServiceWorkerVersion::OnStarted() {
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status()); 1451 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status());
1470 1452
1471 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) { 1453 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) {
1472 DCHECK(!event_recorder_); 1454 DCHECK(!event_recorder_);
1473 event_recorder_ = 1455 event_recorder_ =
1474 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>(); 1456 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>();
1475 } 1457 }
1476 1458
1477 StartTimeoutTimer(); 1459 StartTimeoutTimer();
1478 1460
1479 std::unique_ptr<ServiceWorkerProviderHost> pending_provider_host =
1480 ServiceWorkerProviderHost::PreCreateForController(context());
1481 provider_host_ = pending_provider_host->AsWeakPtr();
1482
1483 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); 1461 auto params = base::MakeUnique<EmbeddedWorkerStartParams>();
1484 params->service_worker_version_id = version_id_; 1462 params->service_worker_version_id = version_id_;
1485 params->scope = scope_; 1463 params->scope = scope_;
1486 params->script_url = script_url_; 1464 params->script_url = script_url_;
1487 params->is_installed = IsInstalled(status_); 1465 params->is_installed = IsInstalled(status_);
1488 params->pause_after_download = pause_after_download_; 1466 params->pause_after_download = pause_after_download_;
1489 1467
1490 embedded_worker_->Start( 1468 embedded_worker_->Start(
1491 std::move(params), 1469 std::move(params), mojo::MakeRequest(&event_dispatcher_),
1492 // Unretained is used here because the callback will be owned by
1493 // |embedded_worker_| whose owner is |this|.
1494 base::BindOnce(&CompleteProviderHostPreparation, base::Unretained(this),
1495 base::Passed(&pending_provider_host), context()),
1496 mojo::MakeRequest(&event_dispatcher_),
1497 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 1470 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
1498 weak_factory_.GetWeakPtr())); 1471 weak_factory_.GetWeakPtr()));
1499 event_dispatcher_.set_connection_error_handler(base::Bind( 1472 event_dispatcher_.set_connection_error_handler(base::Bind(
1500 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr())); 1473 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr()));
1501 } 1474 }
1502 1475
1503 void ServiceWorkerVersion::StartTimeoutTimer() { 1476 void ServiceWorkerVersion::StartTimeoutTimer() {
1504 DCHECK(!timeout_timer_.IsRunning()); 1477 DCHECK(!timeout_timer_.IsRunning());
1505 1478
1506 if (embedded_worker_->devtools_attached()) { 1479 if (embedded_worker_->devtools_attached()) {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 1846
1874 void ServiceWorkerVersion::CleanUpExternalRequest( 1847 void ServiceWorkerVersion::CleanUpExternalRequest(
1875 const std::string& request_uuid, 1848 const std::string& request_uuid,
1876 ServiceWorkerStatusCode status) { 1849 ServiceWorkerStatusCode status) {
1877 if (status == SERVICE_WORKER_OK) 1850 if (status == SERVICE_WORKER_OK)
1878 return; 1851 return;
1879 external_request_uuid_to_request_id_.erase(request_uuid); 1852 external_request_uuid_to_request_id_.erase(request_uuid);
1880 } 1853 }
1881 1854
1882 } // namespace content 1855 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698