Chromium Code Reviews| Index: content/browser/background_sync/background_sync_registration_handle.cc |
| diff --git a/content/browser/background_sync/background_sync_registration_handle.cc b/content/browser/background_sync/background_sync_registration_handle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..992e16e93bb5843e38e0ec0d9e0b49cc55604024 |
| --- /dev/null |
| +++ b/content/browser/background_sync/background_sync_registration_handle.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/background_sync/background_sync_registration_handle.h" |
| + |
| +#include "content/browser/background_sync/background_sync_manager.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace content { |
| + |
| +BackgroundSyncRegistrationHandle::BackgroundSyncRegistrationHandle( |
| + base::WeakPtr<BackgroundSyncManager> background_sync_manager, |
| + HandleId handle_id) |
| + : background_sync_manager_(background_sync_manager), |
| + handle_id_(handle_id), |
| + registration_( |
| + background_sync_manager_->GetRegistrationForHandle(handle_id_)) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(background_sync_manager_); |
| +} |
| + |
| +BackgroundSyncRegistrationHandle::~BackgroundSyncRegistrationHandle() { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (IsValid() && background_sync_manager_) |
| + background_sync_manager_->ReleaseRegistrationHandle(handle_id_); |
| +} |
| + |
| +void BackgroundSyncRegistrationHandle::Unregister( |
| + int64_t sw_registration_id, |
| + const StatusCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(IsValid()); |
| + DCHECK(background_sync_manager_); |
| + |
| + background_sync_manager_->Unregister( |
| + sw_registration_id, options()->periodicity, handle_id_, callback); |
| +} |
| + |
| +bool BackgroundSyncRegistrationHandle::IsValid() const { |
| + return registration_ != nullptr; |
|
michaeln
2015/08/28 02:53:11
maybe test background_sync_mgr_ && registration_
|
| +} |
| + |
| +} // namespace content |