Chromium Code Reviews| 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 | |
| 10 namespace media_router { | 14 namespace media_router { |
| 11 | 15 |
| 12 MediaRoute::MediaRoute(const MediaRoute::Id& media_route_id, | 16 MediaRoute::MediaRoute(const MediaRoute::Id& media_route_id, |
| 13 const MediaSource& media_source, | 17 const MediaSource& media_source, |
| 14 const MediaSink& media_sink, | 18 const MediaSink& media_sink, |
| 15 const std::string& description, | 19 const std::string& description, |
| 16 bool is_local) | 20 bool is_local) |
| 17 : media_route_id_(media_route_id), | 21 : media_route_id_(media_route_id), |
| 18 media_source_(media_source), | 22 media_source_(media_source), |
| 19 media_sink_(media_sink), | 23 media_sink_(media_sink), |
| 20 description_(description), | 24 description_(description), |
| 21 is_local_(is_local), | 25 is_local_(is_local), |
| 22 state_(MEDIA_ROUTE_STATE_NEW) { | 26 state_(MEDIA_ROUTE_STATE_NEW) { |
| 23 } | 27 } |
| 24 | 28 |
| 25 MediaRoute::~MediaRoute() { | 29 MediaRoute::~MediaRoute() { |
| 26 } | 30 } |
| 27 | 31 |
| 28 bool MediaRoute::Equals(const MediaRoute& other) const { | 32 bool MediaRoute::Equals(const MediaRoute& other) const { |
| 29 return media_route_id_ == other.media_route_id_; | 33 return media_route_id_ == other.media_route_id_; |
| 30 } | 34 } |
| 31 | 35 |
| 36 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.
| |
| 37 const MediaRoute::Id& id) { | |
| 38 if (id.find(kRouteUrnPrefix) != 0) { | |
| 39 LOG(ERROR) << "Invalid media route ID. Expecting prefix " | |
| 40 << kRouteUrnPrefix; | |
| 41 return std::make_pair(std::string(), std::string()); | |
| 42 } | |
| 43 size_t prefix_len = strlen(kRouteUrnPrefix); | |
| 44 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
| |
| 45 if (first_delim == std::string::npos || first_delim == prefix_len) { | |
| 46 LOG(ERROR) << "Invalid media route ID. Expecting presentation ID."; | |
| 47 return std::make_pair(std::string(), std::string()); | |
| 48 } | |
| 49 | |
| 50 std::string presentation_id = id.substr(prefix_len, first_delim - prefix_len); | |
| 51 size_t second_delim = id.find("/", first_delim + 1); | |
| 52 if (second_delim == std::string::npos || second_delim == first_delim + 1) { | |
| 53 LOG(ERROR) << "Invalid media route ID. Expecting sink."; | |
| 54 return std::make_pair(std::string(), std::string()); | |
| 55 } | |
| 56 | |
| 57 if (second_delim == id.size() - 1) { | |
| 58 LOG(ERROR) << "Invalid media route ID. Expecting source."; | |
| 59 return std::make_pair(std::string(), std::string()); | |
| 60 } | |
| 61 std::string source = id.substr(second_delim + 1); | |
| 62 return std::make_pair(presentation_id, source); | |
| 63 } | |
| 64 | |
| 32 } // namespace media_router | 65 } // namespace media_router |
| OLD | NEW |