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_
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"
21 class CONTENT_EXPORT BackgroundSyncRegistration
{
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;
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
; }
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
64 TypeConverter
<scoped_ptr
<content::BackgroundSyncRegistration
>,
65 content::SyncRegistrationPtr
> {
66 static scoped_ptr
<content::BackgroundSyncRegistration
> Convert(
67 const content::SyncRegistrationPtr
& input
);
71 struct CONTENT_EXPORT TypeConverter
<content::SyncRegistrationPtr
,
72 content::BackgroundSyncRegistration
> {
73 static content::SyncRegistrationPtr
Convert(
74 const content::BackgroundSyncRegistration
& input
);
79 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_