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

Unified Diff: blimp/client/core/settings/android/java/src/org/chromium/blimp/core/settings/Settings.java

Issue 2463423002: Add Settings[, Oberser] java code and JNI bridge. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: blimp/client/core/settings/android/java/src/org/chromium/blimp/core/settings/Settings.java
diff --git a/blimp/client/core/settings/android/java/src/org/chromium/blimp/core/settings/Settings.java b/blimp/client/core/settings/android/java/src/org/chromium/blimp/core/settings/Settings.java
new file mode 100644
index 0000000000000000000000000000000000000000..6128ea0d30a0034e29541ba7aeeefa4c3e99ecff
--- /dev/null
+++ b/blimp/client/core/settings/android/java/src/org/chromium/blimp/core/settings/Settings.java
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.blimp.core.settings;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * Settings is a Java wrapper to allow communicating with the native Settings object.
+ */
+@JNINamespace("blimp::client")
+public class Settings {
+ @CalledByNative
+ private static Settings create(long nativeSettingsAndroid) {
+ return new Settings(nativeSettingsAndroid);
+ }
+
+ private long mNativeSettingsAndroid;
+
+ // The SettingsObserverProxy is lazily created when the first observer is added. It is used
+ // instead of directly having an ObserverList in this class to ensure there is only a single
+ // JNI hop for each call to observers.
+ private SettingsObserverProxy mObserverProxy;
David Trainor- moved to gerrit 2016/11/03 03:05:10 Who cleans up the observer proxy?
Menglin 2016/11/03 23:17:01 it should be cleaned up in clearNativePtr() when S
+
+ private Settings(long nativeSettingsAndroid) {
+ mNativeSettingsAndroid = nativeSettingsAndroid;
+ }
+
+ @CalledByNative
+ private long getNativePtr() {
David Trainor- moved to gerrit 2016/11/03 03:05:10 Put this down below near clearNativePtr
Menglin 2016/11/03 23:17:01 Done.
+ assert mNativeSettingsAndroid != 0;
+ return mNativeSettingsAndroid;
+ }
+
+ public void addObserver(SettingsObserver observer) {
David Trainor- moved to gerrit 2016/11/03 03:05:10 Javadocs on some of these? Specifically on destro
Menglin 2016/11/03 23:17:01 Done.
+ assert mNativeSettingsAndroid != 0;
+ if (mObserverProxy == null) mObserverProxy = new SettingsObserverProxy(this);
+ mObserverProxy.addObserver(observer);
+ }
+
+ public void removeObserver(SettingsObserver observer) {
+ if (mObserverProxy == null) return;
+ mObserverProxy.removeObserver(observer);
+ }
+
+ public void destroy() {
David Trainor- moved to gerrit 2016/11/03 03:05:10 Do we need this method? I feel like this is going
Menglin 2016/11/03 23:17:01 that's a good point. ObserverProxy should be destr
+ assert mNativeSettingsAndroid != 0;
+ nativeDestroy(mNativeSettingsAndroid);
+ mNativeSettingsAndroid = 0;
+ }
+
+ // Set whether or not Blimp mode is enabled.
+ public void setEnableBlimpMode(boolean enable) {
+ if (mNativeSettingsAndroid == 0) return;
+ nativeSetEnableBlimpModeWrap(mNativeSettingsAndroid, enable);
+ }
+
+ // Set whether or not the engine sends the whole webpage at once or pieces of it based on the
+ // current viewport.
+ public void setRecordWholeDocument(boolean enable) {
+ if (mNativeSettingsAndroid == 0) return;
+ nativeSetRecordWholeDocumentWrap(mNativeSettingsAndroid, enable);
+ }
+
+ // Set whether or not to show the network stats.
+ public void setShowNetworkStats(boolean enable) {
+ if (mNativeSettingsAndroid == 0) return;
+ nativeSetShowNetworkStatsWrap(mNativeSettingsAndroid, enable);
+ }
+
+ @CalledByNative
+ private void clearNativePtr() {
+ mNativeSettingsAndroid = 0;
+ }
+
+ private native void nativeDestroy(long nativeSettingsAndroid);
+ private native void nativeSetEnableBlimpModeWrap(long nativeSettingsAndroid, boolean enable);
+ private native void nativeSetRecordWholeDocumentWrap(
+ long nativeSettingsAndroid, boolean enable);
+ private native void nativeSetShowNetworkStatsWrap(long nativeSettingsAndroid, boolean enable);
+}

Powered by Google App Engine
This is Rietveld 408576698