Skip to content

Commit

Permalink
Upstream Cast Runtime Code to Chromium
Browse files Browse the repository at this point in the history
This CL makes the following changes:
- Upstream Cast Runtime code from Chromecast Internal to Chromium.
- Upstream cors_exempt_headers.cc / .h to Chromium. These provide a
  list of existing headers which pre-date CORS preflight check
  support in HTTP servers.
- Modify //chromecast/cast_core/cast_runtime_service interface to
  change all methods from non-pure-virtual to have empty
  implementations to simplify existing and upcoming code. This class
  acts as the singleton implementation of CastService when running
  the cast runtime executable
- Add CastRuntimeContentBrowserClient (to act as the top-level
  browser-process integration point for the Cast Runtime) and the
  CastRuntimeMain to act as the entry point for this executable.
- Rework existing //chromecast/cast_core classes to support the newly
  upstreamed code.

This is required for E2E testing of the Cast Runtime's Mirroring
implementation.

Change-Id: I8bf9983860561d7d526a2b4ab23893a2169c08f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2956889
Reviewed-by: Brandon Tolsch <btolsch@chromium.org>
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Commit-Queue: Ryan Keane <rwkeane@google.com>
Cr-Commit-Position: refs/heads/master@{#892282}
  • Loading branch information
Ryan Keane authored and Chromium LUCI CQ committed Jun 14, 2021
1 parent 416e97e commit 0781701
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 47 deletions.
1 change: 1 addition & 0 deletions chromecast/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ buildflag_header("chromecast_buildflags") {
"USE_ANDROID_USER_AGENT=$use_android_user_agent",
"USE_CHROMECAST_CDMS=$use_chromecast_cdms",
"ENABLE_CHROMIUM_RUNTIME_CAST_RENDERER=$enable_chromium_runtime_cast_renderer",
"ENABLE_CAST_MEDIA_RUNTIME=$enable_cast_media_runtime",
]
}

Expand Down
56 changes: 51 additions & 5 deletions chromecast/cast_core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,66 @@ cast_source_set("renderer") {
]
}

cast_source_set("cast_core") {
cast_source_set("browser") {
sources = [
"cast_runtime_content_browser_client.cc",
"cast_runtime_content_browser_client.h",
]

deps = [
":runtime_service",
"//base",
"//chromecast/browser",
"//chromecast/common:cors_exempt_headers",
]

if (chromecast_branding == "public") {
sources += [ "cast_runtime_content_browser_client_simple.cc" ]
}
}

cast_source_set("runtime_service") {
sources = [
"cast_runtime_service.cc",
"cast_runtime_service.h",
]

if (chromecast_branding == "public") {
sources += [ "cast_runtime_service_simple.cc" ]
}

deps = [
"//base",
"//chromecast:chromecast_buildflags",
"//chromecast/service",
]

public_deps = [ "//chromecast/media/cma/backend/proxy:headers" ]
}

if (!enable_cast_media_runtime) {
sources += [ "cast_runtime_service_simple.cc" ]
} else {
deps += [ ":renderer" ]
cast_source_set("cast_core") {
sources = []
deps = [ ":runtime_service" ]

if (enable_cast_media_runtime) {
deps += [
":browser",
":renderer",
]
}
}

if (enable_cast_media_runtime) {
cast_executable("core_runtime_simple") {
sources = [ "cast_runtime_main.cc" ]

deps = [
":cast_core",
"//chromecast/app",
"//chromecast/base:default_create_sys_info",
"//chromecast/browser:simple_main_parts",
"//chromecast/utility:simple_client",
"//content/public/app",
]
}
}
4 changes: 4 additions & 0 deletions chromecast/cast_core/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include_rules = [
"+chromecast/app",
"+chromecast/browser",
"+chromecast/chromecast_buildflags.h",
"+chromecast/common",
"+chromecast/media",
"+chromecast/renderer",
'+chromecast/service',
Expand Down
52 changes: 52 additions & 0 deletions chromecast/cast_core/cast_runtime_content_browser_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 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 "chromecast/cast_core/cast_runtime_content_browser_client.h"

#include "chromecast/browser/service_manager_connection.h"
#include "chromecast/cast_core/cast_runtime_service.h"
#include "chromecast/common/cors_exempt_headers.h"

namespace chromecast {
namespace shell {
namespace {

constexpr char kAcceptLanguageHeader[] = "Accept-Language";

} // namespace

// static
std::unique_ptr<CastContentBrowserClient> CastContentBrowserClient::Create(
CastFeatureListCreator* feature_list_creator) {
return CastRuntimeContentBrowserClient::Create(feature_list_creator);
}

// static
std::vector<std::string> CastContentBrowserClient::GetCorsExemptHeadersList() {
base::span<const char*> base_headers = GetLegacyCorsExemptHeaders();
std::vector<std::string> headers{base_headers.begin(), base_headers.end()};
headers.emplace_back(kAcceptLanguageHeader);
return headers;
}

} // namespace shell

CastRuntimeContentBrowserClient::CastRuntimeContentBrowserClient(
CastFeatureListCreator* feature_list_creator)
: shell::CastContentBrowserClient(feature_list_creator) {}

CastRuntimeContentBrowserClient::~CastRuntimeContentBrowserClient() = default;

std::unique_ptr<CastService> CastRuntimeContentBrowserClient::CreateCastService(
content::BrowserContext* browser_context,
CastSystemMemoryPressureEvaluatorAdjuster* memory_pressure_adjuster,
PrefService* pref_service,
media::VideoPlaneController* video_plane_controller,
CastWindowManager* window_manager) {
return CastRuntimeService::Create(
GetMediaTaskRunner(), browser_context, window_manager,
media_pipeline_backend_manager(), pref_service);
}

} // namespace chromecast
35 changes: 35 additions & 0 deletions chromecast/cast_core/cast_runtime_content_browser_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 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.

#ifndef CHROMECAST_CAST_CORE_CAST_RUNTIME_CONTENT_BROWSER_CLIENT_H_
#define CHROMECAST_CAST_CORE_CAST_RUNTIME_CONTENT_BROWSER_CLIENT_H_

#include "chromecast/browser/cast_content_browser_client.h"

namespace chromecast {

class CastFeatureListCreator;

class CastRuntimeContentBrowserClient final
: public shell::CastContentBrowserClient {
public:
static std::unique_ptr<CastRuntimeContentBrowserClient> Create(
CastFeatureListCreator* feature_list_creator);

explicit CastRuntimeContentBrowserClient(
CastFeatureListCreator* feature_list_creator);
~CastRuntimeContentBrowserClient() override;

// CastContentBrowserClient overrides:
std::unique_ptr<CastService> CreateCastService(
content::BrowserContext* browser_context,
CastSystemMemoryPressureEvaluatorAdjuster* memory_pressure_adjuster,
PrefService* pref_service,
media::VideoPlaneController* video_plane_controller,
CastWindowManager* window_manager) final;
};

} // namespace chromecast

#endif // CHROMECAST_CAST_CORE_CAST_RUNTIME_CONTENT_BROWSER_CLIENT_H_
17 changes: 17 additions & 0 deletions chromecast/cast_core/cast_runtime_content_browser_client_simple.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2021 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 "chromecast/cast_core/cast_runtime_content_browser_client.h"

namespace chromecast {

// static
std::unique_ptr<CastRuntimeContentBrowserClient>
CastRuntimeContentBrowserClient::Create(
CastFeatureListCreator* feature_list_creator) {
return std::make_unique<CastRuntimeContentBrowserClient>(
feature_list_creator);
}

} // namespace chromecast
4 changes: 2 additions & 2 deletions chromecast/cast_core/cast_runtime_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CastRuntimeContentRendererClient::~CastRuntimeContentRendererClient() = default;
void CastRuntimeContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
CastContentRendererClient::RenderFrameCreated(render_frame);
cast_streaming_renderer_client_.RenderFrameCreated(render_frame);
cast_streaming_demuxer_provider_.RenderFrameCreated(render_frame);
}

std::unique_ptr<::media::Demuxer>
Expand All @@ -36,7 +36,7 @@ CastRuntimeContentRendererClient::OverrideDemuxerForUrl(
return nullptr;
}

return cast_streaming_renderer_client_.OverrideDemuxerForUrl(
return cast_streaming_demuxer_provider_.OverrideDemuxerForUrl(
render_frame, url, std::move(media_task_runner));
}

Expand Down
5 changes: 2 additions & 3 deletions chromecast/cast_core/cast_runtime_content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <memory>

#include "chromecast/renderer/cast_content_renderer_client.h"
#include "components/cast_streaming/renderer/public/cast_streaming_content_renderer_client.h"
#include "components/cast_streaming/renderer/public/demuxer_provider.h"

namespace media {
class Demuxer;
Expand Down Expand Up @@ -38,8 +38,7 @@ class CastRuntimeContentRendererClient
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) override;

private:
cast_streaming::CastStreamingContentRendererClient
cast_streaming_renderer_client_;
cast_streaming::DemuxerProvider cast_streaming_demuxer_provider_;
};

} // namespace chromecast
Expand Down
14 changes: 14 additions & 0 deletions chromecast/cast_core/cast_runtime_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 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 "chromecast/app/cast_main_delegate.h"
#include "content/public/app/content_main.h"

int main(int argc, const char** argv) {
chromecast::shell::CastMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = argv;
return content::ContentMain(params);
}
47 changes: 47 additions & 0 deletions chromecast/cast_core/cast_runtime_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,58 @@
// found in the LICENSE file.

#include "chromecast/cast_core/cast_runtime_service.h"
#include "chromecast/chromecast_buildflags.h"

#if BUILDFLAG(ENABLE_CAST_MEDIA_RUNTIME)
#include "chromecast/browser/cast_browser_process.h" // nogncheck
#else // BUILDFLAG(ENABLE_CAST_MEDIA_RUNTIME)
#include "base/no_destructor.h"
#endif // BUILDFLAG(ENABLE_CAST_MEDIA_RUNTIME)

namespace chromecast {
namespace {

static std::string kFakeAudioChannelEndpoint = "";

} // namespace

// static
CastRuntimeService* CastRuntimeService::GetInstance() {
#if BUILDFLAG(ENABLE_CAST_MEDIA_RUNTIME)
DCHECK(shell::CastBrowserProcess::GetInstance());
auto* cast_service = shell::CastBrowserProcess::GetInstance()->cast_service();
DCHECK(cast_service);
return static_cast<CastRuntimeService*>(cast_service);
#else
// TODO(b/186668532): Instead use the CastService singleton instead of
// creating a new one with NoDestructor.
static base::NoDestructor<CastRuntimeService> g_instance;
return g_instance.get();
#endif // BUILDFLAG(ENABLE_CAST_MEDIA_RUNTIME)
}

CastRuntimeService::CastRuntimeService() = default;

CastRuntimeService::~CastRuntimeService() = default;

WebCryptoServer* CastRuntimeService::GetWebCryptoServer() {
return nullptr;
}

receiver::MediaManager* CastRuntimeService::GetMediaManager() {
return nullptr;
}

void CastRuntimeService::InitializeInternal() {}

void CastRuntimeService::FinalizeInternal() {}

void CastRuntimeService::StartInternal() {}

void CastRuntimeService::StopInternal() {}

const std::string& CastRuntimeService::GetAudioChannelEndpoint() {
return kFakeAudioChannelEndpoint;
}

} // namespace chromecast
42 changes: 36 additions & 6 deletions chromecast/cast_core/cast_runtime_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,66 @@
#ifndef CHROMECAST_CAST_CORE_CAST_RUNTIME_SERVICE_H_
#define CHROMECAST_CAST_CORE_CAST_RUNTIME_SERVICE_H_

#include <memory>

#include "base/memory/scoped_refptr.h"
#include "chromecast/media/cma/backend/proxy/cast_runtime_audio_channel_endpoint_manager.h"
#include "chromecast/service/cast_service.h"

class PrefService;

namespace base {
class SingleThreadTaskRunner;
} // namespace base

namespace content {
class BrowserContext;
} // namespace content

namespace chromecast {

class CastWindowManager;
class WebCryptoServer;

namespace media {
class MediaPipelineBackendManager;
} // namespace media

namespace receiver {
class MediaManager;
} // namespace receiver

// This interface is to be used for building the Cast Runtime Service and act as
// the border between shared Chromium code and the specifics of that
// implementation.
//
// NOTE: When adding a new interface to this class, first add it to all
// implementations of this interface in downstream repos. Else, the roll of this
// code into those repos will break.
class CastRuntimeService
: public CastService,
public media::CastRuntimeAudioChannelEndpointManager {
public:
static std::unique_ptr<CastRuntimeService> Create(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
content::BrowserContext* browser_context,
CastWindowManager* window_manager,
media::MediaPipelineBackendManager* media_pipeline_backend_manager,
PrefService* pref_service);

// Returns current instance of CastRuntimeService in the browser process.
static CastRuntimeService* GetInstance();

CastRuntimeService();
~CastRuntimeService() override;

virtual WebCryptoServer* GetWebCryptoServer() = 0;
virtual receiver::MediaManager* GetMediaManager() = 0;
virtual WebCryptoServer* GetWebCryptoServer();
virtual receiver::MediaManager* GetMediaManager();

// CastService overrides.
void InitializeInternal() override;
void FinalizeInternal() override;
void StartInternal() override;
void StopInternal() override;

// CastRuntimeAudioChannelEndpointManager overrides.
const std::string& GetAudioChannelEndpoint() override;
};

} // namespace chromecast
Expand Down

0 comments on commit 0781701

Please sign in to comment.