| 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 | |
| 79 namespace content { | 7 namespace content { |
| 80 | 8 |
| 81 const BackgroundSyncRegistration::RegistrationId | 9 const BackgroundSyncRegistration::RegistrationId |
| 82 BackgroundSyncRegistration::kInvalidRegistrationId = -1; | 10 BackgroundSyncRegistration::kInvalidRegistrationId = -1; |
| 83 | 11 |
| 84 const BackgroundSyncRegistration::RegistrationId | 12 const BackgroundSyncRegistration::RegistrationId |
| 85 BackgroundSyncRegistration::kInitialId = 0; | 13 BackgroundSyncRegistration::kInitialId = 0; |
| 86 | 14 |
| 87 bool BackgroundSyncRegistration::Equals( | 15 bool BackgroundSyncRegistration::Equals( |
| 88 const BackgroundSyncRegistration& other) const { | 16 const BackgroundSyncRegistration& other) const { |
| 89 return options_.Equals(other.options_); | 17 return options_.Equals(other.options_); |
| 90 } | 18 } |
| 91 | 19 |
| 92 bool BackgroundSyncRegistration::IsValid() const { | 20 bool BackgroundSyncRegistration::IsValid() const { |
| 93 return id_ != kInvalidRegistrationId; | 21 return id_ != kInvalidRegistrationId; |
| 94 } | 22 } |
| 95 | 23 |
| 96 } // namespace content | 24 } // namespace content |
| OLD | NEW |