Skip to content

Commit 64bc2a9

Browse files
author
Tibor Goldschwendt
committed
[vr] Wait a few sec for assets component when entering VR
Bug: 817656 Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel Change-Id: I5faf83e3b1eae38ed977716a1329bfddb3fb271c Reviewed-on: https://chromium-review.googlesource.com/943925 Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org> Reviewed-by: Christopher Grant <cjgrant@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#540313}(cherry picked from commit 444261f) Reviewed-on: https://chromium-review.googlesource.com/953102 Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org> Cr-Commit-Position: refs/branch-heads/3359@{#58} Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
1 parent 8d3126a commit 64bc2a9

File tree

13 files changed

+90
-52
lines changed

13 files changed

+90
-52
lines changed

chrome/browser/android/vr/vr_gl_thread.cc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ void VrGLThread::Init() {
8181
}
8282
}
8383

84-
if (ui_initial_state_.assets_available) {
85-
LoadAssets();
86-
}
87-
8884
vr_shell_gl_ = std::make_unique<VrShellGl>(
8985
this, std::move(ui), gvr_api_, reprojected_rendering_, daydream_support_,
9086
ui_initial_state_.in_web_vr, pause_content_);
@@ -275,8 +271,9 @@ void VrGLThread::StopAutocomplete() {
275271
}
276272

277273
void VrGLThread::LoadAssets() {
278-
AssetsLoader::GetInstance()->Load(
279-
base::BindOnce(&VrGLThread::OnAssetsLoaded, base::Unretained(this)));
274+
DCHECK(OnGlThread());
275+
main_thread_task_runner_->PostTask(
276+
FROM_HERE, base::BindOnce(&VrShell::LoadAssets, weak_vr_shell_));
280277
}
281278

282279
void VrGLThread::SetFullscreen(bool enabled) {
@@ -417,6 +414,23 @@ void VrGLThread::OnAssetsComponentReady() {
417414
weak_browser_ui_));
418415
}
419416

417+
void VrGLThread::OnAssetsLoaded(AssetsLoadStatus status,
418+
std::unique_ptr<Assets> assets,
419+
const base::Version& component_version) {
420+
DCHECK(OnMainThread());
421+
task_runner()->PostTask(
422+
FROM_HERE,
423+
base::BindOnce(&BrowserUiInterface::OnAssetsLoaded, weak_browser_ui_,
424+
status, std::move(assets), component_version));
425+
}
426+
427+
void VrGLThread::OnAssetsUnavailable() {
428+
DCHECK(OnMainThread());
429+
task_runner()->PostTask(
430+
FROM_HERE, base::BindOnce(&BrowserUiInterface::OnAssetsUnavailable,
431+
weak_browser_ui_));
432+
}
433+
420434
void VrGLThread::ShowSoftInput(bool show) {
421435
DCHECK(OnMainThread());
422436
task_runner()->PostTask(FROM_HERE,
@@ -443,13 +457,4 @@ bool VrGLThread::OnGlThread() const {
443457
return task_runner()->BelongsToCurrentThread();
444458
}
445459

446-
void VrGLThread::OnAssetsLoaded(AssetsLoadStatus status,
447-
std::unique_ptr<Assets> assets,
448-
const base::Version& component_version) {
449-
vr_shell_gl_->OnAssetsLoaded(status, std::move(assets), component_version);
450-
main_thread_task_runner_->PostTask(
451-
FROM_HERE, base::BindOnce(&VrShell::OnAssetsLoaded, weak_vr_shell_,
452-
status, component_version));
453-
}
454-
455460
} // namespace vr

chrome/browser/android/vr/vr_gl_thread.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class VrGLThread : public base::android::JavaHandlerThread,
110110
void SetOmniboxSuggestions(
111111
std::unique_ptr<OmniboxSuggestions> result) override;
112112
void OnAssetsComponentReady() override;
113+
void OnAssetsLoaded(AssetsLoadStatus status,
114+
std::unique_ptr<Assets> assets,
115+
const base::Version& component_version) override;
116+
void OnAssetsUnavailable() override;
113117
void ShowSoftInput(bool show) override;
114118
void UpdateWebInputIndices(int selection_start,
115119
int selection_end,
@@ -124,10 +128,6 @@ class VrGLThread : public base::android::JavaHandlerThread,
124128
bool OnMainThread() const;
125129
bool OnGlThread() const;
126130

127-
void OnAssetsLoaded(AssetsLoadStatus status,
128-
std::unique_ptr<Assets> assets,
129-
const base::Version& component_version);
130-
131131
// Created on GL thread.
132132
std::unique_ptr<VrShellGl> vr_shell_gl_;
133133
std::unique_ptr<GvrKeyboardDelegate> keyboard_delegate_;

chrome/browser/android/vr/vr_shell.cc

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
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_ =
8788
constexpr base::TimeDelta kExitVrDueToUnsupportedModeDelay =
8889
base::TimeDelta::FromSeconds(5);
8990

91+
constexpr base::TimeDelta kAssetsComponentWaitDelay =
92+
base::TimeDelta::FromSeconds(2);
93+
9094
static constexpr float kInchesToMeters = 0.0254f;
9195
// Screen pixel density of the Google Pixel phone in pixels per inch.
9296
static 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+
9941013
void 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

10061028
void 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

10101041
void 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,

chrome/browser/android/vr/vr_shell.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ class VrShell : device::GvrGamepadDataProvider,
223223

224224
void OnVoiceResults(const base::string16& result) override;
225225

226+
void LoadAssets();
226227
void OnAssetsLoaded(AssetsLoadStatus status,
228+
std::unique_ptr<Assets> assets,
227229
const base::Version& component_version);
228230

229231
void AcceptDoffPromptForTesting(
@@ -246,6 +248,7 @@ class VrShell : device::GvrGamepadDataProvider,
246248
content::WebContents* GetNonNativePageWebContents() const;
247249

248250
void OnAssetsComponentReady();
251+
void OnAssetsComponentWaitTimeout();
249252

250253
bool vr_shell_enabled_;
251254

@@ -312,6 +315,8 @@ class VrShell : device::GvrGamepadDataProvider,
312315
gl::SurfaceTexture* overlay_surface_texture_ = nullptr;
313316
gl::SurfaceTexture* ui_surface_texture_ = nullptr;
314317

318+
base::Timer waiting_for_assets_component_timer_;
319+
315320
base::WeakPtrFactory<VrShell> weak_ptr_factory_;
316321

317322
DISALLOW_COPY_AND_ASSIGN(VrShell);

chrome/browser/android/vr/vr_shell_gl.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,6 @@ void VrShellGl::OnSwapContents(int new_content_id) {
458458
ui_->OnSwapContents(new_content_id);
459459
}
460460

461-
void VrShellGl::OnAssetsLoaded(AssetsLoadStatus status,
462-
std::unique_ptr<Assets> assets,
463-
const base::Version& component_version) {
464-
ui_->OnAssetsLoaded(status, std::move(assets), component_version);
465-
}
466-
467461
void VrShellGl::EnableAlertDialog(ContentInputForwarder* input_forwarder,
468462
int width,
469463
int height) {

chrome/browser/android/vr/vr_shell_gl.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "chrome/browser/android/vr/android_vsync_helper.h"
1919
#include "chrome/browser/android/vr/vr_controller.h"
2020
#include "chrome/browser/android/vr/vr_dialog.h"
21-
#include "chrome/browser/vr/assets_load_status.h"
2221
#include "chrome/browser/vr/content_input_delegate.h"
2322
#include "chrome/browser/vr/fps_meter.h"
2423
#include "chrome/browser/vr/model/controller_model.h"
@@ -34,10 +33,6 @@
3433
#include "ui/gfx/geometry/size_f.h"
3534
#include "ui/gfx/native_widget_types.h"
3635

37-
namespace base {
38-
class Version;
39-
} // namespace base
40-
4136
namespace gl {
4237
class GLContext;
4338
class GLFenceEGL;
@@ -60,7 +55,6 @@ class SlidingTimeDeltaAverage;
6055
class Ui;
6156
class VrController;
6257
class VrShell;
63-
struct Assets;
6458

6559
struct WebVrBounds {
6660
WebVrBounds(const gfx::RectF& left,
@@ -119,10 +113,6 @@ class VrShellGl : public device::mojom::VRPresentationProvider {
119113

120114
void OnSwapContents(int new_content_id);
121115

122-
void OnAssetsLoaded(AssetsLoadStatus status,
123-
std::unique_ptr<Assets> assets,
124-
const base::Version& component_version);
125-
126116
void EnableAlertDialog(ContentInputForwarder* input_forwarder,
127117
int width,
128118
int height);

chrome/browser/vr/browser_ui_interface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
#ifndef CHROME_BROWSER_VR_BROWSER_UI_INTERFACE_H_
66
#define CHROME_BROWSER_VR_BROWSER_UI_INTERFACE_H_
77

8+
#include "chrome/browser/vr/assets_load_status.h"
89
#include "chrome/browser/vr/ui_unsupported_mode.h"
910
#include "components/security_state/core/security_state.h"
1011

12+
namespace base {
13+
class Version;
14+
} // namespace base
15+
1116
namespace vr {
1217

18+
struct Assets;
1319
struct OmniboxSuggestions;
1420
struct ToolbarState;
1521

@@ -39,6 +45,10 @@ class BrowserUiInterface {
3945
virtual void SetOmniboxSuggestions(
4046
std::unique_ptr<OmniboxSuggestions> suggestions) = 0;
4147
virtual void OnAssetsComponentReady() = 0;
48+
virtual void OnAssetsLoaded(AssetsLoadStatus status,
49+
std::unique_ptr<Assets> assets,
50+
const base::Version& component_version) = 0;
51+
virtual void OnAssetsUnavailable() = 0;
4252

4353
// Web contents text input related.
4454
virtual void ShowSoftInput(bool show) = 0;

chrome/browser/vr/model/model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct Model {
4545
UiElementRenderer::TextureLocation content_overlay_location =
4646
UiElementRenderer::kTextureLocationLocal;
4747
bool update_ready_snackbar_enabled = false;
48-
bool background_available = false;
48+
bool waiting_for_background = true;
4949
bool can_apply_new_background = false;
5050
bool background_loaded = false;
5151
bool supports_selection = true;

chrome/browser/vr/test/mock_browser_ui_interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "base/macros.h"
99
#include "chrome/browser/vr/browser_ui_interface.h"
10+
#include "chrome/browser/vr/model/assets.h"
1011
#include "chrome/browser/vr/model/omnibox_suggestions.h"
1112
#include "chrome/browser/vr/model/toolbar_state.h"
1213
#include "testing/gmock/include/gmock/gmock.h"
@@ -38,6 +39,10 @@ class MockBrowserUiInterface : public BrowserUiInterface {
3839
MOCK_METHOD1(OnSpeechRecognitionStateChanged, void(int new_state));
3940
void SetOmniboxSuggestions(std::unique_ptr<OmniboxSuggestions> suggestions) {}
4041
MOCK_METHOD0(OnAssetsComponentReady, void());
42+
void OnAssetsLoaded(AssetsLoadStatus status,
43+
std::unique_ptr<Assets> assets,
44+
const base::Version& component_version) {}
45+
MOCK_METHOD0(OnAssetsUnavailable, void());
4146

4247
MOCK_METHOD1(ShowSoftInput, void(bool));
4348
MOCK_METHOD4(UpdateWebInputIndices, void(int, int, int, int));

chrome/browser/vr/testapp/vr_test_context.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ VrTestContext::VrTestContext() : view_scale_factor_(kDefaultViewScaleFactor) {
8989
keyboard_delegate_ = std::make_unique<TestKeyboardDelegate>();
9090

9191
UiInitialState ui_initial_state;
92-
ui_initial_state.assets_available = true;
9392
ui_ = std::make_unique<Ui>(this, nullptr, keyboard_delegate_.get(),
9493
text_input_delegate_.get(), ui_initial_state);
95-
if (ui_initial_state.assets_available) {
96-
LoadAssets();
97-
}
94+
LoadAssets();
9895

9996
text_input_delegate_->SetRequestFocusCallback(
10097
base::BindRepeating(&vr::Ui::RequestFocus, base::Unretained(ui_.get())));

0 commit comments

Comments
 (0)