Commit 247e39e3 authored by Aidan Wolter's avatar Aidan Wolter Committed by Commit Bot

Add parameter for telling apps to start as services

This will allow apps to be conditionally started as
services. The enable_headless_music_mode flag is also added.

Bug: internal b/64904346
Test: Set the enable_headless_music_mode flag and test that GPM and YTM start as services.
Change-Id: Ibbdf4f1874438288659bd4988567a5826986a538
Reviewed-on: https://chromium-review.googlesource.com/654298
Commit-Queue: Aidan Wolter <awolter@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501357}
parent b06b8dfa
......@@ -492,6 +492,7 @@ buildflag_header("chromecast_features") {
"IS_CAST_AUDIO_ONLY=$is_cast_audio_only",
"IS_CAST_USING_CMA_BACKEND=$is_cast_using_cma_backend",
"SUPPORTS_MULTIZONE=$supports_multizone",
"ENABLE_HEADLESS_MUSIC_MODE=$enable_headless_music_mode",
]
}
......
......@@ -35,17 +35,19 @@ public class CastContentWindowAndroid implements CastWebContentsComponent.OnComp
@SuppressWarnings("unused")
@CalledByNative
private static CastContentWindowAndroid create(long nativeCastContentWindowAndroid) {
private static CastContentWindowAndroid create(
long nativeCastContentWindowAndroid, boolean isHeadless) {
return new CastContentWindowAndroid(
nativeCastContentWindowAndroid, ContextUtils.getApplicationContext());
nativeCastContentWindowAndroid, ContextUtils.getApplicationContext(), isHeadless);
}
private CastContentWindowAndroid(long nativeCastContentWindowAndroid, final Context context) {
private CastContentWindowAndroid(
long nativeCastContentWindowAndroid, final Context context, boolean isHeadless) {
mNativeCastContentWindowAndroid = nativeCastContentWindowAndroid;
mContext = context;
mInstanceId = Integer.toString(sInstanceId++);
mComponent = new CastWebContentsComponent(mInstanceId, this, this);
mComponent = new CastWebContentsComponent(mInstanceId, this, this, isHeadless);
}
@SuppressWarnings("unused")
......
......@@ -140,11 +140,12 @@ public class CastWebContentsComponent {
private boolean mStarted = false;
public CastWebContentsComponent(String instanceId,
OnComponentClosedHandler onComponentClosedHandler, OnKeyDownHandler onKeyDownHandler) {
OnComponentClosedHandler onComponentClosedHandler, OnKeyDownHandler onKeyDownHandler,
boolean isHeadless) {
mComponentClosedHandler = onComponentClosedHandler;
mKeyDownHandler = onKeyDownHandler;
mInstanceId = instanceId;
if (BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE) {
if (BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE || isHeadless) {
mDelegate = new ServiceDelegate();
} else {
mDelegate = new ActivityDelegate();
......
......@@ -18,23 +18,25 @@ namespace chromecast {
namespace shell {
namespace {
base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(
jlong nativeWindow) {
base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(jlong nativeWindow,
bool isHeadless) {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_CastContentWindowAndroid_create(env, nativeWindow);
return Java_CastContentWindowAndroid_create(env, nativeWindow, isHeadless);
}
} // namespace
// static
std::unique_ptr<CastContentWindow> CastContentWindow::Create(
CastContentWindow::Delegate* delegate) {
return base::WrapUnique(new CastContentWindowAndroid(delegate));
CastContentWindow::Delegate* delegate,
bool isHeadless) {
return base::WrapUnique(new CastContentWindowAndroid(delegate, isHeadless));
}
CastContentWindowAndroid::CastContentWindowAndroid(
CastContentWindow::Delegate* delegate)
CastContentWindow::Delegate* delegate,
bool isHeadless)
: delegate_(delegate),
java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this))) {
java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this), isHeadless)) {
DCHECK(delegate_);
}
......
......@@ -42,7 +42,8 @@ class CastContentWindowAndroid : public CastContentWindow {
friend class CastContentWindow;
// This class should only be instantiated by CastContentWindow::Create.
explicit CastContentWindowAndroid(CastContentWindow::Delegate* delegate);
CastContentWindowAndroid(CastContentWindow::Delegate* delegate,
bool isHeadless);
CastContentWindow::Delegate* const delegate_;
base::android::ScopedJavaGlobalRef<jobject> java_window_;
......
......@@ -38,7 +38,8 @@ class CastContentWindow {
// Creates the platform specific CastContentWindow. |delegate| should outlive
// the created CastContentWindow.
static std::unique_ptr<CastContentWindow> Create(
CastContentWindow::Delegate* delegate);
CastContentWindow::Delegate* delegate,
bool is_headless);
virtual ~CastContentWindow() {}
......
......@@ -21,7 +21,7 @@ namespace shell {
// static
std::unique_ptr<CastContentWindow> CastContentWindow::Create(
CastContentWindow::Delegate* delegate) {
CastContentWindow::Delegate* delegate, bool is_headless) {
DCHECK(delegate);
return base::WrapUnique(new CastContentWindowLinux());
}
......
......@@ -34,11 +34,12 @@ std::unique_ptr<CastWebView> CastWebContentsManager::CreateWebView(
CastWebView::Delegate* delegate,
scoped_refptr<content::SiteInstance> site_instance,
bool transparent,
bool allow_media_access) {
bool allow_media_access,
bool is_headless) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::MakeUnique<CastWebView>(delegate, this, browser_context_,
site_instance, transparent,
allow_media_access);
allow_media_access, is_headless);
}
void CastWebContentsManager::DelayWebContentsDeletion(
......
......@@ -39,7 +39,8 @@ class CastWebContentsManager {
CastWebView::Delegate* delegate,
scoped_refptr<content::SiteInstance> site_instance,
bool transparent,
bool allow_media_access);
bool allow_media_access,
bool is_headless);
// Take ownership of |web_contents| and delete after |time_delta|, or sooner
// if necessary.
......
......@@ -60,14 +60,15 @@ CastWebView::CastWebView(Delegate* delegate,
content::BrowserContext* browser_context,
scoped_refptr<content::SiteInstance> site_instance,
bool transparent,
bool allow_media_access)
bool allow_media_access,
bool is_headless)
: delegate_(delegate),
web_contents_manager_(web_contents_manager),
browser_context_(browser_context),
site_instance_(std::move(site_instance)),
transparent_(transparent),
web_contents_(CreateWebContents(browser_context_, site_instance_)),
window_(shell::CastContentWindow::Create(delegate)),
window_(shell::CastContentWindow::Create(delegate, is_headless)),
did_start_navigation_(false),
allow_media_access_(allow_media_access),
weak_factory_(this) {
......
......@@ -48,7 +48,8 @@ class CastWebView : content::WebContentsObserver, content::WebContentsDelegate {
content::BrowserContext* browser_context,
scoped_refptr<content::SiteInstance> site_instance,
bool transparent,
bool allow_media_access);
bool allow_media_access,
bool is_headless);
~CastWebView() override;
shell::CastContentWindow* window() const { return window_.get(); }
......
......@@ -64,7 +64,7 @@ void CastServiceSimple::StartInternal() {
cast_web_view_ = web_contents_manager_->CreateWebView(
this, /*site_instance*/ nullptr, /*transparent*/ false,
false /*allow_media_access*/);
false /*allow_media_access*/, /*is_headless*/ false);
cast_web_view_->LoadUrl(startup_url_);
cast_web_view_->Show(window_manager_);
}
......
......@@ -56,7 +56,7 @@ void CastBrowserTest::PostRunTestOnMainThread() {
content::WebContents* CastBrowserTest::NavigateToURL(const GURL& url) {
cast_web_view_ = web_contents_manager_->CreateWebView(
this, nullptr /*site_instance*/, false /*transparent*/,
false /*allow_media_access*/);
false /*allow_media_access*/, false /*is_headless*/);
content::WebContents* web_contents = cast_web_view_->web_contents();
content::WaitForLoadStop(web_contents);
......
......@@ -47,6 +47,9 @@ declare_args() {
# Set true for builds targeting Android Things.
is_android_things = false
# Set to true to start music apps in headless mode.
enable_headless_music_mode = false
}
declare_args() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment