Remove the 'gyp_config' concept from MB.
[chromium-blink-merge.git] / content / browser / background_sync / background_sync_registration_handle.h
bloba9a7305ede79ba29d5e2f5340869eee9789f3003
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.
5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_
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"
15 namespace content {
17 class BackgroundSyncManager;
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)>;
29 ~BackgroundSyncRegistrationHandle();
31 const BackgroundSyncRegistrationOptions* options() const {
32 DCHECK(background_sync_manager_);
33 return registration_->options();
36 SyncState sync_state() const {
37 DCHECK(background_sync_manager_);
38 return registration_->sync_state();
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);
45 // Returns true if the handle is backed by a BackgroundSyncRegistration in the
46 // BackgroundSyncManager.
47 bool IsValid() const;
49 HandleId handle_id() const { return handle_id_; }
51 private:
52 friend class BackgroundSyncManager;
54 BackgroundSyncRegistrationHandle(
55 base::WeakPtr<BackgroundSyncManager> background_sync_manager,
56 HandleId handle_id);
58 BackgroundSyncRegistration* registration() {
59 DCHECK(background_sync_manager_);
60 return registration_;
63 // The BackgroundSyncManager is expected to remain alive for all operations
64 // except for possibly at destruction.
65 base::WeakPtr<BackgroundSyncManager> background_sync_manager_;
67 // Each BackgroundSyncRegistrationHandle is assigned a unique handle id.
68 // The BackgroundSyncManager maps the id to an internal pointer.
69 HandleId handle_id_;
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_;
75 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistrationHandle);
78 } // namespace
80 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_HANDLE_H_