Chromium Code Reviews| Index: chrome/browser/media/router/media_route.cc |
| diff --git a/chrome/browser/media/router/media_route.cc b/chrome/browser/media/router/media_route.cc |
| index 0aa126f3a2177637b22291c92b07b0cc5fae3461..1279dd163c0883b2f67d5045ce8aa2aaaeb7d676 100644 |
| --- a/chrome/browser/media/router/media_route.cc |
| +++ b/chrome/browser/media/router/media_route.cc |
| @@ -7,6 +7,10 @@ |
| #include "base/logging.h" |
| #include "chrome/browser/media/router/media_source.h" |
| +namespace { |
| +const char kRouteUrnPrefix[] = "urn:x-org.chromium:media:route:"; |
| +} |
| + |
| namespace media_router { |
| MediaRoute::MediaRoute(const MediaRoute::Id& media_route_id, |
| @@ -29,4 +33,33 @@ bool MediaRoute::Equals(const MediaRoute& other) const { |
| return media_route_id_ == other.media_route_id_; |
| } |
| +std::pair<std::string, std::string> GetPresentationIdAndUrl( |
|
Kevin M
2015/06/24 23:02:06
This needs a plain description of how the URLs are
haibinlu
2015/06/24 23:25:12
Done.
|
| + const MediaRoute::Id& id) { |
| + if (id.find(kRouteUrnPrefix) != 0) { |
| + LOG(ERROR) << "Invalid media route ID. Expecting prefix " |
| + << kRouteUrnPrefix; |
| + return std::make_pair(std::string(), std::string()); |
| + } |
| + size_t prefix_len = strlen(kRouteUrnPrefix); |
| + size_t first_delim = id.find("/"); |
|
Kevin M
2015/06/24 23:02:06
Use a string splitting function (base/strings/stri
haibinlu
2015/06/24 23:25:12
string_split will has issue because the URL can ha
|
| + if (first_delim == std::string::npos || first_delim == prefix_len) { |
| + LOG(ERROR) << "Invalid media route ID. Expecting presentation ID."; |
| + return std::make_pair(std::string(), std::string()); |
| + } |
| + |
| + std::string presentation_id = id.substr(prefix_len, first_delim - prefix_len); |
| + size_t second_delim = id.find("/", first_delim + 1); |
| + if (second_delim == std::string::npos || second_delim == first_delim + 1) { |
| + LOG(ERROR) << "Invalid media route ID. Expecting sink."; |
| + return std::make_pair(std::string(), std::string()); |
| + } |
| + |
| + if (second_delim == id.size() - 1) { |
| + LOG(ERROR) << "Invalid media route ID. Expecting source."; |
| + return std::make_pair(std::string(), std::string()); |
| + } |
| + std::string source = id.substr(second_delim + 1); |
| + return std::make_pair(presentation_id, source); |
| +} |
| + |
| } // namespace media_router |