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