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