Backed out changeset e954e5a93482 (bug 1287946)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 21 Jul 2016 08:07:11 +0200
changeset 305963 d3a44f609b1ff8f6b7c0fc43931cf06fe3a29550
parent 305962 c774aed886fd764f7bd4a0011f1da25be7d2d3a6
child 305964 5643545ad4992dc69233b6b5bef4887fb10fec0c
push id79730
push usercbook@mozilla.com
push dateThu, 21 Jul 2016 06:15:05 +0000
treeherdermozilla-inbound@28f30533c635 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1287946
milestone50.0a1
backs oute954e5a93482182eaddf52c9ba633d20c174c16e
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
Backed out changeset e954e5a93482 (bug 1287946)
widget/android/PrefsHelper.h
widget/android/jni/Refs.h
--- a/widget/android/PrefsHelper.h
+++ b/widget/android/PrefsHelper.h
@@ -7,18 +7,20 @@
 #define PrefsHelper_h
 
 #include "GeneratedJNINatives.h"
 #include "MainThreadUtils.h"
 #include "nsAppShell.h"
 #include "nsCOMPtr.h"
 #include "nsVariant.h"
 
+#include "mozilla/Maybe.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 
 class PrefsHelper
     : public java::PrefsHelper::Natives<PrefsHelper>
     , public UsesGeckoThreadProxy
 {
     PrefsHelper() = delete;
@@ -61,27 +63,30 @@ class PrefsHelper
                 if (NS_FAILED(aVariant->GetAsAString(strVal))) {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
 
-        jni::StringParam jstrVal(type == java::PrefsHelper::PREF_STRING ?
-                jni::StringParam(strVal, aPrefName.Env()) :
-                jni::StringParam(nullptr));
+        Maybe<jni::StringParam> jstrVal;
+        jstrVal.emplace(nullptr);
+        if (type == java::PrefsHelper::PREF_STRING) {
+            jstrVal.reset();
+            jstrVal.emplace(strVal, aPrefName.Env());
+        }
 
         if (aPrefHandler) {
             java::PrefsHelper::CallPrefHandler(
                     aPrefHandler, type, aPrefName,
-                    boolVal, intVal, jstrVal);
+                    boolVal, intVal, jstrVal.ref());
         } else {
             java::PrefsHelper::OnPrefChange(
-                    aPrefName, type, boolVal, intVal, jstrVal);
+                    aPrefName, type, boolVal, intVal, jstrVal.ref());
         }
         return true;
     }
 
     static bool SetVariantPref(nsIObserverService* aObsServ,
                                nsIWritableVariant* aVariant,
                                jni::String::Param aPrefName,
                                bool aFlush,
@@ -184,21 +189,26 @@ public:
                     if (!GetVariantPref(obsServ, value,
                                         aPrefHandler, nameStr)) {
                         NS_WARNING(nsPrintfCString("Failed to get pref %s",
                                                    name.get()).get());
                     }
                     continue;
             }
 
+            Maybe<jni::StringParam> jstrVal;
+            jstrVal.emplace(nullptr);
+            if (type == java::PrefsHelper::PREF_STRING) {
+                jstrVal.reset();
+                jstrVal.emplace(strVal, aCls.Env());
+            }
+
             java::PrefsHelper::CallPrefHandler(
-                    aPrefHandler, type, nameStr, boolVal, intVal,
-                    jni::StringParam(type == java::PrefsHelper::PREF_STRING ?
-                        jni::StringParam(strVal, aCls.Env()) :
-                        jni::StringParam(nullptr)));
+                    aPrefHandler, type, nameStr,
+                    boolVal, intVal, jstrVal.ref());
         }
 
         java::PrefsHelper::CallPrefHandler(
                 aPrefHandler, java::PrefsHelper::PREF_FINISH,
                 nullptr, false, 0, nullptr);
     }
 
     static void SetPref(jni::String::Param aPrefName,
@@ -308,18 +318,23 @@ public:
                 }
                 break;
             default:
                 NS_WARNING(nsPrintfCString("Invalid pref %s",
                                            name.get()).get());
                 return;
         }
 
+        Maybe<jni::StringParam> jstrVal;
+        jstrVal.emplace(nullptr);
+        if (type == java::PrefsHelper::PREF_STRING) {
+            jstrVal.reset();
+            jstrVal.emplace(strVal);
+        }
+
         java::PrefsHelper::OnPrefChange(
-                name, type, boolVal, intVal,
-                jni::StringParam(type == java::PrefsHelper::PREF_STRING ?
-                    jni::StringParam(strVal) : jni::StringParam(nullptr)));
+                name, type, boolVal, intVal, jstrVal.ref());
     }
 };
 
 } // namespace
 
 #endif // PrefsHelper_h
--- a/widget/android/jni/Refs.h
+++ b/widget/android/jni/Refs.h
@@ -675,26 +675,19 @@ public:
         , mEnv(env)
     {}
 
     MOZ_IMPLICIT StringParam(const char* str, JNIEnv* env = Ref::FindEnv())
         : Ref(GetString(env, NS_ConvertUTF8toUTF16(str)))
         , mEnv(env)
     {}
 
-    StringParam(StringParam&& other)
-        : Ref(other.Get())
-        , mEnv(other.mEnv)
-    {
-        other.mInstance = nullptr;
-    }
-
     ~StringParam()
     {
-        if (mEnv && Get()) {
+        if (mEnv) {
             mEnv->DeleteLocalRef(Get());
         }
     }
 
     operator String::LocalRef() const
     {
         // We can't return our existing ref because the returned
         // LocalRef could be freed first, so we need a new local ref.