| 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 "chrome/browser/media/router/media_route.h" | 5 #include "chrome/browser/media/router/media_route.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/media/router/media_source.h" | 8 #include "chrome/browser/media/router/media_source.h" |
| 9 | 9 |
| 10 namespace { | |
| 11 const char kRouteUrnPrefix[] = "urn:x-org.chromium:media:route:"; | |
| 12 } | |
| 13 | |
| 14 namespace media_router { | 10 namespace media_router { |
| 15 | 11 |
| 16 MediaRoute::MediaRoute(const MediaRoute::Id& media_route_id, | 12 MediaRoute::MediaRoute(const MediaRoute::Id& media_route_id, |
| 17 const MediaSource& media_source, | 13 const MediaSource& media_source, |
| 18 const MediaSink& media_sink, | 14 const MediaSink& media_sink, |
| 19 const std::string& description, | 15 const std::string& description, |
| 20 bool is_local, | 16 bool is_local, |
| 21 const std::string& custom_controller_path) | 17 const std::string& custom_controller_path) |
| 22 : media_route_id_(media_route_id), | 18 : media_route_id_(media_route_id), |
| 23 media_source_(media_source), | 19 media_source_(media_source), |
| 24 media_sink_(media_sink), | 20 media_sink_(media_sink), |
| 25 description_(description), | 21 description_(description), |
| 26 is_local_(is_local), | 22 is_local_(is_local), |
| 27 custom_controller_path_(custom_controller_path) {} | 23 custom_controller_path_(custom_controller_path) {} |
| 28 | 24 |
| 29 MediaRoute::~MediaRoute() { | 25 MediaRoute::~MediaRoute() { |
| 30 } | 26 } |
| 31 | 27 |
| 32 bool MediaRoute::Equals(const MediaRoute& other) const { | 28 bool MediaRoute::Equals(const MediaRoute& other) const { |
| 33 return media_route_id_ == other.media_route_id_; | 29 return media_route_id_ == other.media_route_id_; |
| 34 } | 30 } |
| 35 | 31 |
| 36 // <route-id> = | |
| 37 // urn:x-org.chromium:media:route:<presentation-id>/<sink>/<source> | |
| 38 // <source> = <url>|<capture-source> | |
| 39 // <sink> = <provider-name>-<sink-id> | |
| 40 std::pair<std::string, std::string> GetPresentationIdAndUrl( | |
| 41 const MediaRoute::Id& id) { | |
| 42 if (id.find(kRouteUrnPrefix) != 0) { | |
| 43 LOG(ERROR) << "Invalid media route ID. Expecting prefix " | |
| 44 << kRouteUrnPrefix; | |
| 45 return std::make_pair(std::string(), std::string()); | |
| 46 } | |
| 47 size_t prefix_len = arraysize(kRouteUrnPrefix) - 1; | |
| 48 size_t first_delim = id.find("/"); | |
| 49 if (first_delim == std::string::npos || first_delim == prefix_len) { | |
| 50 LOG(ERROR) << "Invalid media route ID. Expecting presentation ID."; | |
| 51 return std::make_pair(std::string(), std::string()); | |
| 52 } | |
| 53 | |
| 54 std::string presentation_id = id.substr(prefix_len, first_delim - prefix_len); | |
| 55 size_t second_delim = id.find("/", first_delim + 1); | |
| 56 if (second_delim == std::string::npos || second_delim == first_delim + 1) { | |
| 57 LOG(ERROR) << "Invalid media route ID. Expecting sink."; | |
| 58 return std::make_pair(std::string(), std::string()); | |
| 59 } | |
| 60 | |
| 61 if (second_delim == id.size() - 1) { | |
| 62 LOG(ERROR) << "Invalid media route ID. Expecting source."; | |
| 63 return std::make_pair(std::string(), std::string()); | |
| 64 } | |
| 65 std::string source = id.substr(second_delim + 1); | |
| 66 return std::make_pair(presentation_id, source); | |
| 67 } | |
| 68 | |
| 69 MediaRouteIdToPresentationSessionMapping:: | 32 MediaRouteIdToPresentationSessionMapping:: |
| 70 MediaRouteIdToPresentationSessionMapping() { | 33 MediaRouteIdToPresentationSessionMapping() { |
| 71 } | 34 } |
| 72 | 35 |
| 73 MediaRouteIdToPresentationSessionMapping:: | 36 MediaRouteIdToPresentationSessionMapping:: |
| 74 ~MediaRouteIdToPresentationSessionMapping() { | 37 ~MediaRouteIdToPresentationSessionMapping() { |
| 75 } | 38 } |
| 76 | 39 |
| 77 void MediaRouteIdToPresentationSessionMapping::Add( | 40 void MediaRouteIdToPresentationSessionMapping::Add( |
| 78 const MediaRoute::Id& route_id, | 41 const MediaRoute::Id& route_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 } | 53 } |
| 91 | 54 |
| 92 const content::PresentationSessionInfo* | 55 const content::PresentationSessionInfo* |
| 93 MediaRouteIdToPresentationSessionMapping::Get( | 56 MediaRouteIdToPresentationSessionMapping::Get( |
| 94 const MediaRoute::Id& route_id) const { | 57 const MediaRoute::Id& route_id) const { |
| 95 auto it = route_id_to_presentation_.find(route_id); | 58 auto it = route_id_to_presentation_.find(route_id); |
| 96 return it == route_id_to_presentation_.end() ? nullptr : &it->second; | 59 return it == route_id_to_presentation_.end() ? nullptr : &it->second; |
| 97 } | 60 } |
| 98 | 61 |
| 99 } // namespace media_router | 62 } // namespace media_router |
| OLD | NEW |