OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "services/resource_coordinator/public/cpp/coordination_unit_struct_trai
ts.h" |
| 6 |
| 7 namespace mojo { |
| 8 |
| 9 // static |
| 10 resource_coordinator::mojom::CoordinationUnitType |
| 11 EnumTraits<resource_coordinator::mojom::CoordinationUnitType, |
| 12 resource_coordinator::CoordinationUnitType>:: |
| 13 ToMojom(resource_coordinator::CoordinationUnitType type) { |
| 14 switch (type) { |
| 15 case resource_coordinator::CoordinationUnitType::kWebContents: |
| 16 return resource_coordinator::mojom::CoordinationUnitType::kWebContents; |
| 17 case resource_coordinator::CoordinationUnitType::kFrame: |
| 18 return resource_coordinator::mojom::CoordinationUnitType::kFrame; |
| 19 case resource_coordinator::CoordinationUnitType::kNavigation: |
| 20 return resource_coordinator::mojom::CoordinationUnitType::kNavigation; |
| 21 case resource_coordinator::CoordinationUnitType::kProcess: |
| 22 return resource_coordinator::mojom::CoordinationUnitType::kProcess; |
| 23 default: |
| 24 NOTREACHED() << "Invalid type: " << static_cast<uint8_t>(type); |
| 25 // This should not be reached. Just return a random value. |
| 26 return resource_coordinator::mojom::CoordinationUnitType::kWebContents; |
| 27 } |
| 28 } |
| 29 |
| 30 // static |
| 31 bool EnumTraits<resource_coordinator::mojom::CoordinationUnitType, |
| 32 resource_coordinator::CoordinationUnitType>:: |
| 33 FromMojom(resource_coordinator::mojom::CoordinationUnitType input, |
| 34 resource_coordinator::CoordinationUnitType* out) { |
| 35 switch (input) { |
| 36 case resource_coordinator::mojom::CoordinationUnitType::kWebContents: |
| 37 *out = resource_coordinator::CoordinationUnitType::kWebContents; |
| 38 break; |
| 39 case resource_coordinator::mojom::CoordinationUnitType::kFrame: |
| 40 *out = resource_coordinator::CoordinationUnitType::kFrame; |
| 41 break; |
| 42 case resource_coordinator::mojom::CoordinationUnitType::kNavigation: |
| 43 *out = resource_coordinator::CoordinationUnitType::kNavigation; |
| 44 break; |
| 45 case resource_coordinator::mojom::CoordinationUnitType::kProcess: |
| 46 *out = resource_coordinator::CoordinationUnitType::kProcess; |
| 47 break; |
| 48 default: |
| 49 NOTREACHED() << "Invalid type: " << static_cast<uint8_t>(input); |
| 50 return false; |
| 51 } |
| 52 return true; |
| 53 } |
| 54 |
| 55 // static |
| 56 bool StructTraits<resource_coordinator::mojom::CoordinationUnitIDDataView, |
| 57 resource_coordinator::CoordinationUnitID>:: |
| 58 Read(resource_coordinator::mojom::CoordinationUnitIDDataView input, |
| 59 resource_coordinator::CoordinationUnitID* out) { |
| 60 out->id = input.id(); |
| 61 if (!input.ReadType(&out->type)) |
| 62 return false; |
| 63 return true; |
| 64 } |
| 65 |
| 66 } // namespace mojo |
OLD | NEW |