| 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/stl_util.h" | 
|  | 8 #include "content/browser/service_worker/embedded_worker_instance.h" | 
|  | 9 #include "content/browser/service_worker/embedded_worker_registry.h" | 
|  | 10 #include "content/browser/service_worker/service_worker_context_core.h" | 
| 7 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" | 
| 8 | 12 | 
| 9 namespace content { | 13 namespace content { | 
| 10 | 14 | 
| 11 ServiceWorkerVersion::ServiceWorkerVersion( | 15 ServiceWorkerVersion::ServiceWorkerVersion( | 
| 12     ServiceWorkerRegistration* registration) | 16     ServiceWorkerRegistration* registration, | 
| 13     : is_shutdown_(false), registration_(registration) {} | 17     EmbeddedWorkerRegistry* worker_registry, | 
|  | 18     int64 version_id) | 
|  | 19     : version_id_(version_id), | 
|  | 20       is_shutdown_(false), | 
|  | 21       registration_(registration) { | 
|  | 22   if (worker_registry) | 
|  | 23     embedded_worker_ = worker_registry->CreateWorker(); | 
|  | 24 } | 
| 14 | 25 | 
| 15 ServiceWorkerVersion::~ServiceWorkerVersion() { DCHECK(is_shutdown_); } | 26 ServiceWorkerVersion::~ServiceWorkerVersion() { DCHECK(is_shutdown_); } | 
| 16 | 27 | 
| 17 void ServiceWorkerVersion::Shutdown() { | 28 void ServiceWorkerVersion::Shutdown() { | 
| 18   is_shutdown_ = true; | 29   is_shutdown_ = true; | 
| 19   registration_ = NULL; | 30   registration_ = NULL; | 
|  | 31   embedded_worker_.reset(); | 
|  | 32 } | 
|  | 33 | 
|  | 34 void ServiceWorkerVersion::StartWorker() { | 
|  | 35   DCHECK(!is_shutdown_); | 
|  | 36   DCHECK(registration_); | 
|  | 37   embedded_worker_->Start(version_id_, registration_->script_url()); | 
|  | 38 } | 
|  | 39 | 
|  | 40 void ServiceWorkerVersion::StopWorker() { | 
|  | 41   DCHECK(!is_shutdown_); | 
|  | 42   embedded_worker_->Stop(); | 
|  | 43 } | 
|  | 44 | 
|  | 45 void ServiceWorkerVersion::OnAssociateProvider( | 
|  | 46     ServiceWorkerProviderHost* provider_host) { | 
|  | 47   DCHECK(!is_shutdown_); | 
|  | 48   embedded_worker_->AddProcessReference(provider_host->process_id()); | 
|  | 49 } | 
|  | 50 | 
|  | 51 void ServiceWorkerVersion::OnUnassociateProvider( | 
|  | 52     ServiceWorkerProviderHost* provider_host) { | 
|  | 53   embedded_worker_->ReleaseProcessReference(provider_host->process_id()); | 
| 20 } | 54 } | 
| 21 | 55 | 
| 22 }  // namespace content | 56 }  // namespace content | 
| OLD | NEW | 
|---|