| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> | |
| 12 | 11 |
| 13 #include "base/callback.h" | 12 #include "base/callback.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "content/browser/background_sync/background_sync.pb.h" | 15 #include "content/browser/background_sync/background_sync.pb.h" |
| 17 #include "content/browser/background_sync/background_sync_registration_options.h
" | 16 #include "content/browser/background_sync/background_sync_registration_options.h
" |
| 18 #include "content/common/background_sync_service.mojom.h" | |
| 19 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 20 #include "mojo/public/cpp/bindings/type_converter.h" | 18 #include "third_party/WebKit/public/platform/modules/background_sync/background_
sync.mojom.h" |
| 21 | 19 |
| 22 namespace content { | 20 namespace content { |
| 23 | 21 |
| 24 class CONTENT_EXPORT BackgroundSyncRegistration { | 22 class CONTENT_EXPORT BackgroundSyncRegistration { |
| 25 public: | 23 public: |
| 26 using RegistrationId = int64_t; | 24 using RegistrationId = int64_t; |
| 27 | 25 |
| 28 static const RegistrationId kInitialId; | 26 static const RegistrationId kInitialId; |
| 29 | 27 |
| 30 BackgroundSyncRegistration() = default; | 28 BackgroundSyncRegistration() = default; |
| 31 BackgroundSyncRegistration(const BackgroundSyncRegistration& other) = default; | 29 BackgroundSyncRegistration(const BackgroundSyncRegistration& other) = default; |
| 32 BackgroundSyncRegistration& operator=( | 30 BackgroundSyncRegistration& operator=( |
| 33 const BackgroundSyncRegistration& other) = default; | 31 const BackgroundSyncRegistration& other) = default; |
| 34 ~BackgroundSyncRegistration() = default; | 32 ~BackgroundSyncRegistration() = default; |
| 35 | 33 |
| 36 bool Equals(const BackgroundSyncRegistration& other) const; | 34 bool Equals(const BackgroundSyncRegistration& other) const; |
| 37 bool IsValid() const; | 35 bool IsValid() const; |
| 38 bool IsFiring() const; | 36 bool IsFiring() const; |
| 39 | 37 |
| 40 const BackgroundSyncRegistrationOptions* options() const { return &options_; } | 38 const BackgroundSyncRegistrationOptions* options() const { return &options_; } |
| 41 BackgroundSyncRegistrationOptions* options() { return &options_; } | 39 BackgroundSyncRegistrationOptions* options() { return &options_; } |
| 42 | 40 |
| 43 RegistrationId id() const { return id_; } | 41 RegistrationId id() const { return id_; } |
| 44 void set_id(RegistrationId id) { id_ = id; } | 42 void set_id(RegistrationId id) { id_ = id; } |
| 45 | 43 |
| 46 mojom::BackgroundSyncState sync_state() const { return sync_state_; } | 44 blink::mojom::BackgroundSyncState sync_state() const { return sync_state_; } |
| 47 void set_sync_state(mojom::BackgroundSyncState state) { sync_state_ = state; } | 45 void set_sync_state(blink::mojom::BackgroundSyncState state) { |
| 46 sync_state_ = state; |
| 47 } |
| 48 | 48 |
| 49 int num_attempts() const { return num_attempts_; } | 49 int num_attempts() const { return num_attempts_; } |
| 50 void set_num_attempts(int num_attempts) { num_attempts_ = num_attempts; } | 50 void set_num_attempts(int num_attempts) { num_attempts_ = num_attempts; } |
| 51 | 51 |
| 52 base::Time delay_until() const { return delay_until_; } | 52 base::Time delay_until() const { return delay_until_; } |
| 53 void set_delay_until(base::Time delay_until) { delay_until_ = delay_until; } | 53 void set_delay_until(base::Time delay_until) { delay_until_ = delay_until; } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 static const RegistrationId kInvalidRegistrationId; | 56 static const RegistrationId kInvalidRegistrationId; |
| 57 | 57 |
| 58 BackgroundSyncRegistrationOptions options_; | 58 BackgroundSyncRegistrationOptions options_; |
| 59 RegistrationId id_ = kInvalidRegistrationId; | 59 RegistrationId id_ = kInvalidRegistrationId; |
| 60 mojom::BackgroundSyncState sync_state_ = mojom::BackgroundSyncState::PENDING; | 60 blink::mojom::BackgroundSyncState sync_state_ = |
| 61 blink::mojom::BackgroundSyncState::PENDING; |
| 61 int num_attempts_ = 0; | 62 int num_attempts_ = 0; |
| 62 base::Time delay_until_; | 63 base::Time delay_until_; |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace content | 66 } // namespace content |
| 66 | 67 |
| 67 namespace mojo { | |
| 68 | |
| 69 template <> | |
| 70 struct CONTENT_EXPORT | |
| 71 TypeConverter<std::unique_ptr<content::BackgroundSyncRegistration>, | |
| 72 content::mojom::SyncRegistrationPtr> { | |
| 73 static std::unique_ptr<content::BackgroundSyncRegistration> Convert( | |
| 74 const content::mojom::SyncRegistrationPtr& input); | |
| 75 }; | |
| 76 | |
| 77 template <> | |
| 78 struct CONTENT_EXPORT TypeConverter<content::mojom::SyncRegistrationPtr, | |
| 79 content::BackgroundSyncRegistration> { | |
| 80 static content::mojom::SyncRegistrationPtr Convert( | |
| 81 const content::BackgroundSyncRegistration& input); | |
| 82 }; | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ | 68 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_REGISTRATION_H_ |
| OLD | NEW |