Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2865463003: Tracks GVR version crossed with headset type using UMA. (Closed)
Patch Set: Nit: only create native-Java enum if enable_vr is set Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" 11 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h"
12 #include "chrome/browser/android/vr_shell/vr_metrics_util.h"
12 #include "device/vr/android/gvr/gvr_delegate.h" 13 #include "device/vr/android/gvr/gvr_delegate.h"
13 #include "device/vr/android/gvr/gvr_device.h" 14 #include "device/vr/android/gvr/gvr_device.h"
14 #include "device/vr/android/gvr/gvr_device_provider.h" 15 #include "device/vr/android/gvr/gvr_device_provider.h"
15 #include "jni/VrShellDelegate_jni.h" 16 #include "jni/VrShellDelegate_jni.h"
16 17
17 using base::android::JavaParamRef; 18 using base::android::JavaParamRef;
18 using base::android::AttachCurrentThread; 19 using base::android::AttachCurrentThread;
20 using base::android::ScopedJavaLocalRef;
19 21
20 namespace vr_shell { 22 namespace vr_shell {
21 23
22 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) 24 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
23 : weak_ptr_factory_(this) { 25 : weak_ptr_factory_(this) {
24 DVLOG(1) << __FUNCTION__ << "=" << this; 26 DVLOG(1) << __FUNCTION__ << "=" << this;
25 j_vr_shell_delegate_.Reset(env, obj); 27 j_vr_shell_delegate_.Reset(env, obj);
26 } 28 }
27 29
28 VrShellDelegate::~VrShellDelegate() { 30 VrShellDelegate::~VrShellDelegate() {
29 DVLOG(1) << __FUNCTION__ << "=" << this; 31 DVLOG(1) << __FUNCTION__ << "=" << this;
30 if (device_provider_) { 32 if (device_provider_) {
31 device_provider_->Device()->OnExitPresent(); 33 device_provider_->Device()->OnExitPresent();
32 device_provider_->Device()->OnDelegateChanged(); 34 device_provider_->Device()->OnDelegateChanged();
33 } 35 }
34 if (!present_callback_.is_null()) { 36 if (!present_callback_.is_null()) {
35 base::ResetAndReturn(&present_callback_).Run(false); 37 base::ResetAndReturn(&present_callback_).Run(false);
36 } 38 }
37 } 39 }
38 40
39 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { 41 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() {
40 JNIEnv* env = AttachCurrentThread(); 42 JNIEnv* env = AttachCurrentThread();
41 base::android::ScopedJavaLocalRef<jobject> jdelegate = 43 ScopedJavaLocalRef<jobject> jdelegate = Java_VrShellDelegate_getInstance(env);
42 Java_VrShellDelegate_getInstance(env);
43 if (!jdelegate.is_null()) 44 if (!jdelegate.is_null())
44 return GetNativeVrShellDelegate(env, jdelegate.obj()); 45 return GetNativeVrShellDelegate(env, jdelegate.obj());
45 return nullptr; 46 return nullptr;
46 } 47 }
47 48
48 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, 49 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env,
49 jobject jdelegate) { 50 jobject jdelegate) {
50 return reinterpret_cast<VrShellDelegate*>( 51 return reinterpret_cast<VrShellDelegate*>(
51 Java_VrShellDelegate_getNativePointer(env, jdelegate)); 52 Java_VrShellDelegate_getNativePointer(env, jdelegate));
52 } 53 }
53 54
54 void VrShellDelegate::SetPresentingDelegate( 55 void VrShellDelegate::SetPresentingDelegate(
55 device::PresentingGvrDelegate* delegate, 56 device::PresentingGvrDelegate* delegate,
56 gvr_context* context) { 57 gvr_context* context) {
57 presenting_delegate_ = delegate; 58 presenting_delegate_ = delegate;
58 // Clean up the non-presenting delegate. 59 // Clean up the non-presenting delegate.
60 JNIEnv* env = AttachCurrentThread();
59 if (presenting_delegate_ && non_presenting_delegate_) { 61 if (presenting_delegate_ && non_presenting_delegate_) {
60 non_presenting_delegate_ = nullptr; 62 non_presenting_delegate_ = nullptr;
61 JNIEnv* env = AttachCurrentThread();
62 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 63 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
63 env, j_vr_shell_delegate_.obj()); 64 env, j_vr_shell_delegate_.obj());
64 } 65 }
65 if (device_provider_) { 66 if (device_provider_) {
66 device::GvrDevice* device = device_provider_->Device(); 67 device::GvrDevice* device = device_provider_->Device();
67 device->OnDelegateChanged(); 68 device->OnDelegateChanged();
68 } 69 }
69 70
70 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); 71 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_);
71 72
72 if (pending_successful_present_request_) { 73 if (pending_successful_present_request_) {
73 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); 74 presenting_delegate_->SetSubmitClient(std::move(submit_client_));
74 base::ResetAndReturn(&present_callback_).Run(true); 75 base::ResetAndReturn(&present_callback_).Run(true);
75 pending_successful_present_request_ = false; 76 pending_successful_present_request_ = false;
76 } 77 }
78
79 auto vr_core_info = MakeVrCoreInfo(env);
mthiesse 2017/05/24 05:47:26 nit: Only use auto when the type is apparent. I do
tiborg 2017/05/25 00:06:03 Done.
80 VrMetricsUtil::LogGvrVersionForVrViewerType(context, *vr_core_info);
77 } 81 }
78 82
79 void VrShellDelegate::RemoveDelegate() { 83 void VrShellDelegate::RemoveDelegate() {
80 presenting_delegate_ = nullptr; 84 presenting_delegate_ = nullptr;
81 if (device_provider_) { 85 if (device_provider_) {
82 CreateNonPresentingDelegate(); 86 CreateNonPresentingDelegate();
83 device_provider_->Device()->OnExitPresent(); 87 device_provider_->Device()->OnExitPresent();
84 device_provider_->Device()->OnDelegateChanged(); 88 device_provider_->Device()->OnDelegateChanged();
85 } 89 }
86 } 90 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // VRShell is no longer needed by WebVR, allow it to shut down if it's not 194 // VRShell is no longer needed by WebVR, allow it to shut down if it's not
191 // being used elsewhere. 195 // being used elsewhere.
192 JNIEnv* env = AttachCurrentThread(); 196 JNIEnv* env = AttachCurrentThread();
193 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) { 197 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) {
194 if (device_provider_) { 198 if (device_provider_) {
195 device_provider_->Device()->OnExitPresent(); 199 device_provider_->Device()->OnExitPresent();
196 } 200 }
197 } 201 }
198 } 202 }
199 203
204 jlong VrShellDelegate::MakeNativeVrCoreInfo(JNIEnv* env,
mthiesse 2017/05/24 05:47:26 I think you should move this function into (a new)
tiborg 2017/05/25 00:06:03 Done.
205 const JavaParamRef<jobject>& obj,
206 jint major_version,
207 jint minor_version,
208 jint patch_version,
209 jint compatibility) {
210 return reinterpret_cast<intptr_t>(
211 new VrCoreInfo(major_version, minor_version, patch_version,
212 static_cast<VrCoreCompatibility>(compatibility)));
213 }
214
215 std::unique_ptr<VrCoreInfo> VrShellDelegate::MakeVrCoreInfo(JNIEnv* env) {
216 std::unique_ptr<VrCoreInfo> vr_core_info =
217 std::unique_ptr<VrCoreInfo>(reinterpret_cast<VrCoreInfo*>(
mthiesse 2017/05/24 05:47:26 This is pretty confusing. I think you probably wan
tiborg 2017/05/25 00:06:03 Done.
218 Java_VrShellDelegate_getVrCoreInfo(env, j_vr_shell_delegate_.obj())));
219 return vr_core_info;
220 }
221
200 void VrShellDelegate::CreateNonPresentingDelegate() { 222 void VrShellDelegate::CreateNonPresentingDelegate() {
201 JNIEnv* env = AttachCurrentThread(); 223 JNIEnv* env = AttachCurrentThread();
202 gvr_context* context = reinterpret_cast<gvr_context*>( 224 gvr_context* context = reinterpret_cast<gvr_context*>(
203 Java_VrShellDelegate_createNonPresentingNativeContext( 225 Java_VrShellDelegate_createNonPresentingNativeContext(
204 env, j_vr_shell_delegate_.obj())); 226 env, j_vr_shell_delegate_.obj()));
205 non_presenting_delegate_ = 227 non_presenting_delegate_ =
206 base::MakeUnique<NonPresentingGvrDelegate>(context); 228 base::MakeUnique<NonPresentingGvrDelegate>(context);
207 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, 229 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_,
208 interval_seconds_); 230 interval_seconds_);
231 auto vr_core_info = MakeVrCoreInfo(env);
232 VrMetricsUtil::LogGvrVersionForVrViewerType(context, *vr_core_info);
209 } 233 }
210 234
211 void VrShellDelegate::OnActivateDisplayHandled(bool present_requested) { 235 void VrShellDelegate::OnActivateDisplayHandled(bool present_requested) {
212 if (!present_requested) { 236 if (!present_requested) {
213 // WebVR page didn't request presentation in the vrdisplayactivate handler. 237 // WebVR page didn't request presentation in the vrdisplayactivate handler.
214 // Tell VrShell that we are in VR Browsing Mode. 238 // Tell VrShell that we are in VR Browsing Mode.
215 ExitWebVRPresent(); 239 ExitWebVRPresent();
216 } 240 }
217 } 241 }
218 242
(...skipping 20 matching lines...) Expand all
239 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 263 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
240 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 264 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
241 } 265 }
242 266
243 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 267 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
244 device::GvrDelegateProvider::SetInstance( 268 device::GvrDelegateProvider::SetInstance(
245 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 269 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
246 } 270 }
247 271
248 } // namespace vr_shell 272 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698