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

Unified Diff: chrome/browser/media/router/media_source.cc

Issue 949293004: Add media router common classes and unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resync with latest changes Created 5 years, 10 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.cc
diff --git a/chrome/browser/media/router/media_source.cc b/chrome/browser/media/router/media_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21efe0193a37d5dd30c6b94f4a263fd7f683a5e3
--- /dev/null
+++ b/chrome/browser/media/router/media_source.cc
@@ -0,0 +1,61 @@
+// 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.h"
+
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "url/gurl.h"
+
+namespace media_router {
+
+namespace {
+
+// See: https://www.ietf.org/rfc/rfc3406.txt
+const char* kTabMediaUrnPrefix = "urn:x-org.chromium.media:source:tab";
+const char* kDesktopMediaUrnPrefix = "urn:x-org.chromium.media:source:desktop";
+const char* kDialUrnPrefix = "urn:dial-multiscreen-org:dial:application:";
+const char* kCastUrnPrefix = "urn:x-com.google.cast:application:";
+
+} // namespace
+
+MediaSource ForTabMediaSource(int tab_id) {
+ return base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id);
+}
+
+MediaSource ForDesktopMediaSource() {
+ return std::string(kDesktopMediaUrnPrefix);
+}
+
+// TODO(mfoltz): Remove? This is only used for tests.
mark a. foltz 2015/03/02 21:40:10 This is probably a good time as ever to do this.
Kevin M 2015/03/03 21:53:20 Done.
+MediaSource ForDialAppMediaSource(const std::string& app_name) {
+ return kDialUrnPrefix + app_name;
+}
+
+// TODO(mfoltz): Remove when the TODO in
+// MediaSourceManager::GetDefaultMediaSource is resolved.
mark a. foltz 2015/03/02 21:40:10 IIRC this will need to be retained until more Pres
Kevin M 2015/03/03 21:53:20 Acknowledged.
+MediaSource ForCastAppMediaSource(const std::string& app_id) {
+ return kCastUrnPrefix + app_id;
+}
+
+MediaSource ForPresentationUrl(const std::string& presentation_url) {
+ return presentation_url;
+}
+
+bool IsMirroringMediaSource(const MediaSource& source) {
+ return StartsWithASCII(source, kDesktopMediaUrnPrefix, true) ||
+ StartsWithASCII(source, kTabMediaUrnPrefix, true);
+}
+
+bool IsValidMediaSource(const MediaSource& source) {
+ if (IsMirroringMediaSource(source) ||
+ StartsWithASCII(source, kDialUrnPrefix, true) ||
+ StartsWithASCII(source, kCastUrnPrefix, true)) {
+ return true;
+ }
+ GURL url(source);
+ return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698