OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "content/browser/background_sync/background_sync_registration.h" |
| 11 #include "content/browser/background_sync/background_sync_status.h" |
| 12 #include "content/common/content_export.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class BackgroundSyncManager; |
| 17 |
| 18 // Handle to BackgroundSyncRegistration that is exposed to clients. Each |
| 19 // BackgroundSyncRegistrationHandle is given a unique handle id (by the |
| 20 // BackgroundSyncManager) which is released at destruction. |
| 21 // BackgroundSyncRegistrationHandle objects must not be used (but may be |
| 22 // destroyed) after the BackgroundSyncManager has been deleted. |
| 23 class CONTENT_EXPORT BackgroundSyncRegistrationHandle { |
| 24 public: |
| 25 using HandleId = int; |
| 26 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; |
| 27 |
| 28 BackgroundSyncRegistrationHandle( |
| 29 base::WeakPtr<BackgroundSyncManager> background_sync_manager, |
| 30 HandleId handle_id); |
| 31 ~BackgroundSyncRegistrationHandle(); |
| 32 |
| 33 const BackgroundSyncRegistrationOptions* options() const { |
| 34 DCHECK(background_sync_manager_); |
| 35 return registration_->options(); |
| 36 } |
| 37 |
| 38 SyncState sync_state() const { |
| 39 DCHECK(background_sync_manager_); |
| 40 return registration_->sync_state(); |
| 41 } |
| 42 |
| 43 // Unregisters the background sync registration. Calls |callback| |
| 44 // with BACKGROUND_SYNC_STATUS_OK if it succeeds. |
| 45 void Unregister(int64_t service_worker_id, const StatusCallback& callback); |
| 46 |
| 47 // Returns true if the handle is backed by a BackgroundSyncRegistration in the |
| 48 // BackgroundSyncManager. |
| 49 bool IsValid() const; |
| 50 |
| 51 HandleId handle_id() const { return handle_id_; } |
| 52 |
| 53 private: |
| 54 friend class BackgroundSyncManager; |
| 55 |
| 56 BackgroundSyncRegistration* registration() { |
| 57 DCHECK(background_sync_manager_); |
| 58 return registration_; |
| 59 } |
| 60 |
| 61 // The BackgroundSyncManager is expected to remain alive for all operations |
| 62 // except for possibly at destruction. |
| 63 base::WeakPtr<BackgroundSyncManager> background_sync_manager_; |
| 64 |
| 65 // Each BackgroundSyncRegistrationHandle is assigned a unique handle id. |
| 66 // The BackgroundSyncManager maps the id to an internal pointer. |
| 67 HandleId handle_id_; |
| 68 |
| 69 // This is owned by background_sync_manager_ and is valid until handle_id_ is |
| 70 // released in the destructor or background_sync_manager_ has been destroyed. |
| 71 BackgroundSyncRegistration* registration_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); |
| 74 }; |
| 75 |
| 76 } // namespace |
| 77 |
| 78 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H
_ |
OLD | NEW |