3535#include " chrome/browser/profiles/profile_manager.h"
3636#include " chrome/browser/vr/assets_loader.h"
3737#include " chrome/browser/vr/metrics_helper.h"
38+ #include " chrome/browser/vr/model/assets.h"
3839#include " chrome/browser/vr/model/omnibox_suggestions.h"
3940#include " chrome/browser/vr/model/text_input_info.h"
4041#include " chrome/browser/vr/toolbar_helper.h"
@@ -87,6 +88,9 @@ constexpr base::TimeDelta poll_media_access_interval_ =
8788constexpr base::TimeDelta kExitVrDueToUnsupportedModeDelay =
8889 base::TimeDelta::FromSeconds (5 );
8990
91+ constexpr base::TimeDelta kAssetsComponentWaitDelay =
92+ base::TimeDelta::FromSeconds (2 );
93+
9094static constexpr float kInchesToMeters = 0 .0254f ;
9195// Screen pixel density of the Google Pixel phone in pixels per inch.
9296static constexpr float kPixelPpi = 441 .0f ;
@@ -144,6 +148,7 @@ VrShell::VrShell(JNIEnv* env,
144148 reprojected_rendering_(reprojected_rendering),
145149 display_size_meters_(display_width_meters, display_height_meters),
146150 display_size_pixels_(display_width_pixels, display_height_pixels),
151+ waiting_for_assets_component_timer_(false , false ),
147152 weak_ptr_factory_(this ) {
148153 DVLOG (1 ) << __FUNCTION__ << " =" << this ;
149154 DCHECK (g_vr_shell_instance == nullptr );
@@ -168,6 +173,15 @@ VrShell::VrShell(JNIEnv* env,
168173 ui_initial_state.web_vr_autopresentation_expected );
169174 }
170175
176+ if (AssetsLoader::GetInstance ()->ComponentReady ()) {
177+ LoadAssets ();
178+ } else {
179+ waiting_for_assets_component_timer_.Start (
180+ FROM_HERE, kAssetsComponentWaitDelay ,
181+ base::BindRepeating (&VrShell::OnAssetsComponentWaitTimeout,
182+ weak_ptr_factory_.GetWeakPtr ()));
183+ }
184+
171185 AssetsLoader::GetInstance ()->SetOnComponentReadyCallback (base::BindRepeating (
172186 &VrShell::OnAssetsComponentReady, weak_ptr_factory_.GetWeakPtr ()));
173187 AssetsLoader::GetInstance ()->GetMetricsHelper ()->OnEnter (Mode::kVr );
@@ -991,8 +1005,16 @@ void VrShell::OnVoiceResults(const base::string16& result) {
9911005 base::android::ConvertUTF8ToJavaString (env, url.spec ()));
9921006}
9931007
1008+ void VrShell::LoadAssets () {
1009+ AssetsLoader::GetInstance ()->Load (
1010+ base::BindOnce (&VrShell::OnAssetsLoaded, base::Unretained (this )));
1011+ }
1012+
9941013void VrShell::OnAssetsLoaded (AssetsLoadStatus status,
1014+ std::unique_ptr<Assets> assets,
9951015 const base::Version& component_version) {
1016+ ui_->OnAssetsLoaded (status, std::move (assets), component_version);
1017+
9961018 if (status == AssetsLoadStatus::kSuccess ) {
9971019 VLOG (1 ) << " Successfully loaded VR assets component" ;
9981020 } else {
@@ -1004,7 +1026,16 @@ void VrShell::OnAssetsLoaded(AssetsLoadStatus status,
10041026}
10051027
10061028void VrShell::OnAssetsComponentReady () {
1007- ui_->OnAssetsComponentReady ();
1029+ if (waiting_for_assets_component_timer_.IsRunning ()) {
1030+ waiting_for_assets_component_timer_.Stop ();
1031+ LoadAssets ();
1032+ } else {
1033+ ui_->OnAssetsComponentReady ();
1034+ }
1035+ }
1036+
1037+ void VrShell::OnAssetsComponentWaitTimeout () {
1038+ ui_->OnAssetsUnavailable ();
10081039}
10091040
10101041void VrShell::AcceptDoffPromptForTesting (
@@ -1044,8 +1075,7 @@ jlong JNI_VrShellImpl_Init(JNIEnv* env,
10441075 has_or_can_request_audio_permission;
10451076 ui_initial_state.skips_redraw_when_not_dirty =
10461077 base::FeatureList::IsEnabled (features::kVrBrowsingExperimentalRendering );
1047- ui_initial_state.assets_available =
1048- AssetsLoader::GetInstance ()->ComponentReady ();
1078+ ui_initial_state.assets_available = true ;
10491079
10501080 return reinterpret_cast <intptr_t >(new VrShell (
10511081 env, obj, ui_initial_state,
0 commit comments