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 "chrome/browser/media/router/media_source.h" | |
6 | |
7 #include "base/strings/string_util.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "url/gurl.h" | |
10 | |
11 namespace media_router { | |
12 | |
13 namespace { | |
14 | |
15 // See: https://www.ietf.org/rfc/rfc3406.txt | |
16 const char* kTabMediaUrnPrefix = "urn:x-org.chromium.media:source:tab"; | |
xhwang
2015/03/05 22:28:50
nit. We prefer
const char kFoo[]
to
const cha
Kevin M
2015/03/06 23:12:45
Good point, done.
| |
17 const char* kDesktopMediaUrnPrefix = "urn:x-org.chromium.media:source:desktop"; | |
18 const char* kCastUrnPrefix = "urn:x-com.google.cast:application:"; | |
xhwang
2015/03/05 22:28:50
It's confusing that some prefix ends with ":" and
Kevin M
2015/03/06 23:12:45
It's totally media type dependent here.
For tab,
xhwang
2015/03/09 17:37:30
sg, add a comment? It's easy for people to omit th
Kevin M
2015/03/09 23:32:06
Done.
| |
19 | |
20 } // namespace | |
xhwang
2015/03/05 22:28:50
not needed. const variables are static by default.
Kevin M
2015/03/06 23:12:45
I'm not sure about that. const variables can defin
xhwang
2015/03/09 17:37:30
I am talking about
const char kFoo[] = "..."
wi
Kevin M
2015/03/09 23:32:06
OK, done.
| |
21 | |
22 MediaSource ForTabMediaSource(int tab_id) { | |
23 return base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id); | |
24 } | |
25 | |
26 MediaSource ForDesktopMediaSource() { | |
27 return std::string(kDesktopMediaUrnPrefix); | |
28 } | |
29 | |
30 // TODO(mfoltz): Remove when the TODO in | |
31 // MediaSourceManager::GetDefaultMediaSource is resolved. | |
32 MediaSource ForCastAppMediaSource(const std::string& app_id) { | |
33 return kCastUrnPrefix + app_id; | |
34 } | |
35 | |
36 MediaSource ForPresentationUrl(const std::string& presentation_url) { | |
37 return presentation_url; | |
38 } | |
39 | |
40 bool IsMirroringMediaSource(const MediaSource& source) { | |
41 return StartsWithASCII(source, kDesktopMediaUrnPrefix, true) || | |
42 StartsWithASCII(source, kTabMediaUrnPrefix, true); | |
43 } | |
44 | |
45 bool IsValidMediaSource(const MediaSource& source) { | |
46 if (IsMirroringMediaSource(source) || | |
47 StartsWithASCII(source, kCastUrnPrefix, true)) { | |
48 return true; | |
49 } | |
50 GURL url(source); | |
51 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); | |
52 } | |
53 | |
54 } // namespace media_router | |
OLD | NEW |