Chromium Code Reviews| 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 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/background_sync/background_sync_registration.h" | 11 #include "content/browser/background_sync/background_sync_registration.h" |
| 12 #include "content/browser/background_sync/background_sync_status.h" | 12 #include "content/browser/background_sync/background_sync_status.h" |
| 13 #include "content/common/background_sync_service.mojom.h" | |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 class BackgroundSyncManager; | 18 class BackgroundSyncManager; |
| 18 | 19 |
| 19 // Handle to BackgroundSyncRegistration that is exposed to clients. Each | 20 // Handle to BackgroundSyncRegistration that is exposed to clients. Each |
| 20 // BackgroundSyncRegistrationHandle is given a unique handle id (by the | 21 // BackgroundSyncRegistrationHandle is given a unique handle id (by the |
| 21 // BackgroundSyncManager) which is released at destruction. | 22 // BackgroundSyncManager) which is released at destruction. |
| 22 // BackgroundSyncRegistrationHandle objects must not be used (but may be | 23 // BackgroundSyncRegistrationHandle objects must not be used (but may be |
| 23 // destroyed) after the BackgroundSyncManager has been deleted. | 24 // destroyed) after the BackgroundSyncManager has been deleted. |
| 24 class CONTENT_EXPORT BackgroundSyncRegistrationHandle { | 25 class CONTENT_EXPORT BackgroundSyncRegistrationHandle { |
| 25 public: | 26 public: |
| 26 using HandleId = int; | 27 using HandleId = int; |
| 27 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; | 28 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; |
| 29 using StatusAndStateCallback = | |
| 30 base::Callback<void(BackgroundSyncStatus, BackgroundSyncState)>; | |
| 28 | 31 |
| 29 ~BackgroundSyncRegistrationHandle(); | 32 ~BackgroundSyncRegistrationHandle(); |
| 30 | 33 |
| 31 const BackgroundSyncRegistrationOptions* options() const { | 34 const BackgroundSyncRegistrationOptions* options() const { |
| 32 DCHECK(background_sync_manager_); | 35 DCHECK(background_sync_manager_); |
| 33 return registration_->options(); | 36 return registration_->options(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 BackgroundSyncState sync_state() const { | 39 BackgroundSyncState sync_state() const { |
| 37 DCHECK(background_sync_manager_); | 40 DCHECK(background_sync_manager_); |
| 38 return registration_->sync_state(); | 41 return registration_->sync_state(); |
| 39 } | 42 } |
| 40 | 43 |
| 41 // Unregisters the background sync registration. Calls |callback| | 44 // Unregisters the background sync registration. Calls |callback| |
| 42 // with BACKGROUND_SYNC_STATUS_OK if it succeeds. | 45 // with BACKGROUND_SYNC_STATUS_OK if it succeeds. |
| 43 void Unregister(int64_t service_worker_id, const StatusCallback& callback); | 46 void Unregister(int64_t service_worker_id, const StatusCallback& callback); |
| 44 | 47 |
| 48 // Runs |callback| when the registration associated with |handle_id| | |
| 49 // completes.The provided status is BACKGROUND_SYNC_STATUS_OK if the operation | |
| 50 // succeeded. The provided state is BACKGROUND_SYNC_STATE_SUCCESS on success, | |
| 51 // BACKGRUOND_SYNC_STATE_FAILED on final failure, and | |
| 52 // BACKGROUND_SYNC_STATE_UNREGISTERED if the registration was unregistered | |
| 53 // before it could complete. | |
|
michaeln
2015/09/17 21:44:12
maybe comment about what "done" means in the conte
jkarlin
2015/09/18 12:03:19
Done. Added comment and DCHECK to say that this is
| |
| 54 void NotifyWhenDone(const StatusAndStateCallback& callback); | |
| 55 | |
| 45 // Returns true if the handle is backed by a BackgroundSyncRegistration in the | 56 // Returns true if the handle is backed by a BackgroundSyncRegistration in the |
| 46 // BackgroundSyncManager. | 57 // BackgroundSyncManager. |
| 47 bool IsValid() const; | 58 bool IsValid() const; |
| 48 | 59 |
| 49 HandleId handle_id() const { return handle_id_; } | 60 HandleId handle_id() const { return handle_id_; } |
| 50 | 61 |
| 51 private: | 62 private: |
| 52 friend class BackgroundSyncManager; | 63 friend class BackgroundSyncManager; |
| 53 | 64 |
| 54 BackgroundSyncRegistrationHandle( | 65 BackgroundSyncRegistrationHandle( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 71 // This is owned by background_sync_manager_ and is valid until handle_id_ is | 82 // 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. | 83 // released in the destructor or background_sync_manager_ has been destroyed. |
| 73 BackgroundSyncRegistration* registration_; | 84 BackgroundSyncRegistration* registration_; |
| 74 | 85 |
| 75 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); | 86 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); |
| 76 }; | 87 }; |
| 77 | 88 |
| 78 } // namespace | 89 } // namespace |
| 79 | 90 |
| 80 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H _ | 91 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H _ |
| OLD | NEW |