Commit 9d701718 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[vr] Make sure to ondemand update assets component when entering VR

Previously, there was a race condition. The ondemand update could be
requested before the component was registered.

Bug: 851666
Change-Id: I5d2162a87748f93bdf902f78c8cbe63292d65201
Reviewed-on: https://chromium-review.googlesource.com/1097705
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567275}
parent fbbfa7ea
...@@ -1243,6 +1243,10 @@ public class VrShellDelegate ...@@ -1243,6 +1243,10 @@ public class VrShellDelegate
addVrViews(); addVrViews();
boolean webVrMode = mRequestedWebVr || tentativeWebVrMode || mAutopresentWebVr; boolean webVrMode = mRequestedWebVr || tentativeWebVrMode || mAutopresentWebVr;
// Make sure that assets component is registered when creating native VR shell.
if (!sRegisteredVrAssetsComponent) {
registerVrAssetsComponentIfDaydreamUser(isDaydreamCurrentViewer());
}
mVrShell.initializeNative(webVrMode, mAutopresentWebVr, mVrShell.initializeNative(webVrMode, mAutopresentWebVr,
mActivity instanceof CustomTabActivity, getVrClassesWrapper().bootsToVr()); mActivity instanceof CustomTabActivity, getVrClassesWrapper().bootsToVr());
mVrShell.setWebVrModeEnabled(webVrMode); mVrShell.setWebVrModeEnabled(webVrMode);
......
...@@ -45,10 +45,35 @@ const base::FilePath::CharType kRelativeInstallDir[] = ...@@ -45,10 +45,35 @@ const base::FilePath::CharType kRelativeInstallDir[] =
namespace component_updater { namespace component_updater {
bool VrAssetsComponentInstallerPolicy::registration_pending_ = false;
bool VrAssetsComponentInstallerPolicy::ondemand_update_pending_ = false;
// static
void VrAssetsComponentInstallerPolicy::RegisterComponent(
ComponentUpdateService* cus) {
#if BUILDFLAG(USE_VR_ASSETS_COMPONENT)
const std::string crx_id = crx_file::id_util::GenerateIdFromHash(
kVrAssetsPublicKeySHA256, sizeof(kVrAssetsPublicKeySHA256));
std::unique_ptr<VrAssetsComponentInstallerPolicy> policy(
new VrAssetsComponentInstallerPolicy());
auto installer = base::MakeRefCounted<ComponentInstaller>(std::move(policy));
registration_pending_ = true;
installer->Register(
cus,
base::BindOnce(&VrAssetsComponentInstallerPolicy::OnRegisteredComponent,
base::Unretained(cus)));
#endif // BUILDFLAG(USE_VR_ASSETS_COMPONENT)
}
// static // static
void VrAssetsComponentInstallerPolicy::UpdateComponent( void VrAssetsComponentInstallerPolicy::UpdateComponent(
ComponentUpdateService* cus) { ComponentUpdateService* cus) {
#if BUILDFLAG(USE_VR_ASSETS_COMPONENT) #if BUILDFLAG(USE_VR_ASSETS_COMPONENT)
if (registration_pending_) {
ondemand_update_pending_ = true;
return;
}
ondemand_update_pending_ = false;
const std::string crx_id = crx_file::id_util::GenerateIdFromHash( const std::string crx_id = crx_file::id_util::GenerateIdFromHash(
kVrAssetsPublicKeySHA256, sizeof(kVrAssetsPublicKeySHA256)); kVrAssetsPublicKeySHA256, sizeof(kVrAssetsPublicKeySHA256));
// Make sure the component is registered. // Make sure the component is registered.
...@@ -58,6 +83,17 @@ void VrAssetsComponentInstallerPolicy::UpdateComponent( ...@@ -58,6 +83,17 @@ void VrAssetsComponentInstallerPolicy::UpdateComponent(
#endif // BUILDFLAG(USE_VR_ASSETS_COMPONENT) #endif // BUILDFLAG(USE_VR_ASSETS_COMPONENT)
} }
// static
void VrAssetsComponentInstallerPolicy::OnRegisteredComponent(
ComponentUpdateService* cus) {
vr::AssetsLoader::GetInstance()->GetMetricsHelper()->OnRegisteredComponent();
VLOG(1) << "Registered VR assets component";
registration_pending_ = false;
if (ondemand_update_pending_) {
UpdateComponent(cus);
}
}
bool VrAssetsComponentInstallerPolicy:: bool VrAssetsComponentInstallerPolicy::
SupportsGroupPolicyEnabledComponentUpdates() const { SupportsGroupPolicyEnabledComponentUpdates() const {
return false; return false;
...@@ -148,14 +184,7 @@ std::vector<std::string> VrAssetsComponentInstallerPolicy::GetMimeTypes() ...@@ -148,14 +184,7 @@ std::vector<std::string> VrAssetsComponentInstallerPolicy::GetMimeTypes()
} }
void RegisterVrAssetsComponent(ComponentUpdateService* cus) { void RegisterVrAssetsComponent(ComponentUpdateService* cus) {
#if BUILDFLAG(USE_VR_ASSETS_COMPONENT) VrAssetsComponentInstallerPolicy::RegisterComponent(cus);
std::unique_ptr<ComponentInstallerPolicy> policy(
new VrAssetsComponentInstallerPolicy());
auto installer = base::MakeRefCounted<ComponentInstaller>(std::move(policy));
installer->Register(cus, base::Closure());
vr::AssetsLoader::GetInstance()->GetMetricsHelper()->OnRegisteredComponent();
VLOG(1) << "Registered VR assets component";
#endif // BUILDFLAG(USE_VR_ASSETS_COMPONENT)
} }
void UpdateVrAssetsComponent(ComponentUpdateService* cus) { void UpdateVrAssetsComponent(ComponentUpdateService* cus) {
......
...@@ -30,7 +30,9 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy { ...@@ -30,7 +30,9 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy {
~VrAssetsComponentInstallerPolicy() override {} ~VrAssetsComponentInstallerPolicy() override {}
private: private:
static void RegisterComponent(ComponentUpdateService* cus);
static void UpdateComponent(ComponentUpdateService* cus); static void UpdateComponent(ComponentUpdateService* cus);
static void OnRegisteredComponent(ComponentUpdateService* cus);
// ComponentInstallerPolicy: // ComponentInstallerPolicy:
bool SupportsGroupPolicyEnabledComponentUpdates() const override; bool SupportsGroupPolicyEnabledComponentUpdates() const override;
...@@ -50,6 +52,10 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy { ...@@ -50,6 +52,10 @@ class VrAssetsComponentInstallerPolicy : public ComponentInstallerPolicy {
update_client::InstallerAttributes GetInstallerAttributes() const override; update_client::InstallerAttributes GetInstallerAttributes() const override;
std::vector<std::string> GetMimeTypes() const override; std::vector<std::string> GetMimeTypes() const override;
static bool registration_pending_;
static bool ondemand_update_pending_;
friend void RegisterVrAssetsComponent(ComponentUpdateService* cus);
friend void UpdateVrAssetsComponent(ComponentUpdateService* cus); friend void UpdateVrAssetsComponent(ComponentUpdateService* cus);
DISALLOW_COPY_AND_ASSIGN(VrAssetsComponentInstallerPolicy); DISALLOW_COPY_AND_ASSIGN(VrAssetsComponentInstallerPolicy);
......
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