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

Side by Side Diff: device/vr/android/java/src/org/chromium/device/vr/GvrDeviceProvider.java

Issue 2343023002: Switch WebVR to handle GvrApi management through VrShellDelegate (Closed)
Patch Set: Renamed onNativeLibraryReady to initializeNative Created 4 years, 3 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
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.cc ('k') | device/vr/vr_client_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 package org.chromium.device.vr; 5 package org.chromium.device.vr;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.StrictMode;
8 9
9 import com.google.vr.ndk.base.GvrLayout; 10 import com.google.vr.ndk.base.GvrLayout;
10 11
12 import org.chromium.base.Log;
11 import org.chromium.base.annotations.CalledByNative; 13 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.JNINamespace; 14 import org.chromium.base.annotations.JNINamespace;
13 15
14 /** 16 /**
15 * This is the implementation of the C++ counterpart GvrDeviceProvider. 17 * This is the implementation of the C++ counterpart GvrDeviceProvider.
16 */ 18 */
17 @JNINamespace("device") 19 @JNINamespace("device")
18 class GvrDeviceProvider { 20 class GvrDeviceProvider {
19 private static final String TAG = "GvrDeviceProvider"; 21 private static final String TAG = "GvrDeviceProvider";
20 private final GvrLayout mLayout; 22 private final GvrLayout mLayout;
21 private Thread mGvrInitThread;
22 23
23 private GvrDeviceProvider(Context context) { 24 private GvrDeviceProvider(Context context) {
24 mLayout = new GvrLayout(context); 25 mLayout = new GvrLayout(context);
25
26 // Initialize the GVR API on a separate thread to avoid strict mode
27 // violations. Note that this doesn't fix the underlying issue of
28 // blocking on disk reads here.
29 mGvrInitThread = new Thread(new Runnable() {
30 @Override
31 public void run() {
32 mLayout.getGvrApi();
33 }
34 });
35 mGvrInitThread.start();
36 } 26 }
37 27
38 @CalledByNative 28 @CalledByNative
39 private static GvrDeviceProvider create(Context context) { 29 private static GvrDeviceProvider create(Context context) {
40 return new GvrDeviceProvider(context); 30 return new GvrDeviceProvider(context);
41 } 31 }
42 32
43 @CalledByNative 33 @CalledByNative
44 private long getNativeContext() { 34 private long getNativeContext() {
35 long nativeGvrContext = 0;
36
37 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
38
45 try { 39 try {
46 mGvrInitThread.join(); 40 nativeGvrContext = mLayout.getGvrApi().getNativeGvrContext();
47 } catch (Exception ex) { 41 } catch (Exception ex) {
42 Log.e(TAG, "Unable to instantiate GvrApi", ex);
43 return 0;
44 } finally {
45 StrictMode.setThreadPolicy(oldPolicy);
48 } 46 }
49 return mLayout.getGvrApi().getNativeGvrContext(); 47
48 return nativeGvrContext;
50 } 49 }
51 50
52 @CalledByNative 51 @CalledByNative
53 private void shutdown() { 52 private void shutdown() {
54 mLayout.shutdown(); 53 mLayout.shutdown();
55 } 54 }
56 } 55 }
OLDNEW
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.cc ('k') | device/vr/vr_client_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698