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

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: Code review feedback 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..4d9e690e333fa742db9c5f9f024d80591d441bf5
--- /dev/null
+++ b/chrome/browser/media/router/media_source.cc
@@ -0,0 +1,54 @@
+// 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";
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.
+const char* kDesktopMediaUrnPrefix = "urn:x-org.chromium.media:source:desktop";
+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.
+
+} // 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.
+
+MediaSource ForTabMediaSource(int tab_id) {
+ return base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id);
+}
+
+MediaSource ForDesktopMediaSource() {
+ return std::string(kDesktopMediaUrnPrefix);
+}
+
+// TODO(mfoltz): Remove when the TODO in
+// MediaSourceManager::GetDefaultMediaSource is resolved.
+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, 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