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 #include "content/browser/background_sync/background_sync_registration.h" | 5 #include "content/browser/background_sync/background_sync_registration.h" |
6 | 6 |
| 7 namespace mojo { |
| 8 |
| 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), \ |
| 12 mismatching_enums) |
| 13 |
| 14 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_PERIODIC, |
| 15 SYNC_PERIODIC); |
| 16 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_ONE_SHOT, |
| 17 SYNC_ONE_SHOT); |
| 18 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX, SYNC_ONE_SHOT); |
| 19 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_PERIODICITY_MAX, |
| 20 SyncPeriodicity_MAX); |
| 21 COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ANY, |
| 22 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, |
| 32 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, |
| 38 SyncPowerState_MAX); |
| 39 |
| 40 // static |
| 41 scoped_ptr<content::BackgroundSyncRegistration> TypeConverter< |
| 42 scoped_ptr<content::BackgroundSyncRegistration>, |
| 43 content::SyncRegistrationPtr>::Convert(const content::SyncRegistrationPtr& |
| 44 in) { |
| 45 scoped_ptr<content::BackgroundSyncRegistration> out( |
| 46 new content::BackgroundSyncRegistration()); |
| 47 out->set_id(in->id); |
| 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); |
| 55 return out; |
| 56 } |
| 57 |
| 58 // static |
| 59 content::SyncRegistrationPtr |
| 60 TypeConverter<content::SyncRegistrationPtr, |
| 61 content::BackgroundSyncRegistration>:: |
| 62 Convert(const content::BackgroundSyncRegistration& in) { |
| 63 content::SyncRegistrationPtr out(content::SyncRegistration::New()); |
| 64 out->id = in.id(); |
| 65 const content::BackgroundSyncRegistrationOptions* options = in.options(); |
| 66 out->tag = options->tag; |
| 67 out->min_period_ms = options->min_period; |
| 68 out->periodicity = |
| 69 static_cast<content::BackgroundSyncPeriodicity>(options->periodicity); |
| 70 out->power_state = |
| 71 static_cast<content::BackgroundSyncPowerState>(options->power_state); |
| 72 out->network_state = |
| 73 static_cast<content::BackgroundSyncNetworkState>(options->network_state); |
| 74 return out.Pass(); |
| 75 } |
| 76 |
| 77 } // namespace |
| 78 |
7 namespace content { | 79 namespace content { |
8 | 80 |
9 // TODO(thakis): Remove this once http://crbug.com/488634 is fixed. | 81 // TODO(thakis): Remove this once http://crbug.com/488634 is fixed. |
10 BackgroundSyncRegistration::BackgroundSyncRegistration() = default; | 82 BackgroundSyncRegistration::BackgroundSyncRegistration() = default; |
11 | 83 |
12 const BackgroundSyncRegistration::RegistrationId | 84 const BackgroundSyncRegistration::RegistrationId |
13 BackgroundSyncRegistration::kInvalidRegistrationId = -1; | 85 BackgroundSyncRegistration::kInvalidRegistrationId = -1; |
14 | 86 |
15 const BackgroundSyncRegistration::RegistrationId | 87 const BackgroundSyncRegistration::RegistrationId |
16 BackgroundSyncRegistration::kInitialId = 0; | 88 BackgroundSyncRegistration::kInitialId = 0; |
17 | 89 |
18 bool BackgroundSyncRegistration::Equals( | 90 bool BackgroundSyncRegistration::Equals( |
19 const BackgroundSyncRegistration& other) const { | 91 const BackgroundSyncRegistration& other) const { |
20 return options_.Equals(other.options_); | 92 return options_.Equals(other.options_); |
21 } | 93 } |
22 | 94 |
23 bool BackgroundSyncRegistration::IsValid() const { | 95 bool BackgroundSyncRegistration::IsValid() const { |
24 return id_ != kInvalidRegistrationId; | 96 return id_ != kInvalidRegistrationId; |
25 } | 97 } |
26 | 98 |
27 } // namespace content | 99 } // namespace content |
OLD | NEW |