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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 enum PingState { NOT_PINGING, PINGING, PING_TIMED_OUT }; | 464 enum PingState { NOT_PINGING, PINGING, PING_TIMED_OUT }; |
465 ServiceWorkerVersion* version_; // Not owned. | 465 ServiceWorkerVersion* version_; // Not owned. |
466 base::TimeTicks ping_time_; | 466 base::TimeTicks ping_time_; |
467 PingState ping_state_ = NOT_PINGING; | 467 PingState ping_state_ = NOT_PINGING; |
468 DISALLOW_COPY_AND_ASSIGN(PingController); | 468 DISALLOW_COPY_AND_ASSIGN(PingController); |
469 }; | 469 }; |
470 | 470 |
471 ServiceWorkerVersion::ServiceWorkerVersion( | 471 ServiceWorkerVersion::ServiceWorkerVersion( |
472 ServiceWorkerRegistration* registration, | 472 ServiceWorkerRegistration* registration, |
473 const GURL& script_url, | 473 const GURL& script_url, |
474 int64 version_id, | 474 std::string version_uuid, |
475 base::WeakPtr<ServiceWorkerContextCore> context) | 475 base::WeakPtr<ServiceWorkerContextCore> context) |
476 : version_id_(version_id), | 476 : version_uuid_(version_uuid), |
477 registration_id_(registration->id()), | 477 registration_id_(registration->id()), |
478 script_url_(script_url), | 478 script_url_(script_url), |
479 scope_(registration->pattern()), | 479 scope_(registration->pattern()), |
480 context_(context), | 480 context_(context), |
481 script_cache_map_(this, context), | 481 script_cache_map_(this, context), |
482 ping_controller_(new PingController(this)), | 482 ping_controller_(new PingController(this)), |
483 metrics_(new Metrics), | 483 metrics_(new Metrics), |
484 weak_factory_(this) { | 484 weak_factory_(this) { |
485 DCHECK(context_); | 485 DCHECK(context_); |
486 DCHECK(registration); | 486 DCHECK(registration); |
487 context_->AddLiveVersion(this); | 487 context_->AddLiveVersion(this); |
488 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 488 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
489 embedded_worker_->AddListener(this); | 489 embedded_worker_->AddListener(this); |
490 } | 490 } |
491 | 491 |
492 ServiceWorkerVersion::~ServiceWorkerVersion() { | 492 ServiceWorkerVersion::~ServiceWorkerVersion() { |
493 // The user may have closed the tab waiting for SW to start up. | 493 // The user may have closed the tab waiting for SW to start up. |
494 if (GetTickDuration(start_time_) > | 494 if (GetTickDuration(start_time_) > |
495 base::TimeDelta::FromSeconds( | 495 base::TimeDelta::FromSeconds( |
496 kDestructedStartingWorkerTimeoutThresholdSeconds)) { | 496 kDestructedStartingWorkerTimeoutThresholdSeconds)) { |
497 DCHECK(timeout_timer_.IsRunning()); | 497 DCHECK(timeout_timer_.IsRunning()); |
498 DCHECK(!embedded_worker_->devtools_attached()); | 498 DCHECK(!embedded_worker_->devtools_attached()); |
499 RecordStartWorkerResult(SERVICE_WORKER_ERROR_TIMEOUT); | 499 RecordStartWorkerResult(SERVICE_WORKER_ERROR_TIMEOUT); |
500 } | 500 } |
501 | 501 |
502 if (context_) | 502 if (context_) |
503 context_->RemoveLiveVersion(version_id_); | 503 context_->RemoveLiveVersion(version_uuid_); |
504 | 504 |
505 if (running_status() == STARTING || running_status() == RUNNING) | 505 if (running_status() == STARTING || running_status() == RUNNING) |
506 embedded_worker_->Stop(); | 506 embedded_worker_->Stop(); |
507 embedded_worker_->RemoveListener(this); | 507 embedded_worker_->RemoveListener(this); |
508 } | 508 } |
509 | 509 |
510 void ServiceWorkerVersion::SetStatus(Status status) { | 510 void ServiceWorkerVersion::SetStatus(Status status) { |
511 if (status_ == status) | 511 if (status_ == status) |
512 return; | 512 return; |
513 | 513 |
(...skipping 14 matching lines...) Expand all Loading... |
528 } | 528 } |
529 | 529 |
530 void ServiceWorkerVersion::RegisterStatusChangeCallback( | 530 void ServiceWorkerVersion::RegisterStatusChangeCallback( |
531 const base::Closure& callback) { | 531 const base::Closure& callback) { |
532 status_change_callbacks_.push_back(callback); | 532 status_change_callbacks_.push_back(callback); |
533 } | 533 } |
534 | 534 |
535 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { | 535 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { |
536 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 536 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
537 ServiceWorkerVersionInfo info( | 537 ServiceWorkerVersionInfo info( |
538 running_status(), status(), script_url(), registration_id(), version_id(), | 538 running_status(), status(), script_url(), registration_id(), |
539 embedded_worker()->process_id(), embedded_worker()->thread_id(), | 539 version_uuid(), embedded_worker()->process_id(), |
| 540 embedded_worker()->thread_id(), |
540 embedded_worker()->worker_devtools_agent_route_id()); | 541 embedded_worker()->worker_devtools_agent_route_id()); |
541 for (const auto& controllee : controllee_map_) { | 542 for (const auto& controllee : controllee_map_) { |
542 const ServiceWorkerProviderHost* host = controllee.second; | 543 const ServiceWorkerProviderHost* host = controllee.second; |
543 info.clients.insert(std::make_pair( | 544 info.clients.insert(std::make_pair( |
544 host->client_uuid(), | 545 host->client_uuid(), |
545 ServiceWorkerVersionInfo::ClientInfo( | 546 ServiceWorkerVersionInfo::ClientInfo( |
546 host->process_id(), host->route_id(), host->provider_type()))); | 547 host->process_id(), host->route_id(), host->provider_type()))); |
547 } | 548 } |
548 if (!main_script_http_info_) | 549 if (!main_script_http_info_) |
549 return info; | 550 return info; |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 StartWorkerInternal(pause_after_download); | 1753 StartWorkerInternal(pause_after_download); |
1753 return; | 1754 return; |
1754 } | 1755 } |
1755 } | 1756 } |
1756 | 1757 |
1757 void ServiceWorkerVersion::StartWorkerInternal(bool pause_after_download) { | 1758 void ServiceWorkerVersion::StartWorkerInternal(bool pause_after_download) { |
1758 if (!timeout_timer_.IsRunning()) | 1759 if (!timeout_timer_.IsRunning()) |
1759 StartTimeoutTimer(); | 1760 StartTimeoutTimer(); |
1760 if (running_status() == STOPPED) { | 1761 if (running_status() == STOPPED) { |
1761 embedded_worker_->Start( | 1762 embedded_worker_->Start( |
1762 version_id_, scope_, script_url_, pause_after_download, | 1763 version_uuid_, scope_, script_url_, pause_after_download, |
1763 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1764 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
1764 weak_factory_.GetWeakPtr())); | 1765 weak_factory_.GetWeakPtr())); |
1765 } | 1766 } |
1766 } | 1767 } |
1767 | 1768 |
1768 void ServiceWorkerVersion::GetWindowClients( | 1769 void ServiceWorkerVersion::GetWindowClients( |
1769 int request_id, | 1770 int request_id, |
1770 const ServiceWorkerClientQueryOptions& options) { | 1771 const ServiceWorkerClientQueryOptions& options) { |
1771 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || | 1772 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || |
1772 options.client_type == blink::WebServiceWorkerClientTypeAll); | 1773 options.client_type == blink::WebServiceWorkerClientTypeAll); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 } | 2101 } |
2101 | 2102 |
2102 void ServiceWorkerVersion::FoundRegistrationForUpdate( | 2103 void ServiceWorkerVersion::FoundRegistrationForUpdate( |
2103 ServiceWorkerStatusCode status, | 2104 ServiceWorkerStatusCode status, |
2104 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 2105 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
2105 if (!context_) | 2106 if (!context_) |
2106 return; | 2107 return; |
2107 | 2108 |
2108 const scoped_refptr<ServiceWorkerVersion> protect = this; | 2109 const scoped_refptr<ServiceWorkerVersion> protect = this; |
2109 if (is_update_scheduled_) { | 2110 if (is_update_scheduled_) { |
2110 context_->UnprotectVersion(version_id_); | 2111 context_->UnprotectVersion(version_uuid_); |
2111 is_update_scheduled_ = false; | 2112 is_update_scheduled_ = false; |
2112 } | 2113 } |
2113 | 2114 |
2114 if (status != SERVICE_WORKER_OK || registration->active_version() != this) | 2115 if (status != SERVICE_WORKER_OK || registration->active_version() != this) |
2115 return; | 2116 return; |
2116 context_->UpdateServiceWorker(registration.get(), | 2117 context_->UpdateServiceWorker(registration.get(), |
2117 false /* force_bypass_cache */); | 2118 false /* force_bypass_cache */); |
2118 } | 2119 } |
2119 | 2120 |
2120 } // namespace content | 2121 } // namespace content |
OLD | NEW |