Commit c8c23733 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[vr] Register VR assets component from native

If running component updates in a background task we won't instantiate
an activity. As a consequence we won't register the VR assets component
and never get updates for it in the background. To solve this, register
the component in native.

The component gets only registered if the user has a Daydream headset
paired. Checking this is expensive. Thus, we save whether the component
should be registered in user preferences. At Chrome startup (which may
happen when running an update task in the background) read this flag
and conditionally register the component. Reading the flag took less
than 1 ms in my tests.

Change-Id: I1e9d0f6caab094307f8f3397c913cc1b7431d8fa
Reviewed-on: https://chromium-review.googlesource.com/1132147Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575038}
parent 2a578d44
// Copyright 2018 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.
package org.chromium.chrome.browser.component_updater;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
/** Java-side implementation of the VrAssetsComponentInstaller. */
@JNINamespace("component_updater")
public class VrAssetsComponentInstaller {
@CalledByNative
private static boolean shouldRegisterOnStartup() {
return ChromePreferenceManager.getInstance().getShouldRegisterVrAssetsComponentOnStartup();
}
}
......@@ -138,6 +138,9 @@ public class ChromePreferenceManager {
private static final String TRUSTED_WEB_ACTIVITY_LAST_DISCLOSURE_TIME =
"trusted_web_activity_last_disclosure_time:";
private static final String SHOULD_REGISTER_VR_ASSETS_COMPONENT_ON_STARTUP =
"should_register_vr_assets_component_on_startup";
private static class LazyHolder {
static final ChromePreferenceManager INSTANCE = new ChromePreferenceManager();
}
......@@ -532,6 +535,14 @@ public class ChromePreferenceManager {
mSharedPreferences.edit().putStringSet(VERIFIED_DIGITAL_ASSET_LINKS, links).apply();
}
public boolean getShouldRegisterVrAssetsComponentOnStartup() {
return mSharedPreferences.getBoolean(SHOULD_REGISTER_VR_ASSETS_COMPONENT_ON_STARTUP, false);
}
public void setShouldRegisterVrAssetsComponentOnStartup(boolean shouldRegister) {
writeBoolean(SHOULD_REGISTER_VR_ASSETS_COMPONENT_ON_STARTUP, shouldRegister);
}
/**
* Private convenience method to create a Preferences Key to hold the last time the given
* package displayed a "Running in Chrome" disclosure while opening a Trusted Web Activity.
......
......@@ -56,6 +56,7 @@ import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.webapps.WebappActivity;
......@@ -750,6 +751,8 @@ public class VrShellDelegate
nativeRegisterVrAssetsComponent();
sRegisteredVrAssetsComponent = true;
}
ChromePreferenceManager.getInstance().setShouldRegisterVrAssetsComponentOnStartup(
isDaydreamCurrentViewer);
}
/**
......
......@@ -1595,6 +1595,7 @@ chrome_java_sources = [
]
chrome_vr_java_sources = [
"java/src/org/chromium/chrome/browser/component_updater/VrAssetsComponentInstaller.java",
"java/src/org/chromium/chrome/browser/vr/AndroidUiGestureTarget.java",
"java/src/org/chromium/chrome/browser/vr/AndroidVSyncHelper.java",
"java/src/org/chromium/chrome/browser/vr/VrClassesWrapperImpl.java",
......
......@@ -4391,6 +4391,7 @@ if (is_android) {
"../android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountFeedbackReporter.java",
"../android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java",
"../android/java/src/org/chromium/chrome/browser/component_updater/UpdateScheduler.java",
"../android/java/src/org/chromium/chrome/browser/component_updater/VrAssetsComponentInstaller.java",
"../android/java/src/org/chromium/chrome/browser/compositor/CompositorView.java",
"../android/java/src/org/chromium/chrome/browser/compositor/LayerTitleCache.java",
"../android/java/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelContent.java",
......
......@@ -299,6 +299,7 @@
#endif // BUILDFLAG(ENABLE_RLZ)
#if BUILDFLAG(ENABLE_VR)
#include "chrome/browser/component_updater/vr_assets_component_installer.h"
#include "chrome/browser/vr/service/vr_service_impl.h"
#endif
......@@ -608,6 +609,12 @@ void RegisterComponentsForUpdate(PrefService* profile_prefs) {
RegisterInterventionPolicyDatabaseComponent(
cus, g_browser_process->GetTabManager()->intervention_policy_database());
#endif
#if BUILDFLAG(ENABLE_VR)
if (component_updater::ShouldRegisterVrAssetsComponentOnStartup()) {
component_updater::RegisterVrAssetsComponent(cus);
}
#endif
}
#if !defined(OS_ANDROID)
......
......@@ -18,6 +18,7 @@
#include "base/stl_util.h"
#include "base/task_scheduler/post_task.h"
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/browser/vr/assets_loader.h"
#include "chrome/browser/vr/metrics/metrics_helper.h"
#include "chrome/browser/vr/vr_features.h"
......@@ -26,6 +27,11 @@
#include "components/component_updater/component_updater_service.h"
#include "components/crx_file/id_util.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "jni/VrAssetsComponentInstaller_jni.h"
#endif // defined(OS_ANDROID)
using component_updater::ComponentUpdateService;
namespace {
......@@ -45,13 +51,28 @@ const base::FilePath::CharType kRelativeInstallDir[] =
namespace component_updater {
bool VrAssetsComponentInstallerPolicy::registered_component_ = false;
bool VrAssetsComponentInstallerPolicy::registration_pending_ = false;
bool VrAssetsComponentInstallerPolicy::ondemand_update_pending_ = false;
// static
bool VrAssetsComponentInstallerPolicy::
ShouldRegisterVrAssetsComponentOnStartup() {
#if defined(OS_ANDROID)
return Java_VrAssetsComponentInstaller_shouldRegisterOnStartup(
base::android::AttachCurrentThread());
#else // defined(OS_ANDROID)
return false;
#endif // defined(OS_ANDROID)
}
// static
void VrAssetsComponentInstallerPolicy::RegisterComponent(
ComponentUpdateService* cus) {
#if BUILDFLAG(USE_VR_ASSETS_COMPONENT)
if (registration_pending_ || registered_component_) {
return;
}
const std::string crx_id = crx_file::id_util::GenerateIdFromHash(
kVrAssetsPublicKeySHA256, sizeof(kVrAssetsPublicKeySHA256));
std::unique_ptr<VrAssetsComponentInstallerPolicy> policy(
......@@ -90,6 +111,7 @@ void VrAssetsComponentInstallerPolicy::OnRegisteredComponent(
vr::AssetsLoader::GetInstance()->GetMetricsHelper()->OnRegisteredComponent();
VLOG(1) << "Registered VR assets component";
registration_pending_ = false;
registered_component_ = true;
if (ondemand_update_pending_) {
UpdateComponent(cus);
}
......@@ -184,6 +206,11 @@ std::vector<std::string> VrAssetsComponentInstallerPolicy::GetMimeTypes()
return std::vector<std::string>();
}
bool ShouldRegisterVrAssetsComponentOnStartup() {
return VrAssetsComponentInstallerPolicy::
ShouldRegisterVrAssetsComponentOnStartup();
}
void RegisterVrAssetsComponent(ComponentUpdateService* cus) {
VrAssetsComponentInstallerPolicy::RegisterComponent(cus);
}
......
......@@ -30,6 +30,7 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy {
~VrAssetsComponentInstallerPolicy() override {}
private:
static bool ShouldRegisterVrAssetsComponentOnStartup();
static void RegisterComponent(ComponentUpdateService* cus);
static void UpdateComponent(ComponentUpdateService* cus);
static void OnRegisteredComponent(ComponentUpdateService* cus);
......@@ -52,15 +53,20 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy {
update_client::InstallerAttributes GetInstallerAttributes() const override;
std::vector<std::string> GetMimeTypes() const override;
static bool registered_component_;
static bool registration_pending_;
static bool ondemand_update_pending_;
friend bool ShouldRegisterVrAssetsComponentOnStartup();
friend void RegisterVrAssetsComponent(ComponentUpdateService* cus);
friend void UpdateVrAssetsComponent(ComponentUpdateService* cus);
DISALLOW_COPY_AND_ASSIGN(VrAssetsComponentInstallerPolicy);
};
// Returns true if the assets component should be registered at startup.
bool ShouldRegisterVrAssetsComponentOnStartup();
// Call once to make the component update service aware of the VR Assets
// component.
void RegisterVrAssetsComponent(ComponentUpdateService* cus);
......
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