| OLD | NEW |
| 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.chrome.browser.vr_shell; | 5 package org.chromium.chrome.browser.vr_shell; |
| 6 | 6 |
| 7 import android.app.Activity; |
| 7 import android.content.Context; | 8 import android.content.Context; |
| 8 import android.os.StrictMode; | 9 import android.os.StrictMode; |
| 9 | 10 |
| 10 import com.google.vr.ndk.base.AndroidCompat; | 11 import com.google.vr.ndk.base.AndroidCompat; |
| 11 | 12 |
| 12 import org.chromium.base.Log; | 13 import org.chromium.base.Log; |
| 13 import org.chromium.base.VisibleForTesting; | |
| 14 import org.chromium.base.annotations.UsedByReflection; | 14 import org.chromium.base.annotations.UsedByReflection; |
| 15 import org.chromium.chrome.browser.ChromeActivity; | 15 import org.chromium.chrome.browser.ChromeActivity; |
| 16 import org.chromium.chrome.browser.compositor.CompositorViewHolder; | 16 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Builder class to create all VR related classes. These VR classes are behind t
he same build time | 19 * Builder class to create all VR related classes. These VR classes are behind t
he same build time |
| 20 * flag as this class. So no reflection is necessary when create them. | 20 * flag as this class. So no reflection is necessary when create them. |
| 21 */ | 21 */ |
| 22 @UsedByReflection("VrShellDelegate.java") | 22 @UsedByReflection("VrShellDelegate.java") |
| 23 public class VrClassesWrapperImpl implements VrClassesWrapper { | 23 public class VrClassesWrapperImpl implements VrClassesWrapper { |
| 24 private static final String TAG = "VrClassesWrapperImpl"; | 24 private static final String TAG = "VrClassesWrapperImpl"; |
| 25 private final Context mContext; | |
| 26 | 25 |
| 27 @UsedByReflection("VrShellDelegate.java") | 26 @UsedByReflection("VrShellDelegate.java") |
| 28 public VrClassesWrapperImpl(ChromeActivity activity) { | 27 public VrClassesWrapperImpl() {} |
| 29 mContext = activity; | |
| 30 } | |
| 31 | |
| 32 @UsedByReflection("ChromeInstrumentationTestRunner.java") | |
| 33 @VisibleForTesting | |
| 34 public VrClassesWrapperImpl(Context context) { | |
| 35 mContext = context; | |
| 36 } | |
| 37 | 28 |
| 38 @Override | 29 @Override |
| 39 public NonPresentingGvrContext createNonPresentingGvrContext() { | 30 public NonPresentingGvrContext createNonPresentingGvrContext(ChromeActivity
activity) { |
| 40 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 31 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 41 try { | 32 try { |
| 42 return new NonPresentingGvrContextImpl((ChromeActivity) mContext); | 33 return new NonPresentingGvrContextImpl(activity); |
| 43 } catch (Exception ex) { | 34 } catch (Exception ex) { |
| 44 Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex); | 35 Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex); |
| 45 return null; | 36 return null; |
| 46 } finally { | 37 } finally { |
| 47 StrictMode.setThreadPolicy(oldPolicy); | 38 StrictMode.setThreadPolicy(oldPolicy); |
| 48 } | 39 } |
| 49 } | 40 } |
| 50 | 41 |
| 51 @Override | 42 @Override |
| 52 public VrShell createVrShell(VrShellDelegate delegate, | 43 public VrShell createVrShell( |
| 53 CompositorViewHolder compositorViewHolder) { | 44 ChromeActivity activity, VrShellDelegate delegate, TabModelSelector
tabModelSelector) { |
| 54 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 45 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 55 try { | 46 try { |
| 56 return new VrShellImpl((ChromeActivity) mContext, delegate, composit
orViewHolder); | 47 return new VrShellImpl(activity, delegate, tabModelSelector); |
| 57 } catch (Exception ex) { | 48 } catch (Exception ex) { |
| 58 Log.e(TAG, "Unable to instantiate VrShellImpl", ex); | 49 Log.e(TAG, "Unable to instantiate VrShellImpl", ex); |
| 59 return null; | 50 return null; |
| 60 } finally { | 51 } finally { |
| 61 StrictMode.setThreadPolicy(oldPolicy); | 52 StrictMode.setThreadPolicy(oldPolicy); |
| 62 } | 53 } |
| 63 } | 54 } |
| 64 | 55 |
| 65 @Override | 56 @Override |
| 66 public VrDaydreamApi createVrDaydreamApi() { | 57 public VrDaydreamApi createVrDaydreamApi(Activity activity) { |
| 67 return new VrDaydreamApiImpl(mContext); | 58 return new VrDaydreamApiImpl(activity); |
| 68 } | 59 } |
| 69 | 60 |
| 70 @Override | 61 @Override |
| 62 public VrDaydreamApi createVrDaydreamApi(Context context) { |
| 63 return new VrDaydreamApiImpl(context); |
| 64 } |
| 65 |
| 66 @Override |
| 71 public VrCoreVersionChecker createVrCoreVersionChecker() { | 67 public VrCoreVersionChecker createVrCoreVersionChecker() { |
| 72 return new VrCoreVersionCheckerImpl(); | 68 return new VrCoreVersionCheckerImpl(); |
| 73 } | 69 } |
| 74 | 70 |
| 75 @Override | 71 @Override |
| 76 public void setVrModeEnabled(boolean enabled) { | 72 public void setVrModeEnabled(Activity activity, boolean enabled) { |
| 77 AndroidCompat.setVrModeEnabled((ChromeActivity) mContext, enabled); | 73 AndroidCompat.setVrModeEnabled(activity, enabled); |
| 78 } | 74 } |
| 79 } | 75 } |
| OLD | NEW |