Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/media/router/media_source_helper.cc

Issue 949293004: Add media router common classes and unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bring GN files up to date. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_helper.h"
6
7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/media/router/media_source.h"
10 #include "url/gurl.h"
11
12 namespace media_router {
13
14 // Prefixes used to format and detect various protocols' media source URNs.
15 // See: https://www.ietf.org/rfc/rfc3406.txt
16 const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab";
17 const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
18 const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:";
19
20 MediaSource ForTabMediaSource(int tab_id) {
21 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id));
22 }
23
24 MediaSource ForDesktopMediaSource() {
25 return MediaSource(std::string(kDesktopMediaUrn));
26 }
27
28 // TODO(mfoltz): Remove when the TODO in
29 // MediaSourceManager::GetDefaultMediaSource is resolved.
30 MediaSource ForCastAppMediaSource(const std::string& app_id) {
31 return MediaSource(kCastUrnPrefix + app_id);
32 }
33
34 MediaSource ForPresentationUrl(const std::string& presentation_url) {
35 return MediaSource(presentation_url);
36 }
37
38 bool IsMirroringMediaSource(const MediaSource& source) {
39 return StartsWithASCII(source.id(), kDesktopMediaUrn, true) ||
40 StartsWithASCII(source.id(), kTabMediaUrnPrefix, true);
41 }
42
43 bool IsValidMediaSource(const MediaSource& source) {
44 if (IsMirroringMediaSource(source) ||
45 StartsWithASCII(source.id(), kCastUrnPrefix, true)) {
46 return true;
47 }
48 GURL url(source.id());
49 return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
50 }
51
52 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_source_helper.h ('k') | chrome/browser/media/router/media_source_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698