| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 | |
| 7 #include "chrome/browser/media/router/mojo/media_router_type_converters.h" | |
| 8 | |
| 9 using media_router::mojom::MediaRoutePtr; | |
| 10 using media_router::mojom::MediaSinkPtr; | |
| 11 | |
| 12 using PresentationConnectionState = | |
| 13 media_router::mojom::MediaRouter::PresentationConnectionState; | |
| 14 using PresentationConnectionCloseReason = | |
| 15 media_router::mojom::MediaRouter::PresentationConnectionCloseReason; | |
| 16 using RouteRequestResultCode = media_router::mojom::RouteRequestResultCode; | |
| 17 | |
| 18 namespace mojo { | |
| 19 | |
| 20 media_router::MediaSink::IconType SinkIconTypeFromMojo( | |
| 21 media_router::mojom::MediaSink::IconType type) { | |
| 22 switch (type) { | |
| 23 case media_router::mojom::MediaSink::IconType::CAST: | |
| 24 return media_router::MediaSink::CAST; | |
| 25 case media_router::mojom::MediaSink::IconType::CAST_AUDIO: | |
| 26 return media_router::MediaSink::CAST_AUDIO; | |
| 27 case media_router::mojom::MediaSink::IconType::CAST_AUDIO_GROUP: | |
| 28 return media_router::MediaSink::CAST_AUDIO_GROUP; | |
| 29 case media_router::mojom::MediaSink::IconType::HANGOUT: | |
| 30 return media_router::MediaSink::HANGOUT; | |
| 31 case media_router::mojom::MediaSink::IconType::GENERIC: | |
| 32 return media_router::MediaSink::GENERIC; | |
| 33 default: | |
| 34 NOTREACHED() << "Unknown sink icon type " << type; | |
| 35 return media_router::MediaSink::GENERIC; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 media_router::mojom::MediaSink::IconType SinkIconTypeToMojo( | |
| 40 media_router::MediaSink::IconType type) { | |
| 41 switch (type) { | |
| 42 case media_router::MediaSink::CAST: | |
| 43 return media_router::mojom::MediaSink::IconType::CAST; | |
| 44 case media_router::MediaSink::CAST_AUDIO: | |
| 45 return media_router::mojom::MediaSink::IconType::CAST_AUDIO; | |
| 46 case media_router::MediaSink::CAST_AUDIO_GROUP: | |
| 47 return media_router::mojom::MediaSink::IconType::CAST_AUDIO_GROUP; | |
| 48 case media_router::MediaSink::HANGOUT: | |
| 49 return media_router::mojom::MediaSink::IconType::HANGOUT; | |
| 50 case media_router::MediaSink::GENERIC: | |
| 51 return media_router::mojom::MediaSink::IconType::GENERIC; | |
| 52 default: | |
| 53 NOTREACHED() << "Unknown sink icon type " << type; | |
| 54 return media_router::mojom::MediaSink::IconType::GENERIC; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 media_router::MediaSink | |
| 60 TypeConverter<media_router::MediaSink, MediaSinkPtr>::Convert( | |
| 61 const MediaSinkPtr& input) { | |
| 62 media_router::MediaSink sink(input->sink_id, input->name, | |
| 63 SinkIconTypeFromMojo(input->icon_type)); | |
| 64 if (input->description && !input->description->empty()) | |
| 65 sink.set_description(*input->description); | |
| 66 if (input->domain && !input->domain->empty()) | |
| 67 sink.set_domain(*input->domain); | |
| 68 | |
| 69 return sink; | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 media_router::MediaRoute | |
| 74 TypeConverter<media_router::MediaRoute, MediaRoutePtr>::Convert( | |
| 75 const MediaRoutePtr& input) { | |
| 76 media_router::MediaRoute media_route( | |
| 77 input->media_route_id, | |
| 78 media_router::MediaSource(input->media_source.value_or(std::string())), | |
| 79 input->media_sink_id, input->description, input->is_local, | |
| 80 input->custom_controller_path.value_or(std::string()), | |
| 81 input->for_display); | |
| 82 media_route.set_incognito(input->is_incognito); | |
| 83 media_route.set_offscreen_presentation(input->is_offscreen_presentation); | |
| 84 return media_route; | |
| 85 } | |
| 86 | |
| 87 // static | |
| 88 std::unique_ptr<media_router::MediaRoute> | |
| 89 TypeConverter<std::unique_ptr<media_router::MediaRoute>, | |
| 90 MediaRoutePtr>::Convert(const MediaRoutePtr& input) { | |
| 91 std::unique_ptr<media_router::MediaRoute> media_route( | |
| 92 new media_router::MediaRoute( | |
| 93 input->media_route_id, | |
| 94 media_router::MediaSource( | |
| 95 input->media_source.value_or(std::string())), | |
| 96 input->media_sink_id, input->description, input->is_local, | |
| 97 input->custom_controller_path.value_or(std::string()), | |
| 98 input->for_display)); | |
| 99 media_route->set_incognito(input->is_incognito); | |
| 100 media_route->set_offscreen_presentation(input->is_offscreen_presentation); | |
| 101 return media_route; | |
| 102 } | |
| 103 | |
| 104 content::PresentationConnectionState PresentationConnectionStateFromMojo( | |
| 105 PresentationConnectionState state) { | |
| 106 switch (state) { | |
| 107 case PresentationConnectionState::CONNECTING: | |
| 108 return content::PRESENTATION_CONNECTION_STATE_CONNECTING; | |
| 109 case PresentationConnectionState::CONNECTED: | |
| 110 return content::PRESENTATION_CONNECTION_STATE_CONNECTED; | |
| 111 case PresentationConnectionState::CLOSED: | |
| 112 return content::PRESENTATION_CONNECTION_STATE_CLOSED; | |
| 113 case PresentationConnectionState::TERMINATED: | |
| 114 return content::PRESENTATION_CONNECTION_STATE_TERMINATED; | |
| 115 default: | |
| 116 NOTREACHED() << "Unknown PresentationConnectionState " << state; | |
| 117 return content::PRESENTATION_CONNECTION_STATE_TERMINATED; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 content::PresentationConnectionCloseReason | |
| 122 PresentationConnectionCloseReasonFromMojo( | |
| 123 PresentationConnectionCloseReason reason) { | |
| 124 switch (reason) { | |
| 125 case PresentationConnectionCloseReason::CONNECTION_ERROR: | |
| 126 return content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR; | |
| 127 case PresentationConnectionCloseReason::CLOSED: | |
| 128 return content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED; | |
| 129 case PresentationConnectionCloseReason::WENT_AWAY: | |
| 130 return content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | |
| 131 default: | |
| 132 NOTREACHED() << "Unknown PresentationConnectionCloseReason " << reason; | |
| 133 return content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 media_router::RouteRequestResult::ResultCode RouteRequestResultCodeFromMojo( | |
| 138 RouteRequestResultCode result_code) { | |
| 139 switch (result_code) { | |
| 140 case RouteRequestResultCode::UNKNOWN_ERROR: | |
| 141 return media_router::RouteRequestResult::UNKNOWN_ERROR; | |
| 142 case RouteRequestResultCode::OK: | |
| 143 return media_router::RouteRequestResult::OK; | |
| 144 case RouteRequestResultCode::TIMED_OUT: | |
| 145 return media_router::RouteRequestResult::TIMED_OUT; | |
| 146 case RouteRequestResultCode::ROUTE_NOT_FOUND: | |
| 147 return media_router::RouteRequestResult::ROUTE_NOT_FOUND; | |
| 148 case RouteRequestResultCode::SINK_NOT_FOUND: | |
| 149 return media_router::RouteRequestResult::SINK_NOT_FOUND; | |
| 150 case RouteRequestResultCode::INVALID_ORIGIN: | |
| 151 return media_router::RouteRequestResult::INVALID_ORIGIN; | |
| 152 case RouteRequestResultCode::INCOGNITO_MISMATCH: | |
| 153 return media_router::RouteRequestResult::INCOGNITO_MISMATCH; | |
| 154 case RouteRequestResultCode::NO_SUPPORTED_PROVIDER: | |
| 155 return media_router::RouteRequestResult::NO_SUPPORTED_PROVIDER; | |
| 156 case RouteRequestResultCode::CANCELLED: | |
| 157 return media_router::RouteRequestResult::CANCELLED; | |
| 158 default: | |
| 159 NOTREACHED() << "Unknown RouteRequestResultCode " << result_code; | |
| 160 return media_router::RouteRequestResult::UNKNOWN_ERROR; | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 } // namespace mojo | |
| OLD | NEW |