Commit de212233 authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Make ScreenOrientationProvider (Java) a bag of static methods.

BUG=162827

Review URL: https://codereview.chromium.org/410173002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285004 0039d316-1c4b-4281-b951-d872f2087c98
parent fd75b1df
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
#define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
#include "base/macros.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
namespace content { namespace content {
......
...@@ -69,15 +69,9 @@ void ScreenOrientationProviderAndroid::LockOrientation( ...@@ -69,15 +69,9 @@ void ScreenOrientationProviderAndroid::LockOrientation(
} }
} }
if (j_screen_orientation_provider_.is_null()) {
j_screen_orientation_provider_.Reset(Java_ScreenOrientationProvider_create(
base::android::AttachCurrentThread()));
}
lock_applied_ = true; lock_applied_ = true;
Java_ScreenOrientationProvider_lockOrientation( Java_ScreenOrientationProvider_lockOrientation(
base::android::AttachCurrentThread(), base::android::AttachCurrentThread(), lock_orientation);
j_screen_orientation_provider_.obj(), lock_orientation);
// If two calls happen close to each other, Android will ignore the first. // If two calls happen close to each other, Android will ignore the first.
if (pending_lock_) { if (pending_lock_) {
...@@ -99,12 +93,8 @@ void ScreenOrientationProviderAndroid::UnlockOrientation() { ...@@ -99,12 +93,8 @@ void ScreenOrientationProviderAndroid::UnlockOrientation() {
if (!lock_applied_) if (!lock_applied_)
return; return;
// j_screen_orientation_provider_ was set when locking so it can't be null.
DCHECK(!j_screen_orientation_provider_.is_null());
Java_ScreenOrientationProvider_unlockOrientation( Java_ScreenOrientationProvider_unlockOrientation(
base::android::AttachCurrentThread(), base::android::AttachCurrentThread());
j_screen_orientation_provider_.obj());
lock_applied_ = false; lock_applied_ = false;
} }
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
#ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_ #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_
#define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_ #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_
#include "base/android/jni_android.h" #include <jni.h>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "content/browser/screen_orientation/screen_orientation_provider.h" #include "content/browser/screen_orientation/screen_orientation_provider.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -46,8 +47,6 @@ class ScreenOrientationProviderAndroid : public ScreenOrientationProvider, ...@@ -46,8 +47,6 @@ class ScreenOrientationProviderAndroid : public ScreenOrientationProvider,
virtual ~ScreenOrientationProviderAndroid(); virtual ~ScreenOrientationProviderAndroid();
base::android::ScopedJavaGlobalRef<jobject> j_screen_orientation_provider_;
// ScreenOrientationDispatcherHost owns ScreenOrientationProvider so // ScreenOrientationDispatcherHost owns ScreenOrientationProvider so
// dispatcher_ should not point to an invalid memory. // dispatcher_ should not point to an invalid memory.
ScreenOrientationDispatcherHost* dispatcher_; ScreenOrientationDispatcherHost* dispatcher_;
......
...@@ -9,8 +9,6 @@ import android.content.pm.ActivityInfo; ...@@ -9,8 +9,6 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.util.Log; import android.util.Log;
import com.google.common.annotations.VisibleForTesting;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.CalledByNative; import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace; import org.chromium.base.JNINamespace;
...@@ -23,7 +21,7 @@ import org.chromium.content.common.ScreenOrientationValues; ...@@ -23,7 +21,7 @@ import org.chromium.content.common.ScreenOrientationValues;
class ScreenOrientationProvider { class ScreenOrientationProvider {
private static final String TAG = "ScreenOrientationProvider"; private static final String TAG = "ScreenOrientationProvider";
private int getOrientationFromWebScreenOrientations(byte orientations) { private static int getOrientationFromWebScreenOrientations(byte orientations) {
switch (orientations) { switch (orientations) {
case ScreenOrientationValues.DEFAULT: case ScreenOrientationValues.DEFAULT:
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
...@@ -47,14 +45,8 @@ class ScreenOrientationProvider { ...@@ -47,14 +45,8 @@ class ScreenOrientationProvider {
} }
} }
@VisibleForTesting
@CalledByNative
static ScreenOrientationProvider create() {
return new ScreenOrientationProvider();
}
@CalledByNative @CalledByNative
void lockOrientation(byte orientations) { static void lockOrientation(byte orientations) {
Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
if (activity == null) { if (activity == null) {
return; return;
...@@ -69,7 +61,7 @@ class ScreenOrientationProvider { ...@@ -69,7 +61,7 @@ class ScreenOrientationProvider {
} }
@CalledByNative @CalledByNative
void unlockOrientation() { static void unlockOrientation() {
Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
if (activity == null) { if (activity == null) {
return; return;
......
...@@ -29,7 +29,6 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase { ...@@ -29,7 +29,6 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase {
UrlUtils.encodeHtmlDataUri("<html><body>foo</body></html>"); UrlUtils.encodeHtmlDataUri("<html><body>foo</body></html>");
private MockOrientationObserver mObserver; private MockOrientationObserver mObserver;
private final ScreenOrientationProvider mProvider = ScreenOrientationProvider.create();
private boolean checkOrientationForLock(int orientations) { private boolean checkOrientationForLock(int orientations) {
switch (orientations) { switch (orientations) {
...@@ -58,7 +57,7 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase { ...@@ -58,7 +57,7 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase {
* Locks the screen orientation to |orientations| using ScreenOrientationProvider. * Locks the screen orientation to |orientations| using ScreenOrientationProvider.
*/ */
private void lockOrientation(int orientations) { private void lockOrientation(int orientations) {
mProvider.lockOrientation((byte)orientations); ScreenOrientationProvider.lockOrientation((byte)orientations);
} }
/** /**
...@@ -78,7 +77,7 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase { ...@@ -78,7 +77,7 @@ public class ScreenOrientationProviderTest extends ContentShellTestBase {
* Unlock the screen orientation using |ScreenOrientationProvider|. * Unlock the screen orientation using |ScreenOrientationProvider|.
*/ */
private void unlockOrientation() { private void unlockOrientation() {
mProvider.unlockOrientation(); ScreenOrientationProvider.unlockOrientation();
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment