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_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ |
7 | 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/callback.h" |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "content/browser/background_sync/background_sync.pb.h" | 13 #include "content/browser/background_sync/background_sync.pb.h" |
11 #include "content/browser/background_sync/background_sync_registration_options.h
" | 14 #include "content/browser/background_sync/background_sync_registration_options.h
" |
12 #include "content/common/background_sync_service.mojom.h" | 15 #include "content/common/background_sync_service.mojom.h" |
13 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h" | 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h" |
15 | 18 |
16 namespace content { | 19 namespace content { |
17 | 20 |
18 class CONTENT_EXPORT BackgroundSyncRegistration { | 21 class CONTENT_EXPORT BackgroundSyncRegistration { |
19 public: | 22 public: |
20 using RegistrationId = int64_t; | 23 using RegistrationId = int64_t; |
| 24 using StateCallback = base::Callback<void(BackgroundSyncState)>; |
| 25 |
21 static const RegistrationId kInitialId; | 26 static const RegistrationId kInitialId; |
22 | 27 |
23 BackgroundSyncRegistration() = default; | 28 BackgroundSyncRegistration(); |
24 ~BackgroundSyncRegistration() = default; | 29 ~BackgroundSyncRegistration(); |
25 | 30 |
26 bool Equals(const BackgroundSyncRegistration& other) const; | 31 bool Equals(const BackgroundSyncRegistration& other) const; |
27 bool IsValid() const; | 32 bool IsValid() const; |
| 33 void AddDoneCallback(const StateCallback& callback); |
| 34 void RunDoneCallbacks(); |
| 35 bool HasCompleted() const; |
28 | 36 |
29 const BackgroundSyncRegistrationOptions* options() const { return &options_; } | 37 const BackgroundSyncRegistrationOptions* options() const { return &options_; } |
30 BackgroundSyncRegistrationOptions* options() { return &options_; } | 38 BackgroundSyncRegistrationOptions* options() { return &options_; } |
31 | 39 |
32 RegistrationId id() const { return id_; } | 40 RegistrationId id() const { return id_; } |
33 void set_id(RegistrationId id) { id_ = id; } | 41 void set_id(RegistrationId id) { id_ = id; } |
34 | 42 |
35 BackgroundSyncState sync_state() const { return sync_state_; } | 43 BackgroundSyncState sync_state() const { return sync_state_; } |
36 void set_sync_state(BackgroundSyncState state) { sync_state_ = state; } | 44 void set_sync_state(BackgroundSyncState state) { sync_state_ = state; } |
37 | 45 |
38 private: | 46 private: |
39 static const RegistrationId kInvalidRegistrationId; | 47 static const RegistrationId kInvalidRegistrationId; |
40 | 48 |
41 BackgroundSyncRegistrationOptions options_; | 49 BackgroundSyncRegistrationOptions options_; |
42 RegistrationId id_ = kInvalidRegistrationId; | 50 RegistrationId id_ = kInvalidRegistrationId; |
43 BackgroundSyncState sync_state_ = BACKGROUND_SYNC_STATE_PENDING; | 51 BackgroundSyncState sync_state_ = BACKGROUND_SYNC_STATE_PENDING; |
44 | 52 |
| 53 std::list<StateCallback> notify_done_callbacks_; |
| 54 |
45 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistration); | 55 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncRegistration); |
46 }; | 56 }; |
47 | 57 |
48 } // namespace content | 58 } // namespace content |
49 | 59 |
50 namespace mojo { | 60 namespace mojo { |
51 | 61 |
52 template <> | 62 template <> |
53 struct CONTENT_EXPORT | 63 struct CONTENT_EXPORT |
54 TypeConverter<scoped_ptr<content::BackgroundSyncRegistration>, | 64 TypeConverter<scoped_ptr<content::BackgroundSyncRegistration>, |
55 content::SyncRegistrationPtr> { | 65 content::SyncRegistrationPtr> { |
56 static scoped_ptr<content::BackgroundSyncRegistration> Convert( | 66 static scoped_ptr<content::BackgroundSyncRegistration> Convert( |
57 const content::SyncRegistrationPtr& input); | 67 const content::SyncRegistrationPtr& input); |
58 }; | 68 }; |
59 | 69 |
60 template <> | 70 template <> |
61 struct CONTENT_EXPORT TypeConverter<content::SyncRegistrationPtr, | 71 struct CONTENT_EXPORT TypeConverter<content::SyncRegistrationPtr, |
62 content::BackgroundSyncRegistration> { | 72 content::BackgroundSyncRegistration> { |
63 static content::SyncRegistrationPtr Convert( | 73 static content::SyncRegistrationPtr Convert( |
64 const content::BackgroundSyncRegistration& input); | 74 const content::BackgroundSyncRegistration& input); |
65 }; | 75 }; |
66 | 76 |
67 } // namespace | 77 } // namespace |
68 | 78 |
69 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ | 79 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ |
OLD | NEW |