| 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 "content/browser/background_sync/background_sync_registration_handle.h" | 5 #include "content/browser/background_sync/background_sync_registration_handle.h" |
| 6 | 6 |
| 7 #include "content/browser/background_sync/background_sync_manager.h" | 7 #include "content/browser/background_sync/background_sync_manager.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 BackgroundSyncRegistrationHandle::~BackgroundSyncRegistrationHandle() { | 12 BackgroundSyncRegistrationHandle::~BackgroundSyncRegistrationHandle() { |
| 13 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 13 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 14 if (IsValid() && background_sync_manager_) | 14 if (IsValid() && background_sync_manager_) |
| 15 background_sync_manager_->ReleaseRegistrationHandle(handle_id_); | 15 background_sync_manager_->ReleaseRegistrationHandle(handle_id_); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void BackgroundSyncRegistrationHandle::Unregister( | 18 void BackgroundSyncRegistrationHandle::Unregister( |
| 19 int64_t sw_registration_id, | 19 int64_t sw_registration_id, |
| 20 const StatusCallback& callback) { | 20 const StatusCallback& callback) { |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 21 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 22 DCHECK(IsValid()); | 22 DCHECK(IsValid()); |
| 23 DCHECK(background_sync_manager_); | 23 DCHECK(background_sync_manager_); |
| 24 | 24 |
| 25 background_sync_manager_->Unregister( | 25 background_sync_manager_->Unregister( |
| 26 sw_registration_id, options()->periodicity, handle_id_, callback); | 26 sw_registration_id, options()->periodicity, handle_id_, callback); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void BackgroundSyncRegistrationHandle::NotifyWhenDone( |
| 30 const StatusAndStateCallback& callback) { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 32 DCHECK(IsValid()); |
| 33 DCHECK(background_sync_manager_); |
| 34 |
| 35 background_sync_manager_->NotifyWhenDone(handle_id_, callback); |
| 36 } |
| 37 |
| 29 bool BackgroundSyncRegistrationHandle::IsValid() const { | 38 bool BackgroundSyncRegistrationHandle::IsValid() const { |
| 30 return registration_ != nullptr; | 39 return registration_ != nullptr; |
| 31 } | 40 } |
| 32 | 41 |
| 33 BackgroundSyncRegistrationHandle::BackgroundSyncRegistrationHandle( | 42 BackgroundSyncRegistrationHandle::BackgroundSyncRegistrationHandle( |
| 34 base::WeakPtr<BackgroundSyncManager> background_sync_manager, | 43 base::WeakPtr<BackgroundSyncManager> background_sync_manager, |
| 35 HandleId handle_id) | 44 HandleId handle_id) |
| 36 : background_sync_manager_(background_sync_manager), | 45 : background_sync_manager_(background_sync_manager), |
| 37 handle_id_(handle_id), | 46 handle_id_(handle_id), |
| 38 registration_( | 47 registration_( |
| 39 background_sync_manager_->GetRegistrationForHandle(handle_id_)) { | 48 background_sync_manager_->GetRegistrationForHandle(handle_id_)) { |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 41 DCHECK(background_sync_manager_); | 50 DCHECK(background_sync_manager_); |
| 42 } | 51 } |
| 43 | 52 |
| 44 } // namespace content | 53 } // namespace content |
| OLD | NEW |