| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/background_sync/ServiceWorkerRegistrationSync.h" | 5 #include "modules/background_sync/ServiceWorkerRegistrationSync.h" |
| 6 | 6 |
| 7 #include "modules/background_sync/SyncManager.h" | 7 #include "modules/background_sync/SyncManager.h" |
| 8 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 8 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 ServiceWorkerRegistrationSync::ServiceWorkerRegistrationSync( | 12 ServiceWorkerRegistrationSync::ServiceWorkerRegistrationSync( |
| 13 ServiceWorkerRegistration* registration) | 13 ServiceWorkerRegistration& registration) |
| 14 : m_registration(registration) {} | 14 : Supplement<ServiceWorkerRegistration>(registration) {} |
| 15 | 15 |
| 16 ServiceWorkerRegistrationSync::~ServiceWorkerRegistrationSync() {} | 16 ServiceWorkerRegistrationSync::~ServiceWorkerRegistrationSync() {} |
| 17 | 17 |
| 18 const char* ServiceWorkerRegistrationSync::supplementName() { | 18 const char* ServiceWorkerRegistrationSync::supplementName() { |
| 19 return "ServiceWorkerRegistrationSync"; | 19 return "ServiceWorkerRegistrationSync"; |
| 20 } | 20 } |
| 21 | 21 |
| 22 ServiceWorkerRegistrationSync& ServiceWorkerRegistrationSync::from( | 22 ServiceWorkerRegistrationSync& ServiceWorkerRegistrationSync::from( |
| 23 ServiceWorkerRegistration& registration) { | 23 ServiceWorkerRegistration& registration) { |
| 24 ServiceWorkerRegistrationSync* supplement = | 24 ServiceWorkerRegistrationSync* supplement = |
| 25 static_cast<ServiceWorkerRegistrationSync*>( | 25 static_cast<ServiceWorkerRegistrationSync*>( |
| 26 Supplement<ServiceWorkerRegistration>::from(registration, | 26 Supplement<ServiceWorkerRegistration>::from(registration, |
| 27 supplementName())); | 27 supplementName())); |
| 28 if (!supplement) { | 28 if (!supplement) { |
| 29 supplement = new ServiceWorkerRegistrationSync(®istration); | 29 supplement = new ServiceWorkerRegistrationSync(registration); |
| 30 provideTo(registration, supplementName(), supplement); | 30 provideTo(registration, supplementName(), supplement); |
| 31 } | 31 } |
| 32 return *supplement; | 32 return *supplement; |
| 33 } | 33 } |
| 34 | 34 |
| 35 SyncManager* ServiceWorkerRegistrationSync::sync( | 35 SyncManager* ServiceWorkerRegistrationSync::sync( |
| 36 ServiceWorkerRegistration& registration) { | 36 ServiceWorkerRegistration& registration) { |
| 37 return ServiceWorkerRegistrationSync::from(registration).sync(); | 37 return ServiceWorkerRegistrationSync::from(registration).sync(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 SyncManager* ServiceWorkerRegistrationSync::sync() { | 40 SyncManager* ServiceWorkerRegistrationSync::sync() { |
| 41 if (!m_syncManager) | 41 if (!m_syncManager) |
| 42 m_syncManager = SyncManager::create(m_registration); | 42 m_syncManager = SyncManager::create(supplementable()); |
| 43 return m_syncManager.get(); | 43 return m_syncManager.get(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 DEFINE_TRACE(ServiceWorkerRegistrationSync) { | 46 DEFINE_TRACE(ServiceWorkerRegistrationSync) { |
| 47 visitor->trace(m_registration); | |
| 48 visitor->trace(m_syncManager); | 47 visitor->trace(m_syncManager); |
| 49 Supplement<ServiceWorkerRegistration>::trace(visitor); | 48 Supplement<ServiceWorkerRegistration>::trace(visitor); |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace blink | 51 } // namespace blink |
| OLD | NEW |