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

[vr] Use asset component version 1.y

This change configures Chrome to
- Download asset component version 1.y,
- Load and decode background.png/.jpeg,
- Only register assets component on Chromes (not Chromiums).

Bug: 793977, 793405, 793384
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I33de68ac0c3317360c0e26ae4274242e87092ff5
Reviewed-on: https://chromium-review.googlesource.com/822835
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarBiao She <bshe@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524117}
parent af332439
...@@ -24,6 +24,7 @@ import("//rlz/features/features.gni") ...@@ -24,6 +24,7 @@ import("//rlz/features/features.gni")
import("//sandbox/features.gni") import("//sandbox/features.gni")
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
import("//ui/base/ui_features.gni") import("//ui/base/ui_features.gni")
import("//build/buildflag_header.gni")
# //build/config/android/rules.gni imports //tools/grit/grit_rule.gni, which # //build/config/android/rules.gni imports //tools/grit/grit_rule.gni, which
# produces a conflict for the "grit" template so we have to only include one. # produces a conflict for the "grit" template so we have to only include one.
...@@ -33,6 +34,10 @@ if (is_android) { ...@@ -33,6 +34,10 @@ if (is_android) {
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
} }
if (enable_vr) {
import("//chrome/browser/vr/features.gni")
}
additional_modules_list_file = additional_modules_list_file =
"$root_gen_dir/chrome/browser/internal/additional_modules_list.txt" "$root_gen_dir/chrome/browser/internal/additional_modules_list.txt"
...@@ -56,6 +61,13 @@ if (is_win) { ...@@ -56,6 +61,13 @@ if (is_win) {
} }
} }
if (enable_vr) {
buildflag_header("vr_build_features") {
header = "vr_features.h"
flags = [ "REGISTER_VR_ASSETS_COMPONENT=$register_vr_assets_component" ]
}
}
# Use a static library here because many test binaries depend on this but don't # Use a static library here because many test binaries depend on this but don't
# require many files from it. This makes linking more efficient. # require many files from it. This makes linking more efficient.
split_static_library("browser") { split_static_library("browser") {
...@@ -4028,8 +4040,12 @@ split_static_library("browser") { ...@@ -4028,8 +4040,12 @@ split_static_library("browser") {
sources += [ sources += [
"component_updater/vr_assets_component_installer.cc", "component_updater/vr_assets_component_installer.cc",
"component_updater/vr_assets_component_installer.h", "component_updater/vr_assets_component_installer.h",
"vr_features.h",
]
deps += [
":vr_build_features",
"//chrome/browser/vr:vr_common",
] ]
deps += [ "//chrome/browser/vr:vr_common" ]
} }
if (enable_wayland_server) { if (enable_wayland_server) {
......
...@@ -1296,25 +1296,16 @@ void VrShellGl::ClosePresentationBindings() { ...@@ -1296,25 +1296,16 @@ void VrShellGl::ClosePresentationBindings() {
binding_.Close(); binding_.Close();
} }
void VrShellGl::OnAssetsLoaded(bool success, void VrShellGl::OnAssetsLoaded(vr::AssetsLoadStatus status,
std::string environment, std::unique_ptr<SkBitmap> background_image,
const base::Version& component_version) { const base::Version& component_version) {
if (success && environment == "zq7sax8chrtjchxysh7b\n") { // TODO(793407): Handle adding background image to UI.
if (status == vr::AssetsLoadStatus::kSuccess) {
VLOG(1) << "Successfully loaded VR assets component"; VLOG(1) << "Successfully loaded VR assets component";
} else { } else {
VLOG(1) << "Failed to load VR assets component"; VLOG(1) << "Failed to load VR assets component";
} }
if (!success) { browser_->OnAssetsLoaded(status, component_version);
browser_->OnAssetsLoaded(vr::AssetsLoadStatus::kParseFailure,
component_version);
return;
}
if (environment != "zq7sax8chrtjchxysh7b\n") {
browser_->OnAssetsLoaded(vr::AssetsLoadStatus::kInvalidContent,
component_version);
return;
}
browser_->OnAssetsLoaded(vr::AssetsLoadStatus::kSuccess, component_version);
} }
} // namespace vr_shell } // namespace vr_shell
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "chrome/browser/android/vr_shell/android_vsync_helper.h" #include "chrome/browser/android/vr_shell/android_vsync_helper.h"
#include "chrome/browser/android/vr_shell/vr_controller.h" #include "chrome/browser/android/vr_shell/vr_controller.h"
#include "chrome/browser/vr/assets_load_status.h"
#include "chrome/browser/vr/content_input_delegate.h" #include "chrome/browser/vr/content_input_delegate.h"
#include "chrome/browser/vr/controller_mesh.h" #include "chrome/browser/vr/controller_mesh.h"
#include "chrome/browser/vr/fps_meter.h" #include "chrome/browser/vr/fps_meter.h"
...@@ -177,8 +178,8 @@ class VrShellGl : public device::mojom::VRPresentationProvider { ...@@ -177,8 +178,8 @@ class VrShellGl : public device::mojom::VRPresentationProvider {
void ClosePresentationBindings(); void ClosePresentationBindings();
void OnAssetsLoaded(bool success, void OnAssetsLoaded(vr::AssetsLoadStatus status,
std::string environment, std::unique_ptr<SkBitmap> background_image,
const base::Version& component_version); const base::Version& component_version);
// samplerExternalOES texture data for WebVR content image. // samplerExternalOES texture data for WebVR content image.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/vr/assets.h" #include "chrome/browser/vr/assets.h"
#include "chrome/browser/vr/metrics_helper.h" #include "chrome/browser/vr/metrics_helper.h"
#include "chrome/browser/vr_features.h"
#include "chrome/common/safe_browsing/file_type_policies.h" #include "chrome/common/safe_browsing/file_type_policies.h"
#include "components/component_updater/component_updater_paths.h" #include "components/component_updater/component_updater_paths.h"
...@@ -121,7 +122,8 @@ std::string VrAssetsComponentInstallerTraits::GetName() const { ...@@ -121,7 +122,8 @@ std::string VrAssetsComponentInstallerTraits::GetName() const {
update_client::InstallerAttributes update_client::InstallerAttributes
VrAssetsComponentInstallerTraits::GetInstallerAttributes() const { VrAssetsComponentInstallerTraits::GetInstallerAttributes() const {
return update_client::InstallerAttributes(); return {{"compatible_major_version",
std::to_string(vr::kCompatibleMajorVrAssetsComponentVersion)}};
} }
std::vector<std::string> VrAssetsComponentInstallerTraits::GetMimeTypes() std::vector<std::string> VrAssetsComponentInstallerTraits::GetMimeTypes()
...@@ -130,12 +132,14 @@ std::vector<std::string> VrAssetsComponentInstallerTraits::GetMimeTypes() ...@@ -130,12 +132,14 @@ std::vector<std::string> VrAssetsComponentInstallerTraits::GetMimeTypes()
} }
void RegisterVrAssetsComponent(ComponentUpdateService* cus) { void RegisterVrAssetsComponent(ComponentUpdateService* cus) {
#if BUILDFLAG(REGISTER_VR_ASSETS_COMPONENT)
std::unique_ptr<ComponentInstallerPolicy> policy( std::unique_ptr<ComponentInstallerPolicy> policy(
new VrAssetsComponentInstallerTraits()); new VrAssetsComponentInstallerTraits());
auto installer = base::MakeRefCounted<ComponentInstaller>(std::move(policy)); auto installer = base::MakeRefCounted<ComponentInstaller>(std::move(policy));
installer->Register(cus, base::Closure()); installer->Register(cus, base::Closure());
vr::Assets::GetInstance()->GetMetricsHelper()->OnRegisteredComponent(); vr::Assets::GetInstance()->GetMetricsHelper()->OnRegisteredComponent();
VLOG(1) << "Registered VR assets component"; VLOG(1) << "Registered VR assets component";
#endif // BUILDFLAG(REGISTER_VR_ASSETS_COMPONENT)
} }
} // namespace component_updater } // namespace component_updater
...@@ -13,13 +13,18 @@ ...@@ -13,13 +13,18 @@
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/vr/metrics_helper.h" #include "chrome/browser/vr/metrics_helper.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
namespace vr { namespace vr {
namespace { namespace {
static const base::FilePath::CharType kEnvironmentFileName[] = static const base::FilePath::CharType kBackgroundFileNamePng[] =
FILE_PATH_LITERAL("environment"); FILE_PATH_LITERAL("background.png");
static const base::FilePath::CharType kBackgroundFileNameJpeg[] =
FILE_PATH_LITERAL("background.jpeg");
} // namespace } // namespace
...@@ -69,18 +74,60 @@ void Assets::LoadAssetsTask( ...@@ -69,18 +74,60 @@ void Assets::LoadAssetsTask(
const base::Version& component_version, const base::Version& component_version,
const base::FilePath& component_install_dir, const base::FilePath& component_install_dir,
OnAssetsLoadedCallback on_loaded) { OnAssetsLoadedCallback on_loaded) {
std::string environment; std::string background_file_content;
if (!base::ReadFileToString( base::FilePath background_file_path;
component_install_dir.Append(kEnvironmentFileName), &environment)) { bool is_png = false;
if (base::PathExists(component_install_dir.Append(kBackgroundFileNamePng))) {
background_file_path = component_install_dir.Append(kBackgroundFileNamePng);
is_png = true;
} else if (base::PathExists(
component_install_dir.Append(kBackgroundFileNameJpeg))) {
background_file_path =
component_install_dir.Append(kBackgroundFileNameJpeg);
} else {
task_runner->PostTask( task_runner->PostTask(
FROM_HERE, base::BindOnce(std::move(on_loaded), false, std::string(), FROM_HERE,
component_version)); base::BindOnce(std::move(on_loaded), AssetsLoadStatus::kNotFound,
nullptr, component_version));
return; return;
} }
task_runner->PostTask(FROM_HERE, if (!base::ReadFileToString(background_file_path, &background_file_content)) {
base::BindOnce(std::move(on_loaded), true, environment, task_runner->PostTask(
component_version)); FROM_HERE,
base::BindOnce(std::move(on_loaded), AssetsLoadStatus::kParseFailure,
nullptr, component_version));
return;
}
std::unique_ptr<SkBitmap> background_image;
if (is_png) {
background_image = base::MakeUnique<SkBitmap>();
if (!gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(
background_file_content.data()),
background_file_content.size(),
background_image.get())) {
background_image = nullptr;
}
} else {
background_image = gfx::JPEGCodec::Decode(
reinterpret_cast<const unsigned char*>(background_file_content.data()),
background_file_content.size());
}
if (!background_image) {
task_runner->PostTask(
FROM_HERE,
base::BindOnce(std::move(on_loaded), AssetsLoadStatus::kInvalidContent,
nullptr, component_version));
return;
}
task_runner->PostTask(
FROM_HERE,
base::BindOnce(std::move(on_loaded), AssetsLoadStatus::kSuccess,
std::move(background_image), component_version));
} }
Assets::Assets() Assets::Assets()
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/version.h" #include "base/version.h"
#include "chrome/browser/vr/assets_load_status.h"
class SkBitmap;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
...@@ -21,7 +24,7 @@ class Version; ...@@ -21,7 +24,7 @@ class Version;
namespace vr { namespace vr {
constexpr uint32_t kCompatibleMajorVrAssetsComponentVersion = 0; constexpr uint32_t kCompatibleMajorVrAssetsComponentVersion = 1;
class MetricsHelper; class MetricsHelper;
struct AssetsSingletonTrait; struct AssetsSingletonTrait;
...@@ -35,8 +38,8 @@ struct AssetsSingletonTrait; ...@@ -35,8 +38,8 @@ struct AssetsSingletonTrait;
// performed on a worker thread. // performed on a worker thread.
class Assets { class Assets {
public: public:
typedef base::OnceCallback<void(bool success, typedef base::OnceCallback<void(AssetsLoadStatus status,
std::string environment, std::unique_ptr<SkBitmap> background_image,
const base::Version& component_version)> const base::Version& component_version)>
OnAssetsLoadedCallback; OnAssetsLoadedCallback;
......
...@@ -15,9 +15,11 @@ namespace vr { ...@@ -15,9 +15,11 @@ namespace vr {
// reference in // reference in
// //tools/metrics/histograms/histograms.xml. // //tools/metrics/histograms/histograms.xml.
enum class AssetsLoadStatus : int { enum class AssetsLoadStatus : int {
kSuccess = 0, // Assets loaded successfully. kSuccess = 0, // Assets loaded successfully.
kParseFailure = 1, // Failed to load assets. kParseFailure = 1, // Failed to load assets.
kInvalidContent = 2, // Content of assets files is invalid. kInvalidContent =
2, // Content of assets files is invalid, e.g. it couldn't be decoded.
kNotFound = 3, // Could not find asset files.
}; };
} // namespace vr } // namespace vr
......
# Copyright 2017 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.
import("//build/config/chrome_build.gni")
import("//device/vr/features/features.gni")
assert(enable_vr)
declare_args() {
# Whether to register and subsequently download the VR assets component.
register_vr_assets_component = is_chrome_branded
}
...@@ -43491,6 +43491,8 @@ Called by update_traffic_annotation_histograms.py.--> ...@@ -43491,6 +43491,8 @@ Called by update_traffic_annotation_histograms.py.-->
label="Failed to load assets from disk (component version 0.1)."/> label="Failed to load assets from disk (component version 0.1)."/>
<int value="1002" <int value="1002"
label="Assets have an invalid content (component version 0.1)."/> label="Assets have an invalid content (component version 0.1)."/>
<int value="1000003"
label="Assets file(s) not found (component version 1.0)."/>
</enum> </enum>
<enum name="VRComponentStatus"> <enum name="VRComponentStatus">
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