Bug 1453143 - [1.1] Add GeckoRuntimeSettings builder for mutable settings support. r=snorp,jchen
authorEugen Sawin <esawin@mozilla.com>
Tue, 10 Apr 2018 23:12:51 +0200
changeset 413312 5d38501e55dc2172f489b5a394c623c2e6431cee
parent 413276 837a6f4efa3eaf3cff106349b735e718efb4d4a6
child 413313 4d56446fd614f8b4e2beb8466bfe1a13b170bd81
push id33843
push usernerli@mozilla.com
push dateSat, 14 Apr 2018 09:49:25 +0000
treeherdermozilla-central@37b8862d354e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jchen
bugs1453143
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1453143 - [1.1] Add GeckoRuntimeSettings builder for mutable settings support. r=snorp,jchen
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java
@@ -177,16 +177,20 @@ public final class GeckoRuntime implemen
      * Returns the current delegate, if any.
      *
      * @return an instance of {@link GeckoRuntime.Delegate} or null if no delegate has been set.
      */
     public @Nullable Delegate getDelegate() {
         return mDelegate;
     }
 
+    public GeckoRuntimeSettings getSettings() {
+        return mSettings;
+    }
+
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         out.writeParcelable(mSettings, flags);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -8,36 +8,83 @@ package org.mozilla.geckoview;
 
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 
 public final class GeckoRuntimeSettings implements Parcelable {
-    private boolean mUseContentProcess;
-    private String[] mArgs;
-    private Bundle mExtras;
+    /**
+     * Settings builder used to construct the settings object.
+     */
+    public static final class Builder {
+        private final GeckoRuntimeSettings mSettings;
+
+        public Builder() {
+            mSettings = new GeckoRuntimeSettings();
+        }
+
+        public Builder(final GeckoRuntimeSettings settings) {
+            mSettings = new GeckoRuntimeSettings(settings);
+        }
+
+        /**
+         * Finalize and return the settings.
+         *
+         * @return The constructed settings.
+         */
+        public @NonNull GeckoRuntimeSettings build() {
+            return new GeckoRuntimeSettings(mSettings);
+        }
 
-    /**
-     * Initialize default settings.
-     */
-    public  GeckoRuntimeSettings() {
-        this(null);
+        /**
+         * Set the content process hint flag.
+         *
+         * @param use If true, this will reload the content process for future use.
+         */
+        public @NonNull Builder useContentProcessHint(final boolean use) {
+            mSettings.mUseContentProcess = use;
+            return this;
+        }
+
+        /**
+         * Set the custom Gecko process arguments.
+         *
+         * @param args The Gecko process arguments.
+         */
+        public @NonNull Builder arguments(final @NonNull String[] args) {
+            mSettings.mArgs = args;
+            return this;
+        }
+
+        /**
+         * Set the custom Gecko intent extras.
+         *
+         * @param extras The Gecko intent extras.
+         */
+        public @NonNull Builder extras(final @NonNull Bundle extras) {
+            mSettings.mExtras = extras;
+            return this;
+        }
     }
 
-    /* package */ GeckoRuntimeSettings(final @Nullable GeckoRuntimeSettings settings) {
-        if (settings != null) {
-            mUseContentProcess = settings.mUseContentProcess;
-            mArgs = settings.mArgs.clone();
-            mExtras = new Bundle(settings.mExtras);
-        } else {
-            mArgs = new String[0];
-            mExtras = new Bundle();
-        }
+    /* package */ boolean mUseContentProcess;
+    /* package */ String[] mArgs;
+    /* package */ Bundle mExtras;
+
+    /* package */ GeckoRuntimeSettings() {
+        mArgs = new String[0];
+        mExtras = new Bundle();
+    }
+
+    /* package */ GeckoRuntimeSettings(final @NonNull GeckoRuntimeSettings settings) {
+        mUseContentProcess = settings.getUseContentProcessHint();
+        mArgs = settings.getArguments().clone();
+        mExtras = new Bundle(settings.getExtras());
     }
 
     /**
      * Get the content process hint flag.
      *
      * @return The content process hint flag.
      */
     public boolean getUseContentProcessHint() {
@@ -57,43 +104,16 @@ public final class GeckoRuntimeSettings 
      * Get the custom Gecko intent extras.
      *
      * @return The Gecko intent extras.
      */
     public Bundle getExtras() {
         return mExtras;
     }
 
-    /**
-     * Set the content process hint flag.
-     *
-     * @param use If true, this will reload the content process for future use.
-     */
-    public void setUseContentProcessHint(boolean use) {
-        mUseContentProcess = use;
-    }
-
-    /**
-     * Set the custom Gecko process arguments.
-     *
-     * @param args The Gecko process arguments.
-     */
-    public void setArguments(final @NonNull String[] args) {
-        mArgs = args;
-    }
-
-    /**
-     * Set the custom Gecko intent extras.
-     *
-     * @param extras The Gecko intent extras.
-     */
-    public void setExtras(final @NonNull Bundle extras) {
-        mExtras = extras;
-    }
-
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         out.writeByte((byte) (mUseContentProcess ? 1 : 0));