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. NotifyWhenDone should only be called for |
| 54 // SYNC_ONE_SHOT registrations. |
| 55 void NotifyWhenDone(const StatusAndStateCallback& callback); |
| 56 |
45 // Returns true if the handle is backed by a BackgroundSyncRegistration in the | 57 // Returns true if the handle is backed by a BackgroundSyncRegistration in the |
46 // BackgroundSyncManager. | 58 // BackgroundSyncManager. |
47 bool IsValid() const; | 59 bool IsValid() const; |
48 | 60 |
49 HandleId handle_id() const { return handle_id_; } | 61 HandleId handle_id() const { return handle_id_; } |
50 | 62 |
51 private: | 63 private: |
52 friend class BackgroundSyncManager; | 64 friend class BackgroundSyncManager; |
53 | 65 |
54 BackgroundSyncRegistrationHandle( | 66 BackgroundSyncRegistrationHandle( |
(...skipping 16 matching lines...) Expand all Loading... |
71 // This is owned by background_sync_manager_ and is valid until handle_id_ is | 83 // 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. | 84 // released in the destructor or background_sync_manager_ has been destroyed. |
73 BackgroundSyncRegistration* registration_; | 85 BackgroundSyncRegistration* registration_; |
74 | 86 |
75 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); | 87 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); |
76 }; | 88 }; |
77 | 89 |
78 } // namespace | 90 } // namespace |
79 | 91 |
80 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H
_ | 92 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H
_ |
OLD | NEW |