Chromium Code Reviews| Index: content/child/background_sync/background_sync_type_converters.cc |
| diff --git a/content/child/background_sync/background_sync_type_converters.cc b/content/child/background_sync/background_sync_type_converters.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3979a77bcc3f06530ba11bb82af3490a047e5c46 |
| --- /dev/null |
| +++ b/content/child/background_sync/background_sync_type_converters.cc |
| @@ -0,0 +1,157 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/child/background_sync/background_sync_type_converters.h" |
|
jkarlin
2015/04/27 18:25:11
New line after this line
iclelland
2015/04/28 12:41:29
Done.
|
| +#include "base/logging.h" |
| + |
| +namespace mojo { |
| + |
| +// static |
| +blink::WebSyncRegistration::Periodicity |
| + TypeConverter<blink::WebSyncRegistration::Periodicity, |
| + content::background_sync::SyncPeriodicity>::Convert( |
| + content::background_sync::SyncPeriodicity input) { |
| + blink::WebSyncRegistration::Periodicity result; |
| + |
| + switch (input) { |
| + case content::background_sync::SYNC_PERIODICITY_Periodic: |
| + result = blink::WebSyncRegistration::PeriodicityPeriodic; |
| + break; |
| + case content::background_sync::SYNC_PERIODICITY_OneShot: |
| + result = blink::WebSyncRegistration::PeriodicityOneShot; |
| + break; |
| + } |
|
jkarlin
2015/04/27 18:25:10
Since you have the switch, you should call NOTREAC
iclelland
2015/04/28 12:41:29
I thought that the compiler flags always included
jkarlin
2015/04/29 13:49:26
-Wswitch doesn't protect against invalid values (o
|
| + return result; |
| +} |
| + |
| +// static |
| +content::background_sync::SyncPeriodicity |
| + TypeConverter<content::background_sync::SyncPeriodicity, |
| + blink::WebSyncRegistration::Periodicity>::Convert( |
| + blink::WebSyncRegistration::Periodicity input) { |
| + content::background_sync::SyncPeriodicity result; |
| + switch (input) { |
| + case blink::WebSyncRegistration::PeriodicityPeriodic: |
| + result = content::background_sync::SYNC_PERIODICITY_Periodic; |
| + break; |
| + case blink::WebSyncRegistration::PeriodicityOneShot: |
| + result = content::background_sync::SYNC_PERIODICITY_OneShot; |
| + break; |
| + } |
| + return result; |
|
jkarlin
2015/04/27 18:25:10
ditto
iclelland
2015/04/28 12:41:29
Done.
|
| +} |
| + |
| +// static |
| +blink::WebSyncRegistration::NetworkState |
| + TypeConverter<blink::WebSyncRegistration::NetworkState, |
| + content::background_sync::SyncNetworkState>::Convert( |
| + content::background_sync::SyncNetworkState input) { |
| + blink::WebSyncRegistration::NetworkState result; |
| + |
| + switch (input) { |
| + case content::background_sync::SYNC_NETWORK_STATE_Any: |
| + result = blink::WebSyncRegistration::NetworkStateAny; |
| + break; |
| + case content::background_sync::SYNC_NETWORK_STATE_AvoidCellular: |
| + result = blink::WebSyncRegistration::NetworkStateAvoidCellular; |
| + break; |
| + case content::background_sync::SYNC_NETWORK_STATE_Online: |
| + result = blink::WebSyncRegistration::NetworkStateOnline; |
| + break; |
| + } |
| + return result; |
|
jkarlin
2015/04/27 18:25:11
ditto
iclelland
2015/04/28 12:41:29
Done.
|
| +} |
| + |
| +// static |
| +content::background_sync::SyncNetworkState |
| + TypeConverter<content::background_sync::SyncNetworkState, |
| + blink::WebSyncRegistration::NetworkState>::Convert( |
| + blink::WebSyncRegistration::NetworkState input) { |
| + content::background_sync::SyncNetworkState result; |
| + switch (input) { |
| + case blink::WebSyncRegistration::NetworkStateAny: |
| + result = content::background_sync::SYNC_NETWORK_STATE_Any; |
| + break; |
| + case blink::WebSyncRegistration::NetworkStateAvoidCellular: |
| + result = content::background_sync::SYNC_NETWORK_STATE_AvoidCellular; |
| + break; |
| + case blink::WebSyncRegistration::NetworkStateOnline: |
| + result = content::background_sync::SYNC_NETWORK_STATE_Online; |
| + break; |
| + } |
| + return result; |
|
jkarlin
2015/04/27 18:25:11
ditto
iclelland
2015/04/28 12:41:29
Done.
|
| +} |
| + |
| +// static |
| +blink::WebSyncRegistration::PowerState |
| + TypeConverter<blink::WebSyncRegistration::PowerState, |
| + content::background_sync::SyncPowerState>::Convert( |
| + content::background_sync::SyncPowerState input) { |
| + blink::WebSyncRegistration::PowerState result; |
| + |
| + switch (input) { |
| + case content::background_sync::SYNC_POWER_STATE_Auto: |
| + result = blink::WebSyncRegistration::PowerStateAuto; |
| + break; |
| + case content::background_sync::SYNC_POWER_STATE_AvoidDraining: |
| + result = blink::WebSyncRegistration::PowerStateAvoidDraining; |
| + break; |
| + } |
| + return result; |
| +} |
| + |
| +// static |
| +content::background_sync::SyncPowerState |
| + TypeConverter<content::background_sync::SyncPowerState, |
| + blink::WebSyncRegistration::PowerState>::Convert( |
| + blink::WebSyncRegistration::PowerState input) { |
| + content::background_sync::SyncPowerState result; |
| + switch (input) { |
| + case blink::WebSyncRegistration::PowerStateAuto: |
| + result = content::background_sync::SYNC_POWER_STATE_Auto; |
| + break; |
| + case blink::WebSyncRegistration::PowerStateAvoidDraining: |
| + result = content::background_sync::SYNC_POWER_STATE_AvoidDraining; |
| + break; |
| + } |
| + return result; |
|
jkarlin
2015/04/27 18:25:11
ditto
iclelland
2015/04/28 12:41:29
Done.
|
| +} |
| + |
| +// static |
| +blink::WebSyncRegistration* TypeConverter<blink::WebSyncRegistration *, |
|
jkarlin
2015/04/27 18:25:10
This naked pointer scares me. Return a scoped_ptr<
iclelland
2015/04/28 12:41:29
Done.
|
| + content::background_sync::SyncRegistrationPtr>::Convert( |
| + const content::background_sync::SyncRegistrationPtr& input) { |
| + blink::WebSyncRegistration* result = new blink::WebSyncRegistration(); |
| + result->id = input->id; |
| + result->periodicity = |
| + ConvertTo<blink::WebSyncRegistration::Periodicity>(input->periodicity); |
| + result->tag = blink::WebString::fromUTF8(input->tag); |
| + result->minPeriodMs = input->minPeriodMs; |
| + result->networkState = |
| + ConvertTo<blink::WebSyncRegistration::NetworkState>(input->networkState); |
| + result->powerState = |
| + ConvertTo<blink::WebSyncRegistration::PowerState>(input->powerState); |
| + return result; |
| +} |
| + |
| +// static |
| +content::background_sync::SyncRegistrationPtr TypeConverter< |
| + content::background_sync::SyncRegistrationPtr, |
| + blink::WebSyncRegistration>::Convert( |
| + const blink::WebSyncRegistration& input) { |
| + content::background_sync::SyncRegistrationPtr result( |
| + content::background_sync::SyncRegistration::New()); |
| + result->id = input.id; |
| + result->periodicity = |
| + ConvertTo<content::background_sync::SyncPeriodicity>(input.periodicity); |
| + result->tag = input.tag.utf8(); |
| + result->minPeriodMs = input.minPeriodMs; |
| + result->networkState = |
| + ConvertTo<content::background_sync::SyncNetworkState>(input.networkState); |
| + result->powerState = |
| + ConvertTo<content::background_sync::SyncPowerState>(input.powerState); |
| + return result.Pass(); |
| +} |
| + |
| +} // namespace mojo |
|
jkarlin
2015/04/27 18:25:11
two spaces after }
iclelland
2015/04/28 12:41:29
Done.
|