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

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: Rebased on ToT, changed logging to UMA_HISTOGRAM_SPARSE_SLOWLY 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_usage_monitor.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;
21
22 static constexpr int kVrOutOfDate = 2;
ddorwin 2017/05/16 00:15:51 Is this a constant defined in Java? If so, we shou
tiborg 2017/05/23 15:47:24 It's gone in favor of the native VrCoreCompatibili
19 23
20 namespace vr_shell { 24 namespace vr_shell {
21 25
22 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) 26 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
23 : weak_ptr_factory_(this) { 27 : weak_ptr_factory_(this) {
24 DVLOG(1) << __FUNCTION__ << "=" << this; 28 DVLOG(1) << __FUNCTION__ << "=" << this;
25 j_vr_shell_delegate_.Reset(env, obj); 29 j_vr_shell_delegate_.Reset(env, obj);
26 } 30 }
27 31
28 VrShellDelegate::~VrShellDelegate() { 32 VrShellDelegate::~VrShellDelegate() {
29 DVLOG(1) << __FUNCTION__ << "=" << this; 33 DVLOG(1) << __FUNCTION__ << "=" << this;
30 if (device_provider_) { 34 if (device_provider_) {
31 device_provider_->Device()->OnExitPresent(); 35 device_provider_->Device()->OnExitPresent();
32 device_provider_->Device()->OnDelegateChanged(); 36 device_provider_->Device()->OnDelegateChanged();
33 } 37 }
34 if (!present_callback_.is_null()) { 38 if (!present_callback_.is_null()) {
35 base::ResetAndReturn(&present_callback_).Run(false); 39 base::ResetAndReturn(&present_callback_).Run(false);
36 } 40 }
37 } 41 }
38 42
39 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { 43 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() {
40 JNIEnv* env = AttachCurrentThread(); 44 JNIEnv* env = AttachCurrentThread();
41 base::android::ScopedJavaLocalRef<jobject> jdelegate = 45 ScopedJavaLocalRef<jobject> jdelegate = Java_VrShellDelegate_getInstance(env);
42 Java_VrShellDelegate_getInstance(env);
43 if (!jdelegate.is_null()) 46 if (!jdelegate.is_null())
44 return GetNativeVrShellDelegate(env, jdelegate.obj()); 47 return GetNativeVrShellDelegate(env, jdelegate.obj());
45 return nullptr; 48 return nullptr;
46 } 49 }
47 50
48 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env, 51 VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env,
49 jobject jdelegate) { 52 jobject jdelegate) {
50 return reinterpret_cast<VrShellDelegate*>( 53 return reinterpret_cast<VrShellDelegate*>(
51 Java_VrShellDelegate_getNativePointer(env, jdelegate)); 54 Java_VrShellDelegate_getNativePointer(env, jdelegate));
52 } 55 }
53 56
54 void VrShellDelegate::SetPresentingDelegate( 57 void VrShellDelegate::SetPresentingDelegate(
55 device::PresentingGvrDelegate* delegate, 58 device::PresentingGvrDelegate* delegate,
56 gvr_context* context) { 59 gvr_context* context) {
57 presenting_delegate_ = delegate; 60 presenting_delegate_ = delegate;
58 // Clean up the non-presenting delegate. 61 // Clean up the non-presenting delegate.
62 JNIEnv* env = AttachCurrentThread();
59 if (presenting_delegate_ && non_presenting_delegate_) { 63 if (presenting_delegate_ && non_presenting_delegate_) {
60 non_presenting_delegate_ = nullptr; 64 non_presenting_delegate_ = nullptr;
61 JNIEnv* env = AttachCurrentThread();
62 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 65 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
63 env, j_vr_shell_delegate_.obj()); 66 env, j_vr_shell_delegate_.obj());
64 } 67 }
65 if (device_provider_) { 68 if (device_provider_) {
66 device::GvrDevice* device = device_provider_->Device(); 69 device::GvrDevice* device = device_provider_->Device();
67 device->OnDelegateChanged(); 70 device->OnDelegateChanged();
68 } 71 }
69 72
70 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); 73 presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_);
71 74
72 if (pending_successful_present_request_) { 75 if (pending_successful_present_request_) {
73 presenting_delegate_->SetSubmitClient(std::move(submit_client_)); 76 presenting_delegate_->SetSubmitClient(std::move(submit_client_));
74 base::ResetAndReturn(&present_callback_).Run(true); 77 base::ResetAndReturn(&present_callback_).Run(true);
75 pending_successful_present_request_ = false; 78 pending_successful_present_request_ = false;
76 } 79 }
80
81 auto gvr_version = GetGvrVersion(env);
82 VrMetricsUtil::LogGvrVersionForVrViewerType(context, gvr_version.first,
83 gvr_version.second);
77 } 84 }
78 85
79 void VrShellDelegate::RemoveDelegate() { 86 void VrShellDelegate::RemoveDelegate() {
80 presenting_delegate_ = nullptr; 87 presenting_delegate_ = nullptr;
81 if (device_provider_) { 88 if (device_provider_) {
82 CreateNonPresentingDelegate(); 89 CreateNonPresentingDelegate();
83 device_provider_->Device()->OnExitPresent(); 90 device_provider_->Device()->OnExitPresent();
84 device_provider_->Device()->OnDelegateChanged(); 91 device_provider_->Device()->OnDelegateChanged();
85 } 92 }
86 } 93 }
(...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 197 // VRShell is no longer needed by WebVR, allow it to shut down if it's not
191 // being used elsewhere. 198 // being used elsewhere.
192 JNIEnv* env = AttachCurrentThread(); 199 JNIEnv* env = AttachCurrentThread();
193 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) { 200 if (Java_VrShellDelegate_exitWebVRPresent(env, j_vr_shell_delegate_.obj())) {
194 if (device_provider_) { 201 if (device_provider_) {
195 device_provider_->Device()->OnExitPresent(); 202 device_provider_->Device()->OnExitPresent();
196 } 203 }
197 } 204 }
198 } 205 }
199 206
207 std::pair<GvrVersionStatus, gvr_version> VrShellDelegate::GetGvrVersion(
208 JNIEnv* env) {
209 ScopedJavaLocalRef<jobject> j_vr_core_info =
210 Java_VrShellDelegate_getVrCoreInfo(env, j_vr_shell_delegate_.obj());
211 jclass j_vr_core_info_class = env->GetObjectClass(j_vr_core_info.obj());
212 jfieldID j_field_id = env->GetFieldID(j_vr_core_info_class, "version",
213 "Lcom/google/vr/ndk/base/Version;");
214 jobject j_version_object =
215 env->GetObjectField(j_vr_core_info.obj(), j_field_id);
216 gvr_version version;
217 if (j_version_object) {
218 j_vr_core_info_class = env->GetObjectClass(j_version_object);
219 j_field_id = env->GetFieldID(j_vr_core_info_class, "majorVersion", "I");
mthiesse 2017/05/16 01:15:12 The canonical way of doing what you're doing here
tiborg 2017/05/23 15:47:24 That tip is golden. Made it much better!
220 version.major = env->GetIntField(j_version_object, j_field_id);
221 j_field_id = env->GetFieldID(j_vr_core_info_class, "minorVersion", "I");
222 version.minor = env->GetIntField(j_version_object, j_field_id);
223 j_field_id = env->GetFieldID(j_vr_core_info_class, "patchVersion", "I");
224 version.patch = env->GetIntField(j_version_object, j_field_id);
225 return std::make_pair(GvrVersionStatus::PRECISE, version);
226 } else {
227 j_field_id = env->GetFieldID(j_vr_core_info_class, "compatibility", "I");
228 jint compatibility = env->GetIntField(j_vr_core_info.obj(), j_field_id);
229
230 if (compatibility == kVrOutOfDate) {
231 return std::make_pair(GvrVersionStatus::OLDER, version);
232 } else {
233 return std::make_pair(GvrVersionStatus::UNKNOWN, version);
ddorwin 2017/05/16 00:15:51 It seems that VR_NOT_AVAILABLE would be important
tiborg 2017/05/23 15:47:25 Done. All of them are handled.
234 }
235 }
236 }
237
200 void VrShellDelegate::CreateNonPresentingDelegate() { 238 void VrShellDelegate::CreateNonPresentingDelegate() {
201 JNIEnv* env = AttachCurrentThread(); 239 JNIEnv* env = AttachCurrentThread();
202 gvr_context* context = reinterpret_cast<gvr_context*>( 240 gvr_context* context = reinterpret_cast<gvr_context*>(
203 Java_VrShellDelegate_createNonPresentingNativeContext( 241 Java_VrShellDelegate_createNonPresentingNativeContext(
204 env, j_vr_shell_delegate_.obj())); 242 env, j_vr_shell_delegate_.obj()));
205 non_presenting_delegate_ = 243 non_presenting_delegate_ =
206 base::MakeUnique<NonPresentingGvrDelegate>(context); 244 base::MakeUnique<NonPresentingGvrDelegate>(context);
207 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_, 245 non_presenting_delegate_->UpdateVSyncInterval(timebase_nanos_,
208 interval_seconds_); 246 interval_seconds_);
247 auto gvr_version = GetGvrVersion(env);
248 VrMetricsUtil::LogGvrVersionForVrViewerType(context, gvr_version.first,
249 gvr_version.second);
209 } 250 }
210 251
211 void VrShellDelegate::OnActivateDisplayHandled(bool present_requested) { 252 void VrShellDelegate::OnActivateDisplayHandled(bool present_requested) {
212 if (!present_requested) { 253 if (!present_requested) {
213 // WebVR page didn't request presentation in the vrdisplayactivate handler. 254 // WebVR page didn't request presentation in the vrdisplayactivate handler.
214 // Tell VrShell that we are in VR Browsing Mode. 255 // Tell VrShell that we are in VR Browsing Mode.
215 ExitWebVRPresent(); 256 ExitWebVRPresent();
216 } 257 }
217 } 258 }
218 259
(...skipping 20 matching lines...) Expand all
239 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 280 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
240 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 281 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
241 } 282 }
242 283
243 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 284 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
244 device::GvrDelegateProvider::SetInstance( 285 device::GvrDelegateProvider::SetInstance(
245 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 286 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
246 } 287 }
247 288
248 } // namespace vr_shell 289 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698