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 #include "content/browser/background_sync/background_sync_registration.h"
9 #define COMPILE_ASSERT_MATCHING_ENUM(mojo_name, browser_name) \
10 COMPILE_ASSERT(static_cast<int>(content::mojo_name) == \
11 static_cast<int>(content::browser_name), \
14 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_PERIODIC
,
16 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_ONE_SHOT
,
18 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX
, SYNC_ONE_SHOT
);
19 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX
,
21 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ANY
,
23 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_AVOID_CELLULAR
,
24 NETWORK_STATE_AVOID_CELLULAR
);
25 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ONLINE
,
26 NETWORK_STATE_ONLINE
);
27 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_MAX
,
28 NETWORK_STATE_ONLINE
);
29 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_MAX
,
30 SyncNetworkState_MAX
);
31 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_AUTO
,
33 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_AVOID_DRAINING
,
34 POWER_STATE_AVOID_DRAINING
);
35 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_MAX
,
36 POWER_STATE_AVOID_DRAINING
);
37 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_POWER_STATE_MAX
,
41 scoped_ptr
<content::BackgroundSyncRegistration
> TypeConverter
<
42 scoped_ptr
<content::BackgroundSyncRegistration
>,
43 content::SyncRegistrationPtr
>::Convert(const content::SyncRegistrationPtr
&
45 scoped_ptr
<content::BackgroundSyncRegistration
> out(
46 new content::BackgroundSyncRegistration());
48 content::BackgroundSyncRegistrationOptions
* options
= out
->options();
49 options
->tag
= in
->tag
;
50 options
->min_period
= in
->min_period_ms
;
51 options
->power_state
= static_cast<content::SyncPowerState
>(in
->power_state
);
52 options
->network_state
=
53 static_cast<content::SyncNetworkState
>(in
->network_state
);
54 options
->periodicity
= static_cast<content::SyncPeriodicity
>(in
->periodicity
);
59 content::SyncRegistrationPtr
60 TypeConverter
<content::SyncRegistrationPtr
,
61 content::BackgroundSyncRegistration
>::
62 Convert(const content::BackgroundSyncRegistration
& in
) {
63 content::SyncRegistrationPtr
out(content::SyncRegistration::New());
65 const content::BackgroundSyncRegistrationOptions
* options
= in
.options();
66 out
->tag
= options
->tag
;
67 out
->min_period_ms
= options
->min_period
;
69 static_cast<content::BackgroundSyncPeriodicity
>(options
->periodicity
);
71 static_cast<content::BackgroundSyncPowerState
>(options
->power_state
);
73 static_cast<content::BackgroundSyncNetworkState
>(options
->network_state
);
81 const BackgroundSyncRegistration::RegistrationId
82 BackgroundSyncRegistration::kInvalidRegistrationId
= -1;
84 const BackgroundSyncRegistration::RegistrationId
85 BackgroundSyncRegistration::kInitialId
= 0;
87 bool BackgroundSyncRegistration::Equals(
88 const BackgroundSyncRegistration
& other
) const {
89 return options_
.Equals(other
.options_
);
92 bool BackgroundSyncRegistration::IsValid() const {
93 return id_
!= kInvalidRegistrationId
;
96 } // namespace content