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 // *_STATE_FAILED on final failure, and *_STATE_UNREGISTERED if the | |
iclelland
2015/09/17 13:48:09
Is * just 'tired of typing', or does it match some
jkarlin
2015/09/17 17:40:25
Done.
| |
52 // registration was unregistered before it could complete. | |
53 void NotifyWhenDone(const StatusAndStateCallback& callback); | |
54 | |
45 // Returns true if the handle is backed by a BackgroundSyncRegistration in the | 55 // Returns true if the handle is backed by a BackgroundSyncRegistration in the |
46 // BackgroundSyncManager. | 56 // BackgroundSyncManager. |
47 bool IsValid() const; | 57 bool IsValid() const; |
48 | 58 |
49 HandleId handle_id() const { return handle_id_; } | 59 HandleId handle_id() const { return handle_id_; } |
50 | 60 |
51 private: | 61 private: |
52 friend class BackgroundSyncManager; | 62 friend class BackgroundSyncManager; |
53 | 63 |
54 BackgroundSyncRegistrationHandle( | 64 BackgroundSyncRegistrationHandle( |
(...skipping 16 matching lines...) Expand all Loading... | |
71 // This is owned by background_sync_manager_ and is valid until handle_id_ is | 81 // 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. | 82 // released in the destructor or background_sync_manager_ has been destroyed. |
73 BackgroundSyncRegistration* registration_; | 83 BackgroundSyncRegistration* registration_; |
74 | 84 |
75 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); | 85 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle); |
76 }; | 86 }; |
77 | 87 |
78 } // namespace | 88 } // namespace |
79 | 89 |
80 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H _ | 90 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H _ |
OLD | NEW |