| 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_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
| 6 | 6 |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_info.h" | 8 #include "content/browser/service_worker/service_worker_info.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 ServiceWorkerRegistration::ServiceWorkerRegistration( | 13 ServiceWorkerRegistration::ServiceWorkerRegistration( |
| 14 const GURL& pattern, | 14 const GURL& pattern, |
| 15 const GURL& script_url, | 15 const GURL& script_url, |
| 16 int64 registration_id, | 16 int64 registration_id, |
| 17 base::WeakPtr<ServiceWorkerContextCore> context) | 17 base::WeakPtr<ServiceWorkerContextCore> context) |
| 18 : pattern_(pattern), | 18 : pattern_(pattern), |
| 19 script_url_(script_url), | 19 script_url_(script_url), |
| 20 registration_id_(registration_id), | 20 registration_id_(registration_id), |
| 21 is_shutdown_(false), | 21 is_shutdown_(false), |
| 22 context_(context) { | 22 context_(context) { |
| 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 24 DCHECK(context_); | 24 DCHECK(context_); |
| 25 context_->AddLiveRegistration(this); | 25 context_->AddLiveRegistration(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 ServiceWorkerRegistration::~ServiceWorkerRegistration() { | 28 ServiceWorkerRegistration::~ServiceWorkerRegistration() { |
| 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 30 DCHECK(is_shutdown_); | |
| 31 } | |
| 32 | |
| 33 void ServiceWorkerRegistration::Shutdown() { | |
| 34 DCHECK(!is_shutdown_); | |
| 35 if (active_version_) | |
| 36 active_version_->Shutdown(); | |
| 37 active_version_ = NULL; | |
| 38 if (pending_version_) | |
| 39 pending_version_->Shutdown(); | |
| 40 pending_version_ = NULL; | |
| 41 is_shutdown_ = true; | |
| 42 if (context_) | 30 if (context_) |
| 43 context_->RemoveLiveRegistration(registration_id_); | 31 context_->RemoveLiveRegistration(registration_id_); |
| 44 } | 32 } |
| 45 | 33 |
| 46 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() { | 34 ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 48 return ServiceWorkerRegistrationInfo( | 36 return ServiceWorkerRegistrationInfo( |
| 49 script_url(), | 37 script_url(), |
| 50 pattern(), | 38 pattern(), |
| 51 active_version_ ? active_version_->GetInfo() : ServiceWorkerVersionInfo(), | 39 active_version_ ? active_version_->GetInfo() : ServiceWorkerVersionInfo(), |
| 52 pending_version_ ? pending_version_->GetInfo() | 40 pending_version_ ? pending_version_->GetInfo() |
| 53 : ServiceWorkerVersionInfo()); | 41 : ServiceWorkerVersionInfo()); |
| 54 } | 42 } |
| 55 | 43 |
| 56 ServiceWorkerVersion* ServiceWorkerRegistration::GetNewestVersion() { | 44 ServiceWorkerVersion* ServiceWorkerRegistration::GetNewestVersion() { |
| 57 if (active_version()) | 45 if (active_version()) |
| 58 return active_version(); | 46 return active_version(); |
| 59 return pending_version(); | 47 return pending_version(); |
| 60 } | 48 } |
| 61 | 49 |
| 62 void ServiceWorkerRegistration::ActivatePendingVersion() { | 50 void ServiceWorkerRegistration::ActivatePendingVersion() { |
| 63 active_version_->SetStatus(ServiceWorkerVersion::DEACTIVATED); | 51 active_version_->SetStatus(ServiceWorkerVersion::DEACTIVATED); |
| 64 active_version_->Shutdown(); | |
| 65 active_version_ = pending_version_; | 52 active_version_ = pending_version_; |
| 66 // TODO(kinuko): This should be set to ACTIVATING until activation finishes. | 53 // TODO(kinuko): This should be set to ACTIVATING until activation finishes. |
| 67 active_version_->SetStatus(ServiceWorkerVersion::ACTIVE); | 54 active_version_->SetStatus(ServiceWorkerVersion::ACTIVE); |
| 68 pending_version_ = NULL; | 55 pending_version_ = NULL; |
| 69 } | 56 } |
| 70 | 57 |
| 71 } // namespace content | 58 } // namespace content |
| OLD | NEW |