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 // <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 = strlen(kRouteUrnPrefix); | |
|
Kevin M
2015/06/25 22:51:56
Use arraysize() - 1, it's done once statically
haibinlu
2015/06/26 00:12:00
Done.
| |
| 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 | |
| 32 } // namespace media_router | 69 } // namespace media_router |
| OLD | NEW |