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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/router/media_source_helper.cc
diff --git a/chrome/browser/media/router/media_source_helper.cc b/chrome/browser/media/router/media_source_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..305a00fa3437dd83fa5b8eba3de0bdb61e65380c
--- /dev/null
+++ b/chrome/browser/media/router/media_source_helper.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/router/media_source_helper.h"
+
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/media/router/media_source.h"
+#include "url/gurl.h"
+
+namespace media_router {
+
+// Prefixes used to format and detect various protocols' media source URNs.
+// See: https://www.ietf.org/rfc/rfc3406.txt
+const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab";
+const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
+const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:";
+
+MediaSource ForTabMediaSource(int tab_id) {
+ return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id));
+}
+
+MediaSource ForDesktopMediaSource() {
+ return MediaSource(std::string(kDesktopMediaUrn));
+}
+
+// TODO(mfoltz): Remove when the TODO in
+// MediaSourceManager::GetDefaultMediaSource is resolved.
+MediaSource ForCastAppMediaSource(const std::string& app_id) {
+ return MediaSource(kCastUrnPrefix + app_id);
+}
+
+MediaSource ForPresentationUrl(const std::string& presentation_url) {
+ return MediaSource(presentation_url);
+}
+
+bool IsMirroringMediaSource(const MediaSource& source) {
+ return StartsWithASCII(source.id(), kDesktopMediaUrn, true) ||
+ StartsWithASCII(source.id(), kTabMediaUrnPrefix, true);
+}
+
+bool IsValidMediaSource(const MediaSource& source) {
+ if (IsMirroringMediaSource(source) ||
+ StartsWithASCII(source.id(), kCastUrnPrefix, true)) {
+ return true;
+ }
+ GURL url(source.id());
+ return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
+}
+
+} // namespace media_router
« 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