Bug 1195496 - Add PROFILE_READY Gecko state; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 19 Aug 2015 18:14:47 -0400
changeset 259074 6242c04623f1fc5ae7b8aace3e7240ecd7e746db
parent 259073 dee6eb23df212bbabee1927136ac6e9753207f96
child 259075 2d89db567a589c0290d89b16e785690e505db27b
push id29268
push userryanvm@gmail.com
push dateTue, 25 Aug 2015 00:37:23 +0000
treeherdermozilla-central@08015770c9d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1195496
milestone43.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 1195496 - Add PROFILE_READY Gecko state; r=snorp Many Gecko operations depend on the profile being available. This patch adds a PROFILE_READY Gecko state so that we can queue calls until profile is loaded.
mobile/android/base/GeckoThread.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/nsAppShell.cpp
--- a/mobile/android/base/GeckoThread.java
+++ b/mobile/android/base/GeckoThread.java
@@ -44,16 +44,18 @@ public class GeckoThread extends Thread 
         // After launching Gecko thread
         LAUNCHED,
         // After loading the mozglue library.
         MOZGLUE_READY,
         // After loading the libxul library.
         LIBS_READY,
         // After initializing nsAppShell and JNI calls.
         JNI_READY,
+        // After initializing profile and prefs.
+        PROFILE_READY,
         // After initializing frontend JS (corresponding to "Gecko:Ready" event)
         RUNNING,
         // After leaving Gecko event loop
         EXITING,
         // After exiting GeckoThread (corresponding to "Gecko:Exited" event)
         EXITED;
 
         public boolean is(final State other) {
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -911,16 +911,24 @@ auto GeckoThread::State::LIBS_READY() ->
 constexpr char GeckoThread::State::MOZGLUE_READY_t::name[];
 constexpr char GeckoThread::State::MOZGLUE_READY_t::signature[];
 
 auto GeckoThread::State::MOZGLUE_READY() -> State::LocalRef
 {
     return mozilla::jni::Field<MOZGLUE_READY_t>::Get(nullptr, nullptr);
 }
 
+constexpr char GeckoThread::State::PROFILE_READY_t::name[];
+constexpr char GeckoThread::State::PROFILE_READY_t::signature[];
+
+auto GeckoThread::State::PROFILE_READY() -> State::LocalRef
+{
+    return mozilla::jni::Field<PROFILE_READY_t>::Get(nullptr, nullptr);
+}
+
 constexpr char GeckoThread::State::RUNNING_t::name[];
 constexpr char GeckoThread::State::RUNNING_t::signature[];
 
 auto GeckoThread::State::RUNNING() -> State::LocalRef
 {
     return mozilla::jni::Field<RUNNING_t>::Get(nullptr, nullptr);
 }
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -2150,16 +2150,33 @@ public:
         static const bool isMultithreaded = true;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
     };
 
     static auto MOZGLUE_READY() -> State::LocalRef;
 
 public:
+    struct PROFILE_READY_t {
+        typedef State Owner;
+        typedef State::LocalRef ReturnType;
+        typedef State::Param SetterType;
+        typedef mozilla::jni::Args<> Args;
+        static constexpr char name[] = "PROFILE_READY";
+        static constexpr char signature[] =
+                "Lorg/mozilla/gecko/GeckoThread$State;";
+        static const bool isStatic = true;
+        static const bool isMultithreaded = true;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+    };
+
+    static auto PROFILE_READY() -> State::LocalRef;
+
+public:
     struct RUNNING_t {
         typedef State Owner;
         typedef State::LocalRef ReturnType;
         typedef State::Param SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "RUNNING";
         static constexpr char signature[] =
                 "Lorg/mozilla/gecko/GeckoThread$State;";
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -191,18 +191,19 @@ nsAppShell::Init()
 {
     if (!gWidgetLog)
         gWidgetLog = PR_NewLogModule("Widget");
 
     nsresult rv = nsBaseAppShell::Init();
     nsCOMPtr<nsIObserverService> obsServ =
         mozilla::services::GetObserverService();
     if (obsServ) {
+        obsServ->AddObserver(this, "browser-delayed-startup-finished", false);
+        obsServ->AddObserver(this, "profile-do-change", false);
         obsServ->AddObserver(this, "xpcom-shutdown", false);
-        obsServ->AddObserver(this, "browser-delayed-startup-finished", false);
     }
 
     if (sPowerManagerService)
         sPowerManagerService->AddWakeLockListener(sWakeLockListener);
 
     Preferences::AddStrongObservers(this, kObservedPrefs);
     mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
     return rv;
@@ -221,16 +222,26 @@ nsAppShell::Observe(nsISupports* aSubjec
     } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) &&
                aData &&
                nsDependentString(aData).Equals(NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES))) {
         mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
         return NS_OK;
     } else if (!strcmp(aTopic, "browser-delayed-startup-finished")) {
         NS_CreateServicesFromCategory("browser-delayed-startup-finished", nullptr,
                                       "browser-delayed-startup-finished");
+    } else if (!strcmp(aTopic, "profile-do-change")) {
+        if (jni::IsAvailable()) {
+            widget::GeckoThread::SetState(
+                    widget::GeckoThread::State::PROFILE_READY());
+        }
+        nsCOMPtr<nsIObserverService> obsServ =
+            mozilla::services::GetObserverService();
+        if (obsServ) {
+            obsServ->RemoveObserver(this, "profile-do-change");
+        }
     }
     return NS_OK;
 }
 
 void
 nsAppShell::ScheduleNativeEventCallback()
 {
     EVLOG("nsAppShell::ScheduleNativeEventCallback pth: %p thread: %p main: %d", (void*) pthread_self(), (void*) NS_GetCurrentThread(), NS_IsMainThread());