Chromium Code Reviews| Index: device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java |
| diff --git a/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java b/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java |
| index c29dfe32eb80650bf604b936c3918272af42eb35..43dead5d00f7ed98d23fd28f2207052df895c0e2 100644 |
| --- a/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java |
| +++ b/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java |
| @@ -9,12 +9,9 @@ import android.view.View; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.annotations.JNINamespace; |
| -import java.lang.ref.WeakReference; |
| - |
| @JNINamespace("device") |
| class PowerSaveBlocker { |
| - // WeakReference to prevent leaks in Android WebView. |
| - private WeakReference<View> mKeepScreenOnView; |
| + private View mKeepScreenOnView; |
|
boliu
2017/01/18 18:21:16
the weakreference here is not because native side
Jinsuk Kim
2017/01/19 23:48:08
Done.
|
| @CalledByNative |
| private static PowerSaveBlocker create() { |
| @@ -24,21 +21,16 @@ class PowerSaveBlocker { |
| private PowerSaveBlocker() {} |
| @CalledByNative |
| - private void applyBlock(View anchorView) { |
| + private void applyBlock(View view) { |
| assert mKeepScreenOnView == null; |
| - mKeepScreenOnView = new WeakReference<>(anchorView); |
| - anchorView.setKeepScreenOn(true); |
| + mKeepScreenOnView = view; |
| + view.setKeepScreenOn(true); |
| } |
| @CalledByNative |
| private void removeBlock() { |
| - // mKeepScreenOnView may be null since it's possible that |applyBlock()| |
| - // was not invoked due to having failed to acquire an anchor view. |
| - if (mKeepScreenOnView == null) return; |
| - View anchorView = mKeepScreenOnView.get(); |
| - mKeepScreenOnView = null; |
| - if (anchorView == null) return; |
| - |
| - anchorView.setKeepScreenOn(false); |
| + // mKeepScreenOnView may be null since it's possible that |applyBlock()| was |
| + // not invoked due to having failed to get a view to call |setKeepScrenOn| on. |
| + if (mKeepScreenOnView != null) mKeepScreenOnView.setKeepScreenOn(false); |
| } |
| } |