[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / background_sync / background_sync_registration.h
blob741c88850e44a316e13e0ae1cccb820d20fe2a0a
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_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_
8 #include <list>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/background_sync/background_sync.pb.h"
14 #include "content/browser/background_sync/background_sync_registration_options.h"
15 #include "content/common/background_sync_service.mojom.h"
16 #include "content/common/content_export.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h"
19 namespace content {
21 class CONTENT_EXPORT BackgroundSyncRegistration {
22 public:
23 using RegistrationId = int64_t;
24 using StateCallback = base::Callback<void(BackgroundSyncState)>;
26 static const RegistrationId kInitialId;
28 BackgroundSyncRegistration();
29 ~BackgroundSyncRegistration();
31 bool Equals(const BackgroundSyncRegistration& other) const;
32 bool IsValid() const;
33 void AddDoneCallback(const StateCallback& callback);
34 void RunDoneCallbacks();
35 bool HasCompleted() const;
37 const BackgroundSyncRegistrationOptions* options() const { return &options_; }
38 BackgroundSyncRegistrationOptions* options() { return &options_; }
40 RegistrationId id() const { return id_; }
41 void set_id(RegistrationId id) { id_ = id; }
43 BackgroundSyncState sync_state() const { return sync_state_; }
44 void set_sync_state(BackgroundSyncState state) { sync_state_ = state; }
46 private:
47 static const RegistrationId kInvalidRegistrationId;
49 BackgroundSyncRegistrationOptions options_;
50 RegistrationId id_ = kInvalidRegistrationId;
51 BackgroundSyncState sync_state_ = BACKGROUND_SYNC_STATE_PENDING;
53 std::list<StateCallback> notify_done_callbacks_;
55 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistration);
58 } // namespace content
60 namespace mojo {
62 template <>
63 struct CONTENT_EXPORT
64 TypeConverter<scoped_ptr<content::BackgroundSyncRegistration>,
65 content::SyncRegistrationPtr> {
66 static scoped_ptr<content::BackgroundSyncRegistration> Convert(
67 const content::SyncRegistrationPtr& input);
70 template <>
71 struct CONTENT_EXPORT TypeConverter<content::SyncRegistrationPtr,
72 content::BackgroundSyncRegistration> {
73 static content::SyncRegistrationPtr Convert(
74 const content::BackgroundSyncRegistration& input);
77 } // namespace
79 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_