| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #include "content/common/indexed_db/indexed_db_enum_traits.h" | |
| 6 | |
| 7 using indexed_db::mojom::CursorDirection; | |
| 8 using indexed_db::mojom::DataLoss; | |
| 9 using indexed_db::mojom::OperationType; | |
| 10 using indexed_db::mojom::PutMode; | |
| 11 using indexed_db::mojom::TaskType; | |
| 12 using indexed_db::mojom::TransactionMode; | |
| 13 | |
| 14 namespace mojo { | |
| 15 | |
| 16 // static | |
| 17 CursorDirection | |
| 18 EnumTraits<CursorDirection, blink::WebIDBCursorDirection>::ToMojom( | |
| 19 blink::WebIDBCursorDirection input) { | |
| 20 switch (input) { | |
| 21 case blink::WebIDBCursorDirectionNext: | |
| 22 return CursorDirection::Next; | |
| 23 case blink::WebIDBCursorDirectionNextNoDuplicate: | |
| 24 return CursorDirection::NextNoDuplicate; | |
| 25 case blink::WebIDBCursorDirectionPrev: | |
| 26 return CursorDirection::Prev; | |
| 27 case blink::WebIDBCursorDirectionPrevNoDuplicate: | |
| 28 return CursorDirection::PrevNoDuplicate; | |
| 29 } | |
| 30 NOTREACHED(); | |
| 31 return CursorDirection::Next; | |
| 32 } | |
| 33 | |
| 34 // static | |
| 35 bool EnumTraits<CursorDirection, blink::WebIDBCursorDirection>::FromMojom( | |
| 36 CursorDirection input, | |
| 37 blink::WebIDBCursorDirection* output) { | |
| 38 switch (input) { | |
| 39 case CursorDirection::Next: | |
| 40 *output = blink::WebIDBCursorDirectionNext; | |
| 41 return true; | |
| 42 case CursorDirection::NextNoDuplicate: | |
| 43 *output = blink::WebIDBCursorDirectionNextNoDuplicate; | |
| 44 return true; | |
| 45 case CursorDirection::Prev: | |
| 46 *output = blink::WebIDBCursorDirectionPrev; | |
| 47 return true; | |
| 48 case CursorDirection::PrevNoDuplicate: | |
| 49 *output = blink::WebIDBCursorDirectionPrevNoDuplicate; | |
| 50 return true; | |
| 51 } | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 // static | |
| 56 DataLoss EnumTraits<DataLoss, blink::WebIDBDataLoss>::ToMojom( | |
| 57 blink::WebIDBDataLoss input) { | |
| 58 switch (input) { | |
| 59 case blink::WebIDBDataLossNone: | |
| 60 return DataLoss::None; | |
| 61 case blink::WebIDBDataLossTotal: | |
| 62 return DataLoss::Total; | |
| 63 } | |
| 64 NOTREACHED(); | |
| 65 return DataLoss::None; | |
| 66 } | |
| 67 | |
| 68 // static | |
| 69 bool EnumTraits<DataLoss, blink::WebIDBDataLoss>::FromMojom( | |
| 70 DataLoss input, | |
| 71 blink::WebIDBDataLoss* output) { | |
| 72 switch (input) { | |
| 73 case DataLoss::None: | |
| 74 *output = blink::WebIDBDataLossNone; | |
| 75 return true; | |
| 76 case DataLoss::Total: | |
| 77 *output = blink::WebIDBDataLossTotal; | |
| 78 return true; | |
| 79 } | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 // static | |
| 84 OperationType EnumTraits<OperationType, blink::WebIDBOperationType>::ToMojom( | |
| 85 blink::WebIDBOperationType input) { | |
| 86 switch (input) { | |
| 87 case blink::WebIDBAdd: | |
| 88 return OperationType::Add; | |
| 89 case blink::WebIDBPut: | |
| 90 return OperationType::Put; | |
| 91 case blink::WebIDBDelete: | |
| 92 return OperationType::Delete; | |
| 93 case blink::WebIDBClear: | |
| 94 return OperationType::Clear; | |
| 95 case blink::WebIDBOperationTypeCount: | |
| 96 // WebIDBOperationTypeCount is not a valid option. | |
| 97 break; | |
| 98 } | |
| 99 NOTREACHED(); | |
| 100 return OperationType::Add; | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 bool EnumTraits<OperationType, blink::WebIDBOperationType>::FromMojom( | |
| 105 OperationType input, | |
| 106 blink::WebIDBOperationType* output) { | |
| 107 switch (input) { | |
| 108 case OperationType::Add: | |
| 109 *output = blink::WebIDBAdd; | |
| 110 return true; | |
| 111 case OperationType::Put: | |
| 112 *output = blink::WebIDBPut; | |
| 113 return true; | |
| 114 case OperationType::Delete: | |
| 115 *output = blink::WebIDBDelete; | |
| 116 return true; | |
| 117 case OperationType::Clear: | |
| 118 *output = blink::WebIDBClear; | |
| 119 return true; | |
| 120 } | |
| 121 return false; | |
| 122 } | |
| 123 | |
| 124 // static | |
| 125 PutMode EnumTraits<PutMode, blink::WebIDBPutMode>::ToMojom( | |
| 126 blink::WebIDBPutMode input) { | |
| 127 switch (input) { | |
| 128 case blink::WebIDBPutModeAddOrUpdate: | |
| 129 return PutMode::AddOrUpdate; | |
| 130 case blink::WebIDBPutModeAddOnly: | |
| 131 return PutMode::AddOnly; | |
| 132 case blink::WebIDBPutModeCursorUpdate: | |
| 133 return PutMode::CursorUpdate; | |
| 134 } | |
| 135 NOTREACHED(); | |
| 136 return PutMode::AddOrUpdate; | |
| 137 } | |
| 138 | |
| 139 // static | |
| 140 bool EnumTraits<PutMode, blink::WebIDBPutMode>::FromMojom( | |
| 141 PutMode input, | |
| 142 blink::WebIDBPutMode* output) { | |
| 143 switch (input) { | |
| 144 case PutMode::AddOrUpdate: | |
| 145 *output = blink::WebIDBPutModeAddOrUpdate; | |
| 146 return true; | |
| 147 case PutMode::AddOnly: | |
| 148 *output = blink::WebIDBPutModeAddOnly; | |
| 149 return true; | |
| 150 case PutMode::CursorUpdate: | |
| 151 *output = blink::WebIDBPutModeCursorUpdate; | |
| 152 return true; | |
| 153 } | |
| 154 return false; | |
| 155 } | |
| 156 | |
| 157 // static | |
| 158 TaskType EnumTraits<TaskType, blink::WebIDBTaskType>::ToMojom( | |
| 159 blink::WebIDBTaskType input) { | |
| 160 switch (input) { | |
| 161 case blink::WebIDBTaskTypeNormal: | |
| 162 return TaskType::Normal; | |
| 163 case blink::WebIDBTaskTypePreemptive: | |
| 164 return TaskType::Preemptive; | |
| 165 } | |
| 166 NOTREACHED(); | |
| 167 return TaskType::Normal; | |
| 168 } | |
| 169 | |
| 170 // static | |
| 171 bool EnumTraits<TaskType, blink::WebIDBTaskType>::FromMojom( | |
| 172 TaskType input, | |
| 173 blink::WebIDBTaskType* output) { | |
| 174 switch (input) { | |
| 175 case TaskType::Normal: | |
| 176 *output = blink::WebIDBTaskTypeNormal; | |
| 177 return true; | |
| 178 case TaskType::Preemptive: | |
| 179 *output = blink::WebIDBTaskTypePreemptive; | |
| 180 return true; | |
| 181 } | |
| 182 return false; | |
| 183 } | |
| 184 | |
| 185 // static | |
| 186 TransactionMode | |
| 187 EnumTraits<TransactionMode, blink::WebIDBTransactionMode>::ToMojom( | |
| 188 blink::WebIDBTransactionMode input) { | |
| 189 switch (input) { | |
| 190 case blink::WebIDBTransactionModeReadOnly: | |
| 191 return TransactionMode::ReadOnly; | |
| 192 case blink::WebIDBTransactionModeReadWrite: | |
| 193 return TransactionMode::ReadWrite; | |
| 194 case blink::WebIDBTransactionModeVersionChange: | |
| 195 return TransactionMode::VersionChange; | |
| 196 } | |
| 197 NOTREACHED(); | |
| 198 return TransactionMode::ReadOnly; | |
| 199 } | |
| 200 | |
| 201 // static | |
| 202 bool EnumTraits<TransactionMode, blink::WebIDBTransactionMode>::FromMojom( | |
| 203 TransactionMode input, | |
| 204 blink::WebIDBTransactionMode* output) { | |
| 205 switch (input) { | |
| 206 case TransactionMode::ReadOnly: | |
| 207 *output = blink::WebIDBTransactionModeReadOnly; | |
| 208 return true; | |
| 209 case TransactionMode::ReadWrite: | |
| 210 *output = blink::WebIDBTransactionModeReadWrite; | |
| 211 return true; | |
| 212 case TransactionMode::VersionChange: | |
| 213 *output = blink::WebIDBTransactionModeVersionChange; | |
| 214 return true; | |
| 215 } | |
| 216 return false; | |
| 217 } | |
| 218 | |
| 219 } // namespace mojo | |
| OLD | NEW |